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
61 lines
1.9 KiB
PHP
61 lines
1.9 KiB
PHP
<?php
|
||
declare(strict_types=1);
|
||
|
||
use PHPUnit\Framework\TestCase;
|
||
|
||
/**
|
||
* Tests for WPDO_HivePress_Bookings_Adapter (detect-only).
|
||
*
|
||
* @covers WPDO_HivePress_Bookings_Adapter
|
||
*/
|
||
class HivePressBookingsAdapterTest extends TestCase {
|
||
|
||
use WpdbMockTrait;
|
||
|
||
private WPDO_HivePress_Bookings_Adapter $adapter;
|
||
|
||
protected function setUp(): void {
|
||
$this->install_wpdb_mock();
|
||
$reflect = new ReflectionClass( WPDO_Schema_Registry::class );
|
||
$prop = $reflect->getProperty( 'instance' );
|
||
$prop->setAccessible( true );
|
||
$prop->setValue( null, null );
|
||
|
||
$this->adapter = new WPDO_HivePress_Bookings_Adapter();
|
||
}
|
||
|
||
public function test_implements_adapter_interface(): void {
|
||
$this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter );
|
||
}
|
||
|
||
public function test_identity(): void {
|
||
$this->assertSame( 'hivepress-bookings', $this->adapter->plugin_slug() );
|
||
$this->assertSame( 'HivePress\\Bookings\\Plugin', $this->adapter->detection_class() );
|
||
}
|
||
|
||
public function test_on_register_fields_reserves_booking_hot_columns(): void {
|
||
$registry = WPDO_Schema_Registry::instance();
|
||
$this->adapter->on_register_fields( $registry );
|
||
|
||
$start = $registry->get_field( 'hp_booking', 'hp_start_time' );
|
||
$this->assertSame( 'hot', $start['zone'] );
|
||
$this->assertTrue( (bool) $start['indexed'] );
|
||
|
||
$end = $registry->get_field( 'hp_booking', 'hp_end_time' );
|
||
$this->assertSame( 'hot', $end['zone'] );
|
||
$this->assertTrue( (bool) $end['indexed'] );
|
||
}
|
||
|
||
public function test_score_reflects_unverified_perf_dimension(): void {
|
||
$score = $this->adapter->suitability_score();
|
||
// D8 reduced to 0.9 because schema is best-effort until addon installs.
|
||
$this->assertSame( 0.9, $score['d8_perf'] );
|
||
// Aggregate = (7 × 1.0 + 0.9) / 8 × 10 = 9.875 → 9.88.
|
||
$this->assertSame( 9.88, $score['aggregate'] );
|
||
}
|
||
|
||
public function test_migrations_lists_booking_module(): void {
|
||
$this->assertSame( array( 'hot_hp_booking' ), $this->adapter->migrations() );
|
||
}
|
||
}
|