fix: resolve Logger access, wrong model name, and API key guard tests
- bootstrap: add PRAUTOBLOGGER_MAX_RETRIES, API_TIMEOUT, RETRY_BASE_DELAY constants - BaseTestCase: add wp_json_encode + home_url stubs, reset Logger singleton in tearDown - CostTrackerTest: use openai/gpt-4o (in MODEL_PRICING), fix log_api_call args, allow multiple wpdb inserts (Logger may also insert event_log rows) - OpenRouterPricingTest: add wpdb mock with prefix for Logger access on unknown models - OpenRouterProviderTest: test send_chat_completion throws RuntimeException when no API key is configured (matches actual guard clause behavior) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,9 +14,28 @@ use Brain\Monkey\Functions;
|
||||
|
||||
class OpenRouterPricingTest extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject Mock $wpdb for Logger.
|
||||
*/
|
||||
private $wpdb;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
// Logger (called on unknown-model warning) accesses $wpdb->prefix and $wpdb->insert.
|
||||
$this->wpdb = $this->create_mock_wpdb();
|
||||
$this->wpdb->method( 'insert' )->willReturn( 1 );
|
||||
$GLOBALS['wpdb'] = $this->wpdb;
|
||||
|
||||
// Stub get_option for Logger's log_level and Pricing's API key lookup.
|
||||
$this->stub_get_option( [
|
||||
'prautoblogger_log_level' => 'info',
|
||||
'prautoblogger_openrouter_api_key' => '',
|
||||
] );
|
||||
|
||||
// Stub current_time — used by Logger when writing log entries.
|
||||
$this->stub_current_time( '2026-04-12 10:00:00' );
|
||||
|
||||
// OpenRouterPricing::get_available_models() calls get_transient() to check cache.
|
||||
// Return a valid cached model list so it doesn't try to make HTTP calls.
|
||||
Functions\when( 'get_transient' )->alias(
|
||||
@@ -44,6 +63,11 @@ class OpenRouterPricingTest extends BaseTestCase {
|
||||
Functions\when( 'set_transient' )->justReturn( true );
|
||||
}
|
||||
|
||||
protected function tearDown(): void {
|
||||
unset( $GLOBALS['wpdb'] );
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Pricing can be instantiated.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user