The WP core test suite didn't introduce includes/listener-loader.php until WordPress 5.1, so we need to polyfill the behavior when testing against WordPress 5.0

This commit is contained in:
Steve Grunwell 2020-03-11 16:34:52 +00:00
parent 70e7a8ed08
commit 0a3c5186fa
1 changed files with 39 additions and 1 deletions

View File

@ -6,4 +6,42 @@
*/
$wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : '/tmp/wordpress-tests-lib';
require_once $wp_tests_dir . '/includes/listener-loader.php';
/**
* The listener-loader.php file wasn't introduced into the core test framework until r44701, which
* means it came after WordPress 5.0 (r43971).
*
* Once WordPress 5.0 is no longer supported, we can safely reduce this to:
*
* require_once $wp_tests_dir . '/includes/listener-loader.php';
*
* @link https://core.trac.wordpress.org/changeset/44701/
*/
if ( file_exists( $wp_tests_dir . '/includes/listener-loader.php' ) ) {
require_once $wp_tests_dir . '/includes/listener-loader.php';
} else {
if ( version_compare( tests_get_phpunit_version(), '7.0', '>=' ) ) {
require $wp_tests_dir . '/includes/phpunit7/speed-trap-listener.php';
} else {
require $wp_tests_dir . '/includes/speed-trap-listener.php';
}
}
// Polyfill a function that wasn't added until WordPress 5.1.
if ( ! function_exists( 'tests_get_phpunit_version' ) ) {
/**
* Retrieves PHPUnit runner version.
*/
function tests_get_phpunit_version() {
if ( class_exists( 'PHPUnit_Runner_Version' ) ) {
$version = PHPUnit_Runner_Version::id();
} elseif ( class_exists( 'PHPUnit\Runner\Version' ) ) {
// Must be parsable by PHP 5.2.x.
$version = call_user_func( 'PHPUnit\Runner\Version::id' );
} else {
$version = 0;
}
return $version;
}
}