59c9b698b7
從 wp-data-optimizer v3.4.6 移植 5 個 integration 測試檔,並新增 tests/integration/bootstrap.php(複用核心的 integration bootstrap,不重複 與 WP stub)+ phpunit-integration.xml + CI integration job。
99 lines
4.4 KiB
PHP
99 lines
4.4 KiB
PHP
<?php
|
|
/**
|
|
* PHPUnit integration bootstrap for the HivePress AddOn.
|
|
*
|
|
* Reuses the core plugin's integration bootstrap (real MariaDB $wpdb, WP
|
|
* function stubs, constants, WPDO_* aliases) instead of duplicating it, then
|
|
* loads this AddOn's own classes on top.
|
|
*
|
|
* The core plugin must sit next to this one under wp-content/plugins/, and the
|
|
* same TMDO_TEST_DB_* environment variables the core suite needs apply here.
|
|
*
|
|
* @package TMDO_HIVEPRESS
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
$tmdo_core_bootstrap = dirname( __DIR__, 3 ) . '/2meet-data-optimizer/tests/integration/bootstrap.php';
|
|
if ( ! file_exists( $tmdo_core_bootstrap ) ) {
|
|
throw new RuntimeException(
|
|
'HivePress AddOn integration tests require the core plugin at '
|
|
. dirname( __DIR__, 3 ) . '/2meet-data-optimizer'
|
|
);
|
|
}
|
|
require_once $tmdo_core_bootstrap;
|
|
|
|
define( 'TMDO_HIVEPRESS_PATH', dirname( __DIR__, 2 ) . '/' );
|
|
define( 'TMDO_HIVEPRESS_URL', 'http://localhost/wp-content/plugins/2meet-data-optimizer-hivepress-addon/' );
|
|
define( 'TMDO_HIVEPRESS_FILE', TMDO_HIVEPRESS_PATH . '2meet-data-optimizer-hivepress-addon.php' );
|
|
define( 'TMDO_HIVEPRESS_VERSION', '0.1.0' );
|
|
|
|
// ── AddOn classes ──────────────────────────────────────────────────────────
|
|
// Superset of the unit bootstrap's list: the integration suite also exercises
|
|
// the interceptors, which the unit suite does not load.
|
|
|
|
$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',
|
|
'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_glob ) {
|
|
$tmdo_hp_files[] = 'includes/hivepress/adapters/' . basename( $tmdo_hp_glob );
|
|
}
|
|
foreach ( glob( TMDO_HIVEPRESS_PATH . 'includes/interceptors/*.php' ) ?: array() as $tmdo_hp_glob ) {
|
|
$tmdo_hp_files[] = 'includes/interceptors/' . basename( $tmdo_hp_glob );
|
|
}
|
|
foreach ( glob( TMDO_HIVEPRESS_PATH . 'includes/query/*.php' ) ?: array() as $tmdo_hp_glob ) {
|
|
$tmdo_hp_files[] = 'includes/query/' . basename( $tmdo_hp_glob );
|
|
}
|
|
|
|
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_glob, $tmdo_core_bootstrap );
|
|
|
|
// TMDO_Listing_Stats is stubbed by the core integration bootstrap (it lives in
|
|
// this AddOn but core tests reference it). Loading the real one here would
|
|
// collide with that stub, and no integration test exercises it — so it stays
|
|
// out, matching the unit 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 — declare a thin wrapper so the suite can
|
|
// keep referring to the WPDO_ name. The WPDO_HivePress_Adapter interface is
|
|
// declared by interface-tmdo-hp-adapter.php itself (TMDO_ extends WPDO_).
|
|
if ( trait_exists( 'TMDO_HivePress_Adapter_Trait' ) && ! trait_exists( 'WPDO_HivePress_Adapter_Trait', false ) ) {
|
|
trait WPDO_HivePress_Adapter_Trait {
|
|
use TMDO_HivePress_Adapter_Trait;
|
|
}
|
|
}
|