Skip to content

Commit 47303b1

Browse files
Build/Test Tools: Unify the PHPUnit adapter TestCases.
This commit: * Removes the PHPUnit 7 specific `TestCase`. * Removes all existing polyfills from the PHPUnit 5.x `TestCase`. * Imports all polyfill traits from the PHPUnit Polyfills package into the `WP_UnitTestCase` class and updates the DocBlock to reflect the actual function of the class. * Note: The list of polyfills needs to be verified and updated after each new release of the PHPUnit Polyfills package. Alternatively (recommended), one of the built-in `TestCase` classes from the PHPUnit Polyfills package can be used instead. * Moves the `require` for the WP `abstract-testcase.php` to the `bootstrap.php` file. * Adds a `require_once` for the PHPUnit Polyfills autoloader to the `bootstrap.php` file. * Note: while this isn't _strictly_ necessary when the tests are run via Composer, having the include in the bootstrap allows for the tests to also be run via a PHPUnit Phar, providing contributors with more flexibility. Follow-up to [51559]. Props jrf, hellofromTonya, johnbillion, netweb, SergeyBiryukov. See #46149. git-svn-id: https://develop.svn.wordpress.org/trunk@51560 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 8ebd8ec commit 47303b1

File tree

3 files changed

+49
-447
lines changed

3 files changed

+49
-447
lines changed

tests/phpunit/includes/bootstrap.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@
5050
require_once __DIR__ . '/class-mockobject-autoload.php';
5151
spl_autoload_register( 'MockObject_Autoload::load', true, true );
5252

53+
// Check that the PHPUnit Polyfills autoloader exists.
54+
$phpunit_polyfills_autoloader = __DIR__ . '/../../../vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php';
55+
if ( ! file_exists( $phpunit_polyfills_autoloader ) ) {
56+
echo "Error: You need to run `composer update` before running the tests.\n";
57+
echo "You can still use a PHPUnit phar to run them, but the dependencies do need to be installed.\n";
58+
exit( 1 );
59+
}
60+
5361
// If running core tests, check if all the required PHP extensions are loaded before running the test suite.
5462
if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) {
5563
$required_extensions = array(
@@ -195,13 +203,12 @@ function wp_tests_options( $value ) {
195203
require __DIR__ . '/phpunit6/compat.php';
196204
}
197205

198-
// Load separate WP_UnitTestCase classes for PHPUnit 7.5+ and older versions.
199-
if ( version_compare( tests_get_phpunit_version(), '7.5', '>=' ) ) {
200-
require __DIR__ . '/phpunit7/testcase.php';
201-
} else {
202-
require __DIR__ . '/testcase.php';
203-
}
206+
// Load the PHPUnit Polyfills autoloader (check for existence of the file is done earlier in the script).
207+
require_once $phpunit_polyfills_autoloader;
208+
unset( $phpunit_polyfills_autoloader );
204209

210+
require __DIR__ . '/abstract-testcase.php';
211+
require __DIR__ . '/testcase.php';
205212
require __DIR__ . '/testcase-rest-api.php';
206213
require __DIR__ . '/testcase-rest-controller.php';
207214
require __DIR__ . '/testcase-rest-post-type-controller.php';

tests/phpunit/includes/phpunit7/testcase.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)