Changeset 51813
- Timestamp:
- 09/14/2021 06:52:57 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/bootstrap.php
r51812 r51813 62 62 * The PHPUnit Polyfills are a requirement for the WP test suite. 63 63 * 64 * For running the Core tests, the Make WordPress Core handbook contains step-by-step instructions 65 * on how to get up and running for a variety of supported workflows: 66 * {@link https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/#test-running-workflow-options} 67 * 64 68 * Plugin/theme integration tests can handle this in any of the following ways: 65 69 * - When using a full WP install: run `composer update` for the WP install prior to running the tests. 66 70 * - When using a partial WP test suite install: 67 * - Add a `yoast/phpunit-polyfills` (dev) requirement to the irown `composer.json` file.71 * - Add a `yoast/phpunit-polyfills` (dev) requirement to the plugin/theme's own `composer.json` file. 68 72 * - And then: 69 73 * - Either load the PHPUnit Polyfills autoload file prior to running the WP core bootstrap file. 70 * - Or declare a `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant pointing to the root directory 71 * of the PHPUnit Polyfills installation. 72 * This constant can be declared in the `phpunit.xml[.dist]` file like this: 73 * `<php><const name="WP_TESTS_PHPUNIT_POLYFILLS_PATH" value="path/to/yoast/phpunit-polyfills"/></php> 74 * or can be declared as a PHP constant in the `wp-tests-config.php` file or the plugin/theme 75 * test bootstrap file. 74 * - Or declare a `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant containing the absolute path to the 75 * root directory of the PHPUnit Polyfills installation. 76 * If the constant is used, it is strongly recommended to declare this constant in the plugin/theme's 77 * own test bootstrap file. 78 * The constant MUST be declared prior to calling this file. 76 79 */ 77 80 if ( ! class_exists( 'Yoast\PHPUnitPolyfills\Autoload' ) ) { 78 81 // Default location of the autoloader for WP core test runs. 79 $phpunit_polyfills_autoloader = __DIR__ . '/../../../vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php';82 $phpunit_polyfills_autoloader = dirname( dirname( dirname( __DIR__ ) ) ) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php'; 80 83 $phpunit_polyfills_error = false; 81 84 … … 93 96 } 94 97 95 $phpunit_polyfills_path = realpath( $phpunit_polyfills_path ); 96 if ( false !== $phpunit_polyfills_path ) { 97 $phpunit_polyfills_autoloader = $phpunit_polyfills_path; 98 } else { 99 $phpunit_polyfills_error = true; 100 } 98 $phpunit_polyfills_autoloader = $phpunit_polyfills_path; 101 99 } else { 102 100 $phpunit_polyfills_error = true; … … 112 110 ); 113 111 echo 'Please verify that the file path provided in the WP_TESTS_PHPUNIT_POLYFILLS_PATH constant is correct.' . PHP_EOL; 112 echo 'The WP_TESTS_PHPUNIT_POLYFILLS_PATH constant should contain an absolute path to the root directory' 113 . ' of the PHPUnit Polyfills library.' . PHP_EOL; 114 114 } elseif ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) { 115 115 echo 'You need to run `composer update` before running the tests.' . PHP_EOL; 116 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; 116 echo 'Once the dependencies are installed, you can run the tests using the Composer-installed version' 117 . ' of PHPUnit or using a PHPUnit phar file, but the dependencies do need to be installed' 118 . ' whichever way the tests are run.' . PHP_EOL; 117 119 } else { 118 echo 'If you are trying to run plugin/theme integration tests, make sure the PHPUnit Polyfills library is available and either load the autoload file of this library in your own test bootstrap before calling the WP Core test bootstrap file; or set the path to the PHPUnit Polyfills library in a "WP_TESTS_PHPUNIT_POLYFILLS_PATH" constant to allow the WP Core bootstrap to load the Polyfills.' . PHP_EOL . PHP_EOL; 119 echo 'If you are trying to run the WP Core tests, make sure to set the "WP_RUN_CORE_TESTS" constant to 1 and run `composer update` before running the tests.' . PHP_EOL; 120 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; 120 echo 'If you are trying to run plugin/theme integration tests, make sure the PHPUnit Polyfills library' 121 . ' (https://github.com/Yoast/PHPUnit-Polyfills) is available and either load the autoload file' 122 . ' of this library in your own test bootstrap before calling the WP Core test bootstrap file;' 123 . ' or set the absolute path to the PHPUnit Polyfills library in a "WP_TESTS_PHPUNIT_POLYFILLS_PATH"' 124 . ' constant to allow the WP Core bootstrap to load the Polyfills.' . PHP_EOL . PHP_EOL; 125 echo 'If you are trying to run the WP Core tests, make sure to set the "WP_RUN_CORE_TESTS" constant' 126 . ' to 1 and run `composer update` before running the tests.' . PHP_EOL; 127 echo 'Once the dependencies are installed, you can run the tests using the Composer-installed' 128 . ' version of PHPUnit or using a PHPUnit phar file, but the dependencies do need to be' 129 . ' installed whichever way the tests are run.' . PHP_EOL; 121 130 } 122 131 exit( 1 ); … … 137 146 ) { 138 147 printf( 139 'Error: Version mismatch detected for the PHPUnit Polyfills. Please ensure that PHPUnit Polyfills %s or higher is loaded. Found version: %s' . PHP_EOL, 148 'Error: Version mismatch detected for the PHPUnit Polyfills.' 149 . ' Please ensure that PHPUnit Polyfills %s or higher is loaded. Found version: %s' . PHP_EOL, 140 150 $phpunit_polyfills_minimum_version, 141 151 defined( '\Yoast\PHPUnitPolyfills\Autoload::VERSION' ) ? Yoast\PHPUnitPolyfills\Autoload::VERSION : '1.0.0 or lower' … … 143 153 if ( defined( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) ) { 144 154 printf( 145 'Please ensure that the PHPUnit Polyfill install in "%s" is updated to version %s or higher.' . PHP_EOL,155 'Please ensure that the PHPUnit Polyfill installation in "%s" is updated to version %s or higher.' . PHP_EOL, 146 156 WP_TESTS_PHPUNIT_POLYFILLS_PATH, 147 157 $phpunit_polyfills_minimum_version
Note: See TracChangeset
for help on using the changeset viewer.