最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How do I get PHPUnit Polyfills set up for testing on a mac?

programmeradmin1浏览0评论

Got a mac development machine with PHP installed via brew. I'm trying to get testing tools set up. I successfully set up test scaffolding with wp cli and managed to get bin/install-wp-tests.sh to do its thing.

But I get an error with phpunit tests/test-sample.php:

Error: The PHPUnit Polyfills library is a requirement for running the WP test suite.
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 absolute path to the PHPUnit Polyfills library in a "WP_TESTS_PHPUNIT_POLYFILLS_PATH" constant to allow the WP Core bootstrap to load the Polyfills.

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 -W` before running the tests.
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.

So I ran composer require --dev yoast/phpunit-polyfills and opened a new terminal window but still get the same error. Running brew doctor doesn't show anything related to php or composer.

I don't develop with PHP much so I'm at a loss as to what else to try.

Got a mac development machine with PHP installed via brew. I'm trying to get testing tools set up. I successfully set up test scaffolding with wp cli and managed to get bin/install-wp-tests.sh to do its thing.

But I get an error with phpunit tests/test-sample.php:

Error: The PHPUnit Polyfills library is a requirement for running the WP test suite.
If you are trying to run plugin/theme integration tests, make sure the PHPUnit Polyfills library (https://github.com/Yoast/PHPUnit-Polyfills) 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 absolute path to the PHPUnit Polyfills library in a "WP_TESTS_PHPUNIT_POLYFILLS_PATH" constant to allow the WP Core bootstrap to load the Polyfills.

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 -W` before running the tests.
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.

So I ran composer require --dev yoast/phpunit-polyfills and opened a new terminal window but still get the same error. Running brew doctor doesn't show anything related to php or composer.

I don't develop with PHP much so I'm at a loss as to what else to try.

Share Improve this question asked Feb 6, 2022 at 5:36 StevieDStevieD 2212 silver badges11 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

OK, I was reading from an outdated tutorial. Command for running tests is now:

vendor/bin/phpunit <path_to_file>

This command should be Run from root directory of wordpress.

I had the same issue and resolved it by adding the composer autoload to the top of my tests/bootstrap.php file...

require 'vendor/autoload.php';

After which I can run the normal phpunit command.

发布评论

评论列表(0)

  1. 暂无评论