0a3b05789e
AddOn 先前 tests=0。新增: - composer.json(dev 依賴 + phpunit/phpcs script) - phpunit.xml(failOnWarning=true) - tests/bootstrap.php:直接 require 核心 plugin 的 unit bootstrap,避免複製 ~700 行 WP stub,再載入本 AddOn 的類別;補 trait wrapper 與自動 WPDO_ alias (includes/back-compat-aliases.php 掛在 plugins_loaded:7,PHPUnit 下不會跑) - tests/unit/ 25 個測試 + WpdbMockTrait(自 A 移植) 生產碼一併修對外契約:interface-tmdo-hp-adapter.php 改為先宣告空的 WPDO_HivePress_Adapter、再讓 TMDO_HivePress_Adapter extends 它(PHP 無法 class_alias 介面,只有繼承能讓 instanceof WPDO_HivePress_Adapter 對 implements TMDO_ 名稱的 adapter 成立)。與核心 interface-entity-adapter.php 同一模式。這也讓第三方自訂 adapter 用舊介面名仍可通過核心檢查。 145 tests / 357 assertions GREEN Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TbG1keQQ7XBa7qMQY16KCY
77 lines
2.7 KiB
PHP
77 lines
2.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Tests for WPDO_HivePress_Suitability_Scorer.
|
|
*
|
|
* @covers WPDO_HivePress_Suitability_Scorer
|
|
*/
|
|
class HivePressSuitabilityScorerTest extends TestCase {
|
|
|
|
public function test_dimensions_constant_lists_eight_keys(): void {
|
|
$this->assertCount( 8, WPDO_HivePress_Suitability_Scorer::DIMENSIONS );
|
|
$this->assertContains( 'd1_meta_calls', WPDO_HivePress_Suitability_Scorer::DIMENSIONS );
|
|
$this->assertContains( 'd8_perf', WPDO_HivePress_Suitability_Scorer::DIMENSIONS );
|
|
}
|
|
|
|
public function test_compute_aggregate_with_empty_input_returns_zero(): void {
|
|
$this->assertSame( 0.0, WPDO_HivePress_Suitability_Scorer::compute_aggregate( array() ) );
|
|
}
|
|
|
|
public function test_compute_aggregate_averages_adapter_scores(): void {
|
|
$scores = array(
|
|
'a' => array( 'aggregate' => 10.0 ),
|
|
'b' => array( 'aggregate' => 9.0 ),
|
|
'c' => array( 'aggregate' => 8.0 ),
|
|
);
|
|
// (10 + 9 + 8) / 3 = 9.0
|
|
$this->assertSame( 9.0, WPDO_HivePress_Suitability_Scorer::compute_aggregate( $scores ) );
|
|
}
|
|
|
|
public function test_compute_per_dimension_averages_each_dimension(): void {
|
|
$scores = array(
|
|
'a' => array(
|
|
'd1_meta_calls' => 1.0, 'd2_meta_sql' => 1.0, 'd3_table_coverage' => 1.0,
|
|
'd4_registry_meta' => 1.0, 'd5_hook_bus' => 1.0, 'd6_options' => 1.0,
|
|
'd7_coupling' => 1.0, 'd8_perf' => 0.9,
|
|
),
|
|
'b' => array(
|
|
'd1_meta_calls' => 1.0, 'd2_meta_sql' => 1.0, 'd3_table_coverage' => 1.0,
|
|
'd4_registry_meta' => 1.0, 'd5_hook_bus' => 1.0, 'd6_options' => 1.0,
|
|
'd7_coupling' => 1.0, 'd8_perf' => 1.0,
|
|
),
|
|
);
|
|
$dim = WPDO_HivePress_Suitability_Scorer::compute_per_dimension( $scores );
|
|
|
|
// d1-d7 are 1.0 across both adapters → average 1.0.
|
|
$this->assertSame( 1.0, $dim['d1_meta_calls'] );
|
|
$this->assertSame( 1.0, $dim['d7_coupling'] );
|
|
|
|
// d8: (0.9 + 1.0) / 2 = 0.95.
|
|
$this->assertSame( 0.95, $dim['d8_perf'] );
|
|
}
|
|
|
|
public function test_compute_per_dimension_with_empty_input_returns_all_zero(): void {
|
|
$dim = WPDO_HivePress_Suitability_Scorer::compute_per_dimension( array() );
|
|
foreach ( WPDO_HivePress_Suitability_Scorer::DIMENSIONS as $d ) {
|
|
$this->assertSame( 0.0, $dim[ $d ] );
|
|
}
|
|
}
|
|
|
|
public function test_report_with_no_active_adapters(): void {
|
|
// Bootstrap not booted in unit env → adapters() = empty.
|
|
WPDO_HivePress_Bootstrap::reset_for_tests();
|
|
$report = WPDO_HivePress_Suitability_Scorer::report();
|
|
|
|
$this->assertSame( 0, $report['adapter_count'] );
|
|
$this->assertSame( 0.0, $report['aggregate'] );
|
|
$this->assertSame( array(), $report['adapters'] );
|
|
}
|
|
|
|
public function test_adapters_below_threshold_returns_empty_for_unknown_dimension(): void {
|
|
$this->assertSame( array(), WPDO_HivePress_Suitability_Scorer::adapters_below_threshold( 'd99_garbage' ) );
|
|
}
|
|
}
|