80ed7b1bb2
unit bootstrap 改載入真實 TMDO_Listing_Stats:先 define TMDO_TEST_SKIP_LISTING_STATS_STUB,核心 bootstrap 便會跳過它的 stub。 145 → 154 tests。
94 lines
3.9 KiB
PHP
94 lines
3.9 KiB
PHP
<?php
|
|
/**
|
|
* PHPUnit bootstrap for the HivePress AddOn.
|
|
*
|
|
* Reuses the core plugin's unit bootstrap (WP function stubs, $wpdb stub,
|
|
* constants, WPDO_* aliases) instead of duplicating ~700 lines of stubs, then
|
|
* loads this AddOn's own classes on top.
|
|
*
|
|
* The core plugin must sit next to this one under wp-content/plugins/.
|
|
*
|
|
* @package TMDO_HIVEPRESS
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
// Load the real TMDO_Listing_Stats below instead of core's stub.
|
|
define( 'TMDO_TEST_SKIP_LISTING_STATS_STUB', true );
|
|
|
|
$tmdo_core_bootstrap = dirname( __DIR__, 2 ) . '/2meet-data-optimizer/tests/bootstrap.php';
|
|
if ( ! file_exists( $tmdo_core_bootstrap ) ) {
|
|
throw new RuntimeException(
|
|
'HivePress AddOn tests require the core plugin at ' . dirname( __DIR__, 2 ) . '/2meet-data-optimizer'
|
|
);
|
|
}
|
|
require_once $tmdo_core_bootstrap;
|
|
|
|
define( 'TMDO_HIVEPRESS_PATH', dirname( __DIR__ ) . '/' );
|
|
define( 'TMDO_HIVEPRESS_URL', 'http://localhost/wp-content/plugins/2meet-data-optimizer-hivepress-addon/' );
|
|
define( 'TMDO_HIVEPRESS_FILE', dirname( __DIR__ ) . '/2meet-data-optimizer-hivepress-addon.php' );
|
|
define( 'TMDO_HIVEPRESS_VERSION', '0.1.0' );
|
|
|
|
// ── AddOn classes ──────────────────────────────────────────────────────────
|
|
|
|
$tmdo_hp_files = array(
|
|
'includes/class-tmdo-hivepress.php',
|
|
'includes/hivepress/interface-tmdo-hp-adapter.php',
|
|
'includes/hivepress/trait-tmdo-hp-adapter.php',
|
|
'includes/hivepress/class-tmdo-hivepress-detector.php',
|
|
'includes/hivepress/class-tmdo-hivepress-conflict-guard.php',
|
|
'includes/hivepress/class-tmdo-hivepress-bootstrap.php',
|
|
'includes/hivepress/class-tmdo-hivepress-comment-router.php',
|
|
'includes/hivepress/class-tmdo-hivepress-cron-optimizer.php',
|
|
'includes/hivepress/class-tmdo-hivepress-attribute-bridge.php',
|
|
'includes/hivepress/class-tmdo-hivepress-suitability-scorer.php',
|
|
'includes/hivepress/class-tmdo-hivepress-benchmark.php',
|
|
'includes/hivepress/class-tmdo-hivepress-rest.php',
|
|
'includes/class-tmdo-hivepress-transient-filter.php',
|
|
'includes/class-tmdo-hivepress-term-comment-fields.php',
|
|
'includes/class-tmdo-hpct-import.php',
|
|
'includes/class-tmdo-listing-stats.php',
|
|
'admin/class-tmdo-admin-hivepress.php',
|
|
'cli/class-tmdo-cli-hivepress.php',
|
|
);
|
|
|
|
foreach ( glob( TMDO_HIVEPRESS_PATH . 'includes/hivepress/adapters/*.php' ) ?: array() as $tmdo_hp_adapter ) {
|
|
$tmdo_hp_files[] = 'includes/hivepress/adapters/' . basename( $tmdo_hp_adapter );
|
|
}
|
|
|
|
foreach ( $tmdo_hp_files as $tmdo_hp_file ) {
|
|
$tmdo_hp_path = TMDO_HIVEPRESS_PATH . $tmdo_hp_file;
|
|
if ( file_exists( $tmdo_hp_path ) ) {
|
|
require_once $tmdo_hp_path;
|
|
}
|
|
}
|
|
unset( $tmdo_hp_files, $tmdo_hp_file, $tmdo_hp_path, $tmdo_hp_adapter, $tmdo_core_bootstrap );
|
|
|
|
// ── Back-compat aliases for this AddOn's classes ───────────────────────────
|
|
// Mirrors includes/back-compat-aliases.php, which runs on plugins_loaded:7 and
|
|
// therefore never fires under PHPUnit.
|
|
foreach ( get_declared_classes() as $tmdo_declared ) {
|
|
if ( str_starts_with( $tmdo_declared, 'TMDO_' ) ) {
|
|
$tmdo_alias = 'WPDO_' . substr( $tmdo_declared, 5 );
|
|
if ( ! class_exists( $tmdo_alias, false ) ) {
|
|
class_alias( $tmdo_declared, $tmdo_alias );
|
|
}
|
|
}
|
|
}
|
|
unset( $tmdo_declared, $tmdo_alias );
|
|
|
|
// PHP cannot class_alias() traits or interfaces — declare thin wrappers so the
|
|
// suite can keep referring to the WPDO_ names.
|
|
if ( trait_exists( 'TMDO_HivePress_Adapter_Trait' ) && ! trait_exists( 'WPDO_HivePress_Adapter_Trait', false ) ) {
|
|
trait WPDO_HivePress_Adapter_Trait {
|
|
use TMDO_HivePress_Adapter_Trait;
|
|
}
|
|
}
|
|
// WPDO_HivePress_Adapter is declared by interface-tmdo-hp-adapter.php itself
|
|
// (TMDO_ extends WPDO_), so no wrapper is needed here.
|
|
|
|
// Shared $wpdb mock helper used by the adapter tests.
|
|
if ( file_exists( __DIR__ . '/unit/WpdbMockTrait.php' ) ) {
|
|
require_once __DIR__ . '/unit/WpdbMockTrait.php';
|
|
}
|