Files
2meet-data-optimizer-hivepr…/tests/integration/bootstrap.php
T
wpdev d129139c7d perf(2meet-data-optimizer-hivepress-addon): expire object-cache transients
- with an external object cache, a HivePress timeout entry expires when it
  records; the value (written before its timeout) after at most a week — a
  miss only makes HivePress rebuild it. Entries of deleted posts no longer
  accumulate without end
- Verify: HivepressTransientFilterTest TTL test, integration 53, unit 145;
  dev36 Redis TTL on tmdo_hp_transient keys
- PR: PR-099
2026-09-27 16:42:52 +08:00

105 lines
4.5 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'
);
}
// Defined before the core bootstrap (which only adds it when missing) so tests can read the TTL.
if ( ! function_exists( 'wp_cache_set' ) ) {
function wp_cache_set( $key, $value, $group = '', $ttl = 0 ): bool {
$GLOBALS['_wp_cache'][ $group ][ $key ] = $value;
$GLOBALS['_wp_cache_ttl'][ $group ][ $key ] = (int) $ttl;
return true;
}
}
require_once $tmdo_core_bootstrap;
// External object cache switch for the transient filter tests (Redis on real sites).
if ( ! function_exists( 'wp_using_ext_object_cache' ) ) {
function wp_using_ext_object_cache( $using = null ): bool { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
return ! empty( $GLOBALS['_wp_using_ext_object_cache'] );
}
}
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 ──────────────────────────────────────────────────────────
$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-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-hivepress-entity-groups.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 ( $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;
}
}