Closed davidperezgar closed 2 days ago
Hi @davidperezgar, thanks for the question! I think we probably need to update the documentation for running tests locally when you're using environments that don't already support PHPUnit.
The npm run test-php
command is intended to use when developing using the @wordpress/env
package (i.e., wp-env
). The composer test
script ensures that the version of PHPUnit installed via the dependency definitions of the composer.json
file are used to run the tests, but it doesn't actually set up the test environment for you.
Given the many ways that people might be developing plugins using this tool, I think it would be a good idea for us to improve the included tools to provide ways to more easily run these locally on various environments.
Thanks @joemcgill ! Yes, I'm trying to finishing my PR and I need to make the tests working.
I use that, but I get this error:
OCI runtime exec failed: exec failed: unable to start container process: chdir to cwd ("/var/www/html/wp-content/plugins/Local") set in config.json failed: no such file or directory: unknown
✖ Command failed with exit code 126
Command failed with exit code 126
Do you know if it's needed that config.js? What would be the content?
Hi @davidperezgar! Could you please describe your local setup? Are you using wp-env
to start the local environment? The error message provided doesn't give much information on its own.
I recently cloned this repo and ran PHPUnit tests using wp-env
, and everything worked as expected. Here are the steps I followed after cloning the repo:
npm ci
npm run wp-env start
npm run test-php
Thanks! I'm getting these errors:
service "tests-cli" is not running ✖ Command failed with exit code 1 Command failed with exit code 1 ℹ Starting 'composer dump --dev' on the tests-cli container.
service "tests-cli" is not running ✖ Command failed with exit code 1 Command failed with exit code 1 ℹ Starting 'composer --working-dir=build-phpunit update --no-interaction' on the tests-cli container.
service "tests-cli" is not running ✖ Command failed with exit code 1 Command failed with exit code 1
the command npm run test-php
that is:
wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename $(pwd)) build-phpunit/vendor/bin/phpunit -c phpunit.xml.dist --verbose
takes me to:
/var/www/html/wp-content/plugins/Local
something is not well configured
Thanks @joemcgill for helping me solving the problem. It was the name of the folder has an space and that would breaks the tests.
/Users/davidperez/Local Sites/wpplugins/app/public/wp-content/plugins/plugin-check
I've moved to another folder different than "Local Sites" and reinitiate all setup and now is working for me.
We have to add it in the documentation.
I've reopened the issue to make changes in the documentation to allow users to know how to run tests
I'm finishing my check and I'd need some help about tests setup.
As I understand, is running:
npm run test-php
orcomposer test
but there are some setup that I don't find it clearly.Could you share with me how to make the setup?