From f87b2430a288e72b7df31cbce44c514c57ef74ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 18 Aug 2026 14:41:55 -0400 Subject: [PATCH] fix(bootstrap): make Unit/Integration bootstraps self-locating PHPUnit re-runs the configured bootstrap file standalone in isolated child processes (@runInSeparateProcess), where the wpmedia-phpunit bin never runs and WPMEDIA_PHPUNIT_ROOT_DIR / WPMEDIA_PHPUNIT_ROOT_TEST_DIR are never defined, causing a fatal. Guard both bootstraps to self-derive the constants via BootstrapManager::setupConstants() when absent, mirroring the bin's class_exists/require_once pattern, so consumers no longer need a per-plugin Tests/{Unit,Integration}/init-tests.php shim whose only job was to define these two constants. Closes #52 Co-Authored-By: Claude Opus 4.8 --- src/Integration/bootstrap.php | 7 +++++++ src/Unit/bootstrap.php | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/Integration/bootstrap.php b/src/Integration/bootstrap.php index b3de64b..987378a 100644 --- a/src/Integration/bootstrap.php +++ b/src/Integration/bootstrap.php @@ -6,6 +6,13 @@ use function WPMedia\PHPUnit\init_test_suite; use Yoast\WPTestUtils\WPIntegration; +if ( ! defined( 'WPMEDIA_PHPUNIT_ROOT_DIR' ) ) { + if ( ! class_exists( BootstrapManager::class ) ) { + require_once dirname( __DIR__ ) . '/BootstrapManager.php'; + } + BootstrapManager::setupConstants( 'integration' ); +} + require_once WPMEDIA_PHPUNIT_ROOT_DIR . '/vendor/yoast/wp-test-utils/src/WPIntegration/bootstrap-functions.php'; require_once dirname( dirname( __FILE__ ) ) . '/bootstrap-functions.php'; init_test_suite(); diff --git a/src/Unit/bootstrap.php b/src/Unit/bootstrap.php index 5838d22..78012e0 100644 --- a/src/Unit/bootstrap.php +++ b/src/Unit/bootstrap.php @@ -4,6 +4,13 @@ use function WPMedia\PHPUnit\init_test_suite; +if ( ! defined( 'WPMEDIA_PHPUNIT_ROOT_DIR' ) ) { + if ( ! class_exists( \WPMedia\PHPUnit\BootstrapManager::class ) ) { + require_once dirname( __DIR__ ) . '/BootstrapManager.php'; + } + \WPMedia\PHPUnit\BootstrapManager::setupConstants( 'unit' ); +} + require_once WPMEDIA_PHPUNIT_ROOT_DIR . '/vendor/yoast/wp-test-utils/src/BrainMonkey/bootstrap.php'; require_once dirname( dirname( __FILE__ ) ) . '/bootstrap-functions.php'; init_test_suite();