Closed pvogel2 closed 4 years ago
Just ran into this exact issue myself. Was thinking about trying to set up @wordpress/env
to run the PHPUnit tests for a plugin, but couldn't get it working. Then went back to Gutenberg to see how it was done here and realized npm run test-unit-php
it isn't working here either! 🙃
So I think I've found the culprit. This issue appears to occur when you also have wp-env
installed globally. The test-unit-php
command calls wp-env run phpunit
.
It seems when I change it to npm run wp-env run phpunit
then it will work as long as I've already run npm run wp-env start
at least once before.
Another note is that you need to have run wp-env start
locally before running the PHP unit tests. I've added a note to the docs about this in the PR, and I think we should consider running wp-env start as the first step in the test-php code :)
The reason is that wp-env start calls the wp installation code which sets the needed wp-config constants.
Hi, thanks @earnjam
So I think I've found the culprit. This issue appears to occur when you also have
wp-env
installed globally. Thetest-unit-php
command callswp-env run phpunit
.It seems when I change it to
npm run wp-env run phpunit
then it will work as long as I've already runnpm run wp-env start
at least once before.
I could reproduce this behaviour by tweeking the package.json as you described. Then the tests are performed sucessfully. And thx to @noahtallen for working on a sollution.
@pvogel2 We drilled into the problem a bit more and realized that you don't have to change anything if you just run npm run wp-env start
first.
The environment seemed like it was working fine independent of the testing, but my problem is I had run wp-env start
without the npm run
before it. So that set up the site outside the repo in the global context. Then when running npm run test-unit-php
it was using the local wp-env
script which was using a different set of containers that hadn't been provisioned yet.
@noahtallen is working on a PR that updates the documentation to reflect that required step and also exploring some changes to automatically run start
if needed.
OK, I get it now :-) . You are right. Without tweeking tests are also running when the environment ist started before. 👍 Can not beleave that I did not try this out :-)
Describe the bug Hi everyone. I have a checkout of the gutenberg repository and try to get the php tests up and running by calling
npm run test-php
. I have initially callednpm install
and use the local environment setup.When the script is executed it first calls the composer docker image and installs all needed dependencies. Then the linting is checked successfully. In the next step the unit tests are executed and the script fails with errors. Here is the complete cmdline output of the run:
To reproduce
npm install
npm run build
npm run test-php
Expected behavior I guess the tests should be performed without exception :-)
Versions:
Additional context Maybe I am missing something here, I do not know. I followed the description on this page: https://developer.wordpress.org/block-editor/contributors/develop/testing-overview/ I debugged into the php code and could get forward by defining the missing constants in the related php scripts, but failed then at a later state in the code again.