From b0695e66eb089050fd7a74b2a9fc37a8b4da24f7 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 4 Oct 2023 10:34:29 +0200 Subject: [PATCH] Tests: make sure all files are namespaced ... including the test bootstrap. Includes ensuring that all calls to global functions and global constants are now fully qualified. --- tests/unit/bootstrap.php | 16 +++++++++------- tests/wp/bootstrap.php | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/tests/unit/bootstrap.php b/tests/unit/bootstrap.php index 7bd3fe8b5..7fe2b245d 100644 --- a/tests/unit/bootstrap.php +++ b/tests/unit/bootstrap.php @@ -5,15 +5,17 @@ * @package Yoast\WP\Duplicate_Post\Tests */ -define( 'OBJECT', 'OBJECT' ); -define( 'ARRAY_A', 'ARRAY_A' ); -define( 'ARRAY_N', 'ARRAY_N' ); +namespace Yoast\WP\Duplicate_Post\Tests\Unit; -define( 'DUPLICATE_POST_FILE', '/var/www/html/wp-content/plugins/duplicate-post/duplicate-post.php' ); -define( 'DUPLICATE_POST_CURRENT_VERSION', '4.0' ); +\define( 'OBJECT', 'OBJECT' ); +\define( 'ARRAY_A', 'ARRAY_A' ); +\define( 'ARRAY_N', 'ARRAY_N' ); -if ( file_exists( dirname( __DIR__, 2 ) . '/vendor/autoload.php' ) === false ) { - echo PHP_EOL, 'ERROR: Run `composer install` to generate the autoload files before running the unit tests.', PHP_EOL; +\define( 'DUPLICATE_POST_FILE', '/var/www/html/wp-content/plugins/duplicate-post/duplicate-post.php' ); +\define( 'DUPLICATE_POST_CURRENT_VERSION', '4.0' ); + +if ( \file_exists( \dirname( __DIR__, 2 ) . '/vendor/autoload.php' ) === false ) { + echo \PHP_EOL, 'ERROR: Run `composer install` to generate the autoload files before running the unit tests.', \PHP_EOL; exit( 1 ); } diff --git a/tests/wp/bootstrap.php b/tests/wp/bootstrap.php index 0bc1ce523..2785db2a3 100644 --- a/tests/wp/bootstrap.php +++ b/tests/wp/bootstrap.php @@ -5,28 +5,30 @@ * @package Yoast\WP\Duplicate_Post\Tests */ +namespace Yoast\WP\Duplicate_Post\Tests\WP; + use Yoast\WPTestUtils\WPIntegration; // Disable xdebug backtrace. -if ( function_exists( 'xdebug_disable' ) ) { - xdebug_disable(); +if ( \function_exists( 'xdebug_disable' ) ) { + \xdebug_disable(); } -echo 'Welcome to the Duplicate Post Test Suite' . PHP_EOL; -echo 'Version: 1.0' . PHP_EOL . PHP_EOL; +echo 'Welcome to the Duplicate Post Test Suite' . \PHP_EOL; +echo 'Version: 1.0' . \PHP_EOL . \PHP_EOL; /* * Load the plugin(s). */ -require_once dirname( __DIR__, 2 ) . '/vendor/yoast/wp-test-utils/src/WPIntegration/bootstrap-functions.php'; +require_once \dirname( __DIR__, 2 ) . '/vendor/yoast/wp-test-utils/src/WPIntegration/bootstrap-functions.php'; // Get access to tests_add_filter() function. require_once WPIntegration\get_path_to_wp_test_dir() . 'includes/functions.php'; -tests_add_filter( +\tests_add_filter( 'muplugins_loaded', function() { - require_once dirname( __DIR__, 2 ) . '/duplicate-post.php'; + require_once \dirname( __DIR__, 2 ) . '/duplicate-post.php'; } );