Closed mszkb closed 9 months ago
@mszkb Sorry you are experiencing problems, but this is not an issue with the PHPUnit Polyfills. but user error.
You should never include vendor
in your classmap and most definitely not in an autoload
directive.
Each dependency defines their own autoload requirements and Composer puts those all together resulting in a vendor/autoload.php
file (with sub-files) which handles it all.
This file will differ depending on whether the install was run with --no-dev
or without.
The autoload
directive in your composer.json
should only include your own files.
Additionally, anything non-runtime related (like tests), should be handled via a separate autoload-dev
directive.
As side-notes:
^2.0
version as the WP Core test suite is not compatible with PHPUnit 10/PHPUnit Polyfills 2.0. You need to use ^1.0
.All in all, I don't know those tutorials, but you may want to educate yourself about the use of Composer a little more. I'd suggest starting with the Composer documentation: https://getcomposer.org/doc/
This issue occured when I wanted to make run Wordpress plugin Integrationtests. I used following tutorials: https://make.wordpress.org/cli/handbook/misc/plugin-unit-tests/ and https://sarathlal.com/unit-testing-wordpress-plugin-using-phpunit/
Following those tutorials, running phpunit requires me to install yoast/phpunit-polyfills. Doing so gives me biiig warnings during installing phase. Afterwards when I want to run phpunit
./bin/vendor/phpunit -c phpunit.xml.dist
it gives me some weird errors:It turns out, I had to exclude the yoast dependency from the classmapping of composer. Then everything works fine. Like this:
Doing
composer update
it does not show significant warnings and finally./bin/vendor/phpunit -c phpunit.xml.dist
does work.Maybe you can address this issue by the next release. Right now it works with the exclusion. I hope this helps somebody.