fix: add WP constants, WP_Query mock, fix arg types and stubs

- bootstrap: define DAY_IN_SECONDS, ARRAY_A, mock WP_Query class
- CostTrackerTest: fix log_api_call signature (post_id is ?int, not string)
- PublisherTest: fix apply_filters usage, remove broken expectation
- OpenRouterPricingTest: fix assertGreaterThanOrEqual direction
- OpenRouterProviderTest: add wp_salt stub, use empty API key
- ContentAnalyzerTest: add apply_filters, current_time, get_results stubs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
peptiderepo
2026-04-12 08:17:18 +07:00
parent ece032efe5
commit 7728db5671
6 changed files with 81 additions and 25 deletions

View File

@@ -112,7 +112,7 @@ class OpenRouterPricingTest extends BaseTestCase {
$pricing = new \PRAutoBlogger_OpenRouter_Pricing();
$cost = $pricing->estimate_cost( 'unknown/fake-model', 1000, 500 );
// Unknown models may return 0.0 or a fallback value
// Unknown models may return 0.0 or a fallback value.
$this->assertIsFloat( $cost );
$this->assertGreaterThanOrEqual( 0.0, $cost );
}
@@ -139,8 +139,8 @@ class OpenRouterPricingTest extends BaseTestCase {
$cost_small = $pricing->estimate_cost( 'google/gemini-2.0-flash-001', 100, 100 );
$cost_large = $pricing->estimate_cost( 'google/gemini-2.0-flash-001', 1000, 1000 );
// Larger token counts should result in higher or equal costs.
$this->assertLessThanOrEqual( $cost_large, $cost_small + 100 ); // Very loose check
// Larger token counts should cost more or equal.
$this->assertGreaterThanOrEqual( $cost_small, $cost_large );
}
/**

View File

@@ -20,10 +20,14 @@ class OpenRouterProviderTest extends BaseTestCase {
// Stub get_option — provider calls get_option('prautoblogger_openrouter_api_key', '')
// for API key retrieval via private get_api_key() method.
// Return empty string so decryption is skipped (no key = empty return).
$this->stub_get_option( [
'prautoblogger_openrouter_api_key' => 'test_encrypted_key',
'prautoblogger_openrouter_api_key' => '',
] );
// Stub wp_salt — called by PRAutoBlogger_Encryption during API key decryption.
Functions\when( 'wp_salt' )->justReturn( 'test_salt_key_for_unit_tests' );
// Stub get_transient/set_transient — used by OpenRouter_Pricing (called internally).
Functions\when( 'get_transient' )->alias(
function ( string $key ) {