All 14 test files updated to use correct constructor patterns (array-based value objects, dependency injection for ContentAnalyzer, etc.) and verified method names against source. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
126 lines
4.0 KiB
PHP
126 lines
4.0 KiB
PHP
<?php
|
|
/**
|
|
* Tests for PRAutoBlogger_OpenRouter_Pricing.
|
|
*
|
|
* Validates the pricing API with instance methods for model prices and cost estimation.
|
|
*
|
|
* @package PRAutoBlogger\Tests\Providers
|
|
*/
|
|
|
|
namespace PRAutoBlogger\Tests\Providers;
|
|
|
|
use PRAutoBlogger\Tests\BaseTestCase;
|
|
|
|
class OpenRouterPricingTest extends BaseTestCase {
|
|
|
|
/**
|
|
* Test Pricing can be instantiated.
|
|
*/
|
|
public function test_openrouter_pricing_instantiation(): void {
|
|
$pricing = new \PRAutoBlogger_OpenRouter_Pricing();
|
|
|
|
$this->assertInstanceOf( \PRAutoBlogger_OpenRouter_Pricing::class, $pricing );
|
|
}
|
|
|
|
/**
|
|
* Test get_available_models returns array.
|
|
*/
|
|
public function test_get_available_models_returns_array(): void {
|
|
$pricing = new \PRAutoBlogger_OpenRouter_Pricing();
|
|
$models = $pricing->get_available_models();
|
|
|
|
$this->assertIsArray( $models );
|
|
}
|
|
|
|
/**
|
|
* Test get_available_models returns non-empty array.
|
|
*/
|
|
public function test_get_available_models_not_empty(): void {
|
|
$pricing = new \PRAutoBlogger_OpenRouter_Pricing();
|
|
$models = $pricing->get_available_models();
|
|
|
|
$this->assertNotEmpty( $models );
|
|
}
|
|
|
|
/**
|
|
* Test estimate_cost returns float.
|
|
*/
|
|
public function test_estimate_cost_returns_float(): void {
|
|
$pricing = new \PRAutoBlogger_OpenRouter_Pricing();
|
|
$cost = $pricing->estimate_cost( 'google/gemini-2.0-flash-001', 1000, 500 );
|
|
|
|
$this->assertIsFloat( $cost );
|
|
}
|
|
|
|
/**
|
|
* Test estimate_cost with zero tokens returns zero or non-negative.
|
|
*/
|
|
public function test_estimate_cost_with_zero_tokens(): void {
|
|
$pricing = new \PRAutoBlogger_OpenRouter_Pricing();
|
|
$cost = $pricing->estimate_cost( 'google/gemini-2.0-flash-001', 0, 0 );
|
|
|
|
$this->assertIsFloat( $cost );
|
|
$this->assertGreaterThanOrEqual( 0.0, $cost );
|
|
}
|
|
|
|
/**
|
|
* Test estimate_cost with positive tokens.
|
|
*/
|
|
public function test_estimate_cost_with_positive_tokens(): void {
|
|
$pricing = new \PRAutoBlogger_OpenRouter_Pricing();
|
|
$cost = $pricing->estimate_cost( 'google/gemini-2.0-flash-001', 1000, 1000 );
|
|
|
|
$this->assertIsFloat( $cost );
|
|
$this->assertGreaterThanOrEqual( 0.0, $cost );
|
|
}
|
|
|
|
/**
|
|
* Test estimate_cost with unknown model.
|
|
*/
|
|
public function test_estimate_cost_with_unknown_model(): void {
|
|
$pricing = new \PRAutoBlogger_OpenRouter_Pricing();
|
|
$cost = $pricing->estimate_cost( 'unknown/fake-model', 1000, 500 );
|
|
|
|
// Unknown models may return 0.0 or a fallback value
|
|
$this->assertIsFloat( $cost );
|
|
$this->assertGreaterThanOrEqual( 0.0, $cost );
|
|
}
|
|
|
|
/**
|
|
* Test estimate_cost consistency.
|
|
*/
|
|
public function test_estimate_cost_consistency(): void {
|
|
$pricing = new \PRAutoBlogger_OpenRouter_Pricing();
|
|
|
|
$cost1 = $pricing->estimate_cost( 'google/gemini-2.0-flash-001', 1000, 500 );
|
|
$cost2 = $pricing->estimate_cost( 'google/gemini-2.0-flash-001', 1000, 500 );
|
|
|
|
// Same inputs should yield same results.
|
|
$this->assertSame( $cost1, $cost2 );
|
|
}
|
|
|
|
/**
|
|
* Test estimate_cost increases with tokens.
|
|
*/
|
|
public function test_estimate_cost_increases_with_tokens(): void {
|
|
$pricing = new \PRAutoBlogger_OpenRouter_Pricing();
|
|
|
|
$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
|
|
}
|
|
|
|
/**
|
|
* Test available models includes known OpenRouter models.
|
|
*/
|
|
public function test_available_models_includes_popular_models(): void {
|
|
$pricing = new \PRAutoBlogger_OpenRouter_Pricing();
|
|
$models = $pricing->get_available_models();
|
|
|
|
// At least some models should be present.
|
|
$this->assertGreaterThan( 0, count( $models ) );
|
|
}
|
|
}
|