Files
2meet-data-optimizer-woocom…/tests/bootstrap.php
T
wpdev abe738e900
Tests / PHP Lint (push) Successful in 5s
Tests / Unit Tests (push) Successful in 17s
test,ci: 建立 phpunit 基建 + 移植 WC 測試 + CI workflow
- composer.json / phpunit.xml / tests/bootstrap.php(比照 HP AddOn,
  直接 require 核心 plugin 的 unit bootstrap)
- tests/unit/WooCommerceIntegrationTest.php(自 A 移植,10 tests)
- .gitea/workflows/test.yml:lint + unit(unit job 會一併 checkout 核心 plugin,
  因為測試 bootstrap 依賴它)

10 tests / 33 assertions GREEN

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TbG1keQQ7XBa7qMQY16KCY
2026-07-31 09:20:07 +08:00

50 lines
1.7 KiB
PHP

<?php
/**
* PHPUnit bootstrap for the WooCommerce AddOn.
*
* Reuses the core plugin's unit bootstrap (WP function stubs, $wpdb stub,
* constants, WPDO_* aliases) and loads this AddOn's classes on top.
*
* @package TMDO_WOOCOMMERCE
*/
declare(strict_types=1);
$tmdo_core_bootstrap = dirname( __DIR__, 2 ) . '/2meet-data-optimizer/tests/bootstrap.php';
if ( ! file_exists( $tmdo_core_bootstrap ) ) {
throw new RuntimeException(
'WooCommerce AddOn tests require the core plugin at ' . dirname( __DIR__, 2 ) . '/2meet-data-optimizer'
);
}
require_once $tmdo_core_bootstrap;
define( 'TMDO_WOOCOMMERCE_PATH', dirname( __DIR__ ) . '/' );
define( 'TMDO_WOOCOMMERCE_URL', 'http://localhost/wp-content/plugins/2meet-data-optimizer-woocommerce-addon/' );
define( 'TMDO_WOOCOMMERCE_FILE', dirname( __DIR__ ) . '/2meet-data-optimizer-woocommerce-addon.php' );
define( 'TMDO_WOOCOMMERCE_VERSION', '0.1.0' );
foreach ( array(
'includes/class-tmdo-woocommerce.php',
'includes/class-tmdo-wc-orders-interceptor.php',
'includes/class-tmdo-wc-term-count-filter.php',
'admin/class-tmdo-admin-wc.php',
) as $tmdo_wc_file ) {
$tmdo_wc_path = TMDO_WOOCOMMERCE_PATH . $tmdo_wc_file;
if ( file_exists( $tmdo_wc_path ) ) {
require_once $tmdo_wc_path;
}
}
unset( $tmdo_wc_file, $tmdo_wc_path, $tmdo_core_bootstrap );
// 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 );