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

Execute Unit Tests in wp-env #32456

Closed
wants to merge 32 commits into from
Closed

Execute Unit Tests in wp-env #32456

wants to merge 32 commits into from

Conversation

ObliviousHarmony
Copy link
Contributor

All Submissions:

Changes proposed in this Pull Request:

This pull request makes changes to the unit test suite in order to support executing the tests within the wp-env environment. This will make it easier for people to start developing locally since they won't need to do anything special to run the test suite anymore.

Closes #32436.

How to test the changes in this Pull Request:

  1. Run wp-env start

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?

Changelog entry

N/A

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@ObliviousHarmony ObliviousHarmony changed the title Testing Config Changes Execute Unit Tests in wp-env Apr 1, 2022
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Apr 1, 2022
@ObliviousHarmony ObliviousHarmony force-pushed the add/wp-env-phpunit branch 2 times, most recently from f9f1fed to 48cd5f5 Compare April 8, 2022 07:49
@ObliviousHarmony ObliviousHarmony force-pushed the add/wp-env-phpunit branch 13 times, most recently from 7a64074 to c62dbf7 Compare April 27, 2022 18:13
@ObliviousHarmony
Copy link
Contributor Author

I've landed an upstream change in wp-env that will resolve the outstanding problems with executing the unit tests. I'd like to wait for #33079 to land and rebase this pull request against it in order to take that into consideration when executing the test command itself.

This allows us to run unit tests without running the
install.sh script that used to download a version
of WordPress and associated tests.
This moves our unit test execution into the
`wp-env` tests container. This also updates
the CI workflow file so that it will also
execute the tests in the environment.
The permissions on the `wp-env` container
prevent manipulating files and folders outside
of the web root. This means that the traversal
test cannot function correctly. Technically
this decreases the quality of the test,
since it is ambiguous whether or not the
test failed due to the missing file, but
technically speaking, there's no easy way
to make this work.
There are a few tests that fail when ABSPATH
is not absolute.
With the position of the plugin now in the correct
location, path tokenization for the template cache
works in tests. This tokenizes the expected path
so that the test is no longer failing. As a bonus,
this means we're now testing the tokenization too!
This changes the code coverage to use `wp-env`
as well.
Since we're explicitly selecting 5.9 for the
`wp-phpunit/wp-phpunit` package, we also
want to explicitly use WordPress 5.9's version.
Since we aren't always using WordPress 5.9, we need
to make sure that the version of the test package
also matches WordPress.
Since `wp-env` now contains an environment variable
for setting the Core version, we no longer need the
hacky setup script in our workflows. This commit removes
that and applies the change to `wp-env run` as well.
@botwoo
Copy link
Collaborator

botwoo commented Jun 7, 2022

📊 Test reports for this pull request have been published and are accessible through the following links:

Latest commit referenced in the reports: Updated wp-env and Workflows 3bf59d2
This comment will automatically be updated with the latest referenced commit when you push new changes to this pull request.


Visit the WooCommerce Test Reports homepage to view all published reports. See the FAQs page if you're having problems accessing them.

@ObliviousHarmony
Copy link
Contributor Author

Since this PR was initially created, a few different upstream changes have made much of it either obsolete or unnecessary. Rather than continuing to keep this open, I'm going to close the pull request in favor of making a new one once the final upstream change has been created.

@ObliviousHarmony ObliviousHarmony deleted the add/wp-env-phpunit branch June 15, 2022 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: woocommerce Issues related to the WooCommerce Core plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Execute PHP Unit Tests using wp-env
2 participants