WordPress / plugin-check

A repository for the new Plugin Check plugin from the WordPress Performance and Plugins Team.
https://wordpress.org/plugins/plugin-check/
GNU General Public License v2.0
195 stars 39 forks source link

A guide for making tests setup #466

Closed davidperezgar closed 2 days ago

davidperezgar commented 4 weeks ago

I'm finishing my check and I'd need some help about tests setup.

As I understand, is running: npm run test-php or composer test but there are some setup that I don't find it clearly.

Could you share with me how to make the setup?

joemcgill commented 4 weeks 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.

davidperezgar commented 3 weeks ago

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?

thelovekesh commented 2 weeks ago

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
davidperezgar commented 2 weeks ago

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

davidperezgar commented 1 week ago

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

davidperezgar commented 1 week ago

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.

davidperezgar commented 1 week ago

I've reopened the issue to make changes in the documentation to allow users to know how to run tests