Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A guide for making tests setup #466

Closed
davidperezgar opened this issue Jun 2, 2024 · 7 comments · Fixed by #477
Closed

A guide for making tests setup #466

davidperezgar opened this issue Jun 2, 2024 · 7 comments · Fixed by #477
Assignees

Comments

@davidperezgar
Copy link
Member

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
Copy link
Member

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.

@joemcgill joemcgill self-assigned this Jun 3, 2024
@davidperezgar
Copy link
Member Author

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
Copy link
Member

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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

@davidperezgar davidperezgar linked a pull request Jun 24, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants