From a028cfb49cc7a4249e160201e7a0740a63980a13 Mon Sep 17 00:00:00 2001 From: Alda Vigdis Skarphedinsdottir Date: Fri, 22 Mar 2024 02:09:25 +0100 Subject: [PATCH] Cleaning up the bootstrap.php file (#26) * Cleaning up the bootstrap.php file - Moving some of the conditionals and functionalities from bootstrap.php file into a separate class - Moving the "require" bits into the Bootstrap::init() function - Moving the test environment inclusion into a separate function --- bootstrap.php | 28 +++++---------------------- composer.lock | 2 +- src/Bootstrap.php | 15 +++++++++++++++ src/SetEnv.php | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 24 deletions(-) create mode 100644 src/SetEnv.php diff --git a/bootstrap.php b/bootstrap.php index b650647..c3d83e1 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -4,30 +4,12 @@ require_once 'vendor/autoload.php'; -# The WP test suite assumes the existence of classes that only exist in -# version 9 and older of PHPUnit. This solves that. -if ( 1 === version_compare( \PHPUnit\Runner\Version::id(), '10' ) ) { - require __DIR__ . '/supressors/SupressFramework.php'; - require __DIR__ . '/supressors/SupressFrameworkError.php'; -} - use Aldavigdis\WpTestsStrapon\Bootstrap; -use Aldavigdis\WpTestsStrapon\FetchWP; - -if (getenv('WP_VERSION') === false) { - putenv('WP_VERSION=master'); -} +use Aldavigdis\WpTestsStrapon\SetEnv; -if (defined('WP_TESTS_CONFIG_FILE_PATH') === false) { - define( - 'WP_TESTS_CONFIG_FILE_PATH', - Aldavigdis\WpTestsStrapon\Config::path() - ); -} +SetEnv::supress(); +SetEnv::setWpVersion(); +SetEnv::setConfigFilePath(); Bootstrap::init(getenv('WP_VERSION')); - -require FetchWP::extractDirPath() . 'wordpress-develop-trunk/tests/phpunit/includes/functions.php'; -ob_start(); -require FetchWP::extractDirPath() . 'wordpress-develop-trunk/tests/phpunit/includes/bootstrap.php'; -ob_end_clean(); +Bootstrap::requireWordPressTestEnv(); diff --git a/composer.lock b/composer.lock index 4ebdb19..31dcc02 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "dbc4d02b7215ae5dfb1ffd28e87ce7ea", + "content-hash": "50e46c0920f200025eafd691dede4e62", "packages": [ { "name": "myclabs/deep-copy", diff --git a/src/Bootstrap.php b/src/Bootstrap.php index 7b2cfe5..7f7937e 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -386,6 +386,21 @@ public static function init(string $wp_version): void self::displaySeparator(); } + /** + * Require the WP test environment + * + * This enables us to use WordPress' built-in functions in our tests. + */ + public static function requireWordPressTestEnv(): void { + require FetchWP::extractDirPath() . + 'wordpress-develop-trunk/tests/phpunit/includes/functions.php'; + + ob_start(); + require FetchWP::extractDirPath() . + 'wordpress-develop-trunk/tests/phpunit/includes/bootstrap.php'; + ob_end_clean(); + } + /** * Get the width for the current terminal * diff --git a/src/SetEnv.php b/src/SetEnv.php new file mode 100644 index 0000000..f6183eb --- /dev/null +++ b/src/SetEnv.php @@ -0,0 +1,49 @@ +