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

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.

Topic testing Wordpress

Category Web


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.


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.