Skip to content

Complete PHPUnit infrastructure for out-of-the-box local and CI testing, including initial tests #29

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

Merged
merged 9 commits into from
Dec 2, 2021

Conversation

felixarntz
Copy link
Member

This PR completes the PHPUnit infrastructure so that the repository allows to easily run PHPUnit tests locally in a centralized environment. It also includes a GitHub action to ensure PHPUnit tests run as CI.

The implementation here is pretty much copied over from Gutenberg, reusing the @wordpress/env package, which allows us to keep the code here simple.

In detail, this PR includes:

  • minimal package.json file to include @wordpress/env dependency and PHP linting/testing scripts
  • PHPUnit configurations and test commands for single site and multisite which can be run locally without any additional setup (the only tools required are Node and Docker)
  • GitHub action php-test.yml to run the above tests automatically on push and PR merge
  • test coverage for the functions in the plugin main file load.php (which is all PHP code that exists so far)

Please see the README.md additions for which commands to use locally to run PHP linting and testing.

Fixes #28

Copy link
Member

@JustinyAhin JustinyAhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixarntz I've tested this, and it looks good overall.
Just added a little comment about the documentation.

@@ -1,3 +1,13 @@
# WordPress Performance

Monorepo for the [WordPress Performance Group](https://make.wordpress.org/core/tag/performance/), primarily for the overall performance plugin, which is a collection of standalone performance modules.

## Useful commands

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it makes sense to mention we need to have Docker up and running before running the wp-env commands. And/or link to the handbook (https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to that, for someone without Docker this npm run wp-env start and everything after fails.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point, I added a note about both Node.js and Docker being required.

@adamsilverstein
Copy link
Member

@felixarntz when I tried running npm install I got a warning message:

image

Apparently my current npm version of 7.10.0 is too high? I can switch to a lower npm version to get around this, however I'd rather fix the issue if we can. Any idea why this limitation of npm < v 7 is in place? cc @gziolo who may know.

For what its worth, I get a similar error (not warning) when I try to do npm install in the gutenberg repo:
image

@adamsilverstein
Copy link
Member

@felixarntz - this looks great! I left a few questions.

I was able to run the tests locally without docker by setting WP_TESTS_DIR to my development tests folder (wordpress-develop/tests/phpunit/).

@felixarntz
Copy link
Member Author

@JustinyAhin @ThierryA @adamsilverstein Updated based on your feedback!

I was able to run the tests locally without docker by setting WP_TESTS_DIR to my development tests folder (wordpress-develop/tests/phpunit/).

Yes, this is intended. The NPM commands (outlined in the README.md) are the easiest way to get started, you just need Node.js and Docker. However, the implementation leaves the freedom for folks to use another approach locally, e.g. if you don't want to use Docker, you can also install Composer, set up the WordPress test suite and a database somewhere locally. In that case, the Composer commands can be used directly, they all run locally. However, that is more complex to get up and running, so to get started NPM is the recommended approach.

Copy link
Member

@adamsilverstein adamsilverstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

@adamsilverstein adamsilverstein self-requested a review December 2, 2021 19:01
@felixarntz felixarntz merged commit 6fbfcc4 into trunk Dec 2, 2021
@felixarntz felixarntz added [Type] Enhancement A suggestion for improvement of an existing feature Infrastructure Issues for the overall performance plugin infrastructure no milestone PRs that do not have a defined milestone for release labels Dec 16, 2021
@tillkruss tillkruss deleted the add/phpunit-infrastructure branch March 7, 2022 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Infrastructure Issues for the overall performance plugin infrastructure no milestone PRs that do not have a defined milestone for release [Type] Enhancement A suggestion for improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Complete PHP unit testing and linting infrastructure
5 participants