Skip to content

Commit 3062b3d

Browse files
Build/Test Tools: Improve messaging when PHPUnit Polyfills do not comply with version requirements.
Previously, two situations were taken in to account: 1. The `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant is defined => just show a message about the version mismatch. 2. The constant is not defined => show a message to run `composer update`. This message is intended for people trying to run the WP Core tests. This could lead to an unclear situation for people trying to run plugin/theme integration tests without the new `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant being defined. They could be shown the message to run `composer update` while if they would do so for their local install without adding the Polyfills, the message would still display the next time they would attempt to run the tests. This commit: 1. Provides more information about the PHPUnit Polyfills version detected vs the version expected. 2. Shows a more specific message to guide users which have the `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant declared. 3. Only shows the message to run `composer update` when the `WP_RUN_CORE_TESTS` constant is declared to prevent confusing people more. Follow-up to [51598], [51810], [51811]. Props jrf, schlessera, hellofromTonya, jeherve, lucatume. See #46149. git-svn-id: https://develop.svn.wordpress.org/trunk@51812 602fd350-edb4-49c9-b593-d223f7449a82
1 parent c3a3da8 commit 3062b3d

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

tests/phpunit/includes/bootstrap.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,20 @@
133133
$phpunit_polyfills_minimum_version = '1.0.1';
134134
if ( class_exists( '\Yoast\PHPUnitPolyfills\Autoload' )
135135
&& ( defined( '\Yoast\PHPUnitPolyfills\Autoload::VERSION' ) === false
136-
|| version_compare( \Yoast\PHPUnitPolyfills\Autoload::VERSION, $phpunit_polyfills_minimum_version, '<' ) )
136+
|| version_compare( Yoast\PHPUnitPolyfills\Autoload::VERSION, $phpunit_polyfills_minimum_version, '<' ) )
137137
) {
138138
printf(
139-
'Error: Version mismatch detected for the PHPUnit Polyfills. Please ensure that PHPUnit Polyfills %s or higher is loaded.' . PHP_EOL,
140-
$phpunit_polyfills_minimum_version
139+
'Error: Version mismatch detected for the PHPUnit Polyfills. Please ensure that PHPUnit Polyfills %s or higher is loaded. Found version: %s' . PHP_EOL,
140+
$phpunit_polyfills_minimum_version,
141+
defined( '\Yoast\PHPUnitPolyfills\Autoload::VERSION' ) ? Yoast\PHPUnitPolyfills\Autoload::VERSION : '1.0.0 or lower'
141142
);
142-
if ( ! defined( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) ) {
143+
if ( defined( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) ) {
144+
printf(
145+
'Please ensure that the PHPUnit Polyfill install in "%s" is updated to version %s or higher.' . PHP_EOL,
146+
WP_TESTS_PHPUNIT_POLYFILLS_PATH,
147+
$phpunit_polyfills_minimum_version
148+
);
149+
} elseif ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) {
143150
echo 'Please run `composer update` to install the latest version.' . PHP_EOL;
144151
}
145152
exit( 1 );

0 commit comments

Comments
 (0)