Skip to content

Commit

Permalink
Tests: make sure all files are namespaced
Browse files Browse the repository at this point in the history
... including the test bootstrap.

Includes ensuring that all calls to global functions and global constants are now fully qualified.
  • Loading branch information
jrfnl committed Nov 17, 2023
1 parent 9081aa2 commit b0695e6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
16 changes: 9 additions & 7 deletions tests/unit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down
16 changes: 9 additions & 7 deletions tests/wp/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
);

Expand Down

0 comments on commit b0695e6

Please sign in to comment.