test: 加入 integration 測試套件(連真實 MariaDB)
從 wp-data-optimizer v3.4.6 移植 1 個 integration 測試檔,並新增 tests/integration/bootstrap.php(複用核心的 integration bootstrap,不重複 與 WP stub)+ phpunit-integration.xml + CI integration job。
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPUnit integration bootstrap for the WooCommerce AddOn.
|
||||
*
|
||||
* Reuses the core plugin's integration bootstrap (real MariaDB $wpdb, WP
|
||||
* function stubs, constants, WPDO_* aliases) and loads this AddOn's classes on
|
||||
* top. The same TMDO_TEST_DB_* environment variables the core suite needs
|
||||
* apply here.
|
||||
*
|
||||
* @package TMDO_WOOCOMMERCE
|
||||
*/
|
||||
|
||||
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(
|
||||
'WooCommerce AddOn integration tests require the core plugin at '
|
||||
. dirname( __DIR__, 3 ) . '/2meet-data-optimizer'
|
||||
);
|
||||
}
|
||||
require_once $tmdo_core_bootstrap;
|
||||
|
||||
define( 'TMDO_WOOCOMMERCE_PATH', dirname( __DIR__, 2 ) . '/' );
|
||||
define( 'TMDO_WOOCOMMERCE_URL', 'http://localhost/wp-content/plugins/2meet-data-optimizer-woocommerce-addon/' );
|
||||
define( 'TMDO_WOOCOMMERCE_FILE', TMDO_WOOCOMMERCE_PATH . '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 );
|
||||
Reference in New Issue
Block a user