Changeset 51598
- Timestamp:
- 08/10/2021 09:13:38 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/composer.json
r51574 r51598 18 18 "wp-coding-standards/wpcs": "~2.3.0", 19 19 "phpcompatibility/phpcompatibility-wp": "~2.1.2", 20 "yoast/phpunit-polyfills": "^1.0 "20 "yoast/phpunit-polyfills": "^1.0.1" 21 21 }, 22 22 "scripts": { -
trunk/tests/phpunit/includes/bootstrap.php
r51584 r51598 47 47 } 48 48 49 // Check that the PHPUnit Polyfills autoloader exists. 50 $phpunit_polyfills_autoloader = __DIR__ . '/../../../vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php'; 51 if ( ! file_exists( $phpunit_polyfills_autoloader ) ) { 52 echo 'Error: You need to run `composer update` before running the tests.' . PHP_EOL; 53 echo 'You can still use a PHPUnit phar to run them, but the dependencies do need to be installed.' . PHP_EOL; 54 exit( 1 ); 55 } 49 /* 50 * Load the PHPUnit Polyfills autoloader. 51 * 52 * The PHPUnit Polyfills are a requirement for the WP test suite. 53 * 54 * Plugin/theme integration tests can handle this in any of the following ways: 55 * - When using a full WP install: run `composer update` for the WP install prior to running the tests. 56 * - When using a partial WP test suite install: 57 * - Add a `yoast/phpunit-polyfills` (dev) requirement to their own `composer.json` file. 58 * - And then: 59 * - Either load the PHPUnit Polyfills autoload file prior to running the WP core bootstrap file. 60 * - Or declare a `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant pointing to the root directory 61 * of the PHPUnit Polyfills installation. 62 * This constant can be declared in the `phpunit.xml[.dist]` file like this: 63 * `<php><const name="WP_TESTS_PHPUNIT_POLYFILLS_PATH" value="path/to/yoast/phpunit-polyfills"/></php> 64 * or can be declared as a PHP constant in the `wp-tests-config.php` file or the plugin/theme 65 * test bootstrap file. 66 */ 67 if ( ! class_exists( 'Yoast\PHPUnitPolyfills\Autoload' ) ) { 68 // Default location of the autoloader for WP core test runs. 69 $phpunit_polyfills_autoloader = __DIR__ . '/../../../vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php'; 70 $phpunit_polyfills_error = false; 71 72 // Allow for a custom installation location to be provided for plugin/theme integration tests. 73 if ( defined( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) ) { 74 $phpunit_polyfills_path = WP_TESTS_PHPUNIT_POLYFILLS_PATH; 75 76 if ( is_string( WP_TESTS_PHPUNIT_POLYFILLS_PATH ) 77 && '' !== WP_TESTS_PHPUNIT_POLYFILLS_PATH 78 ) { 79 $phpunit_polyfills_path = rtrim( $phpunit_polyfills_path, '/\\' ); 80 $phpunit_polyfills_path = realpath( $phpunit_polyfills_path . '/phpunitpolyfills-autoload.php' ); 81 if ( false !== $phpunit_polyfills_path ) { 82 $phpunit_polyfills_autoloader = $phpunit_polyfills_path; 83 } else { 84 $phpunit_polyfills_error = true; 85 } 86 } else { 87 $phpunit_polyfills_error = true; 88 } 89 } 90 91 if ( $phpunit_polyfills_error || ! file_exists( $phpunit_polyfills_autoloader ) ) { 92 echo 'Error: The PHPUnit Polyfills library is a requirement for running the WP test suite.' . PHP_EOL; 93 if ( isset( $phpunit_polyfills_path ) ) { 94 printf( 95 'The PHPUnit Polyfills autoload file was not found in "%s"' . PHP_EOL, 96 WP_TESTS_PHPUNIT_POLYFILLS_PATH 97 ); 98 echo 'Please verify that the file path provided in the WP_TESTS_PHPUNIT_POLYFILLS_PATH constant is correct.' . PHP_EOL; 99 } else { 100 echo 'You need to run `composer update` before running the tests.' . PHP_EOL; 101 echo 'Once the dependencies are installed, you can run the tests using the Composer-installed version of PHPUnit or using a PHPUnit phar file, but the dependencies do need to be installed whichever way the tests are run.' . PHP_EOL; 102 } 103 exit( 1 ); 104 } 105 106 require_once $phpunit_polyfills_autoloader; 107 } 108 unset( $phpunit_polyfills_autoloader, $phpunit_polyfills_error, $phpunit_polyfills_path ); 109 110 /* 111 * Minimum version of the PHPUnit Polyfills package as declared in `composer.json`. 112 * Only needs updating when new polyfill features start being used in the test suite. 113 */ 114 $phpunit_polyfills_minimum_version = '1.0.1'; 115 if ( class_exists( '\Yoast\PHPUnitPolyfills\Autoload' ) 116 && ( defined( '\Yoast\PHPUnitPolyfills\Autoload::VERSION' ) === false 117 || version_compare( \Yoast\PHPUnitPolyfills\Autoload::VERSION, $phpunit_polyfills_minimum_version, '<' ) ) 118 ) { 119 printf( 120 'Error: Version mismatch detected for the PHPUnit Polyfills. Please ensure that PHPUnit Polyfills %s or higher is loaded.' . PHP_EOL, 121 $phpunit_polyfills_minimum_version 122 ); 123 if ( ! defined( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) ) { 124 echo 'Please run `composer update` to install the latest version.' . PHP_EOL; 125 } 126 exit( 1 ); 127 } 128 unset( $phpunit_polyfills_minimum_version ); 56 129 57 130 // If running core tests, check if all the required PHP extensions are loaded before running the test suite. … … 199 272 require __DIR__ . '/phpunit6/compat.php'; 200 273 } 201 202 // Load the PHPUnit Polyfills autoloader (check for existence of the file is done earlier in the script).203 require_once $phpunit_polyfills_autoloader;204 unset( $phpunit_polyfills_autoloader );205 274 206 275 require __DIR__ . '/phpunit-adapter-testcase.php';
Note: See TracChangeset
for help on using the changeset viewer.