-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add instructions for running PHPUnit with wp-env. #2276
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,6 +136,37 @@ $ vendor/bin/phpunit | |
|
||
The tests will execute and you'll be presented with a summary. | ||
|
||
### Running tests using `wp-env` | ||
|
||
To run PHPUnit from within the included `wp-env` environment, you will need to load the development version of the WooCommerce plugin in your environment. | ||
|
||
First, clone the WooCommerce repo, replacing `${WC_VERSION}` with the latest version of the plugin (e.g. 8.6.1): | ||
|
||
```bash | ||
$ git clone --depth=1 --branch="${WC_VERSION}" https://github.com/woocommerce/woocommerce.git ../woocommerce/` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the instructions assume we are going to place On my install if I'd have a development version of WooCommerce installed I'd have a symlink in my There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, this is not as intuitive as it could be. Essentially, I'm trying to avoid adding these files to the same folder that the GLA plugin repo lives, so folks don't have to worry about another The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I'm fine with leaving it as is (I prefer it outside the plugin folder). Just a note to clarify that any location can be used (since a lot of people would already have a copy or I could point it to the copy installed by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The bootstrap process doesn't really have a lot of heavy requirements, it just loads 4 files directly with the full path: https://github.com/woocommerce/google-listings-and-ads/blob/2.6.0/tests/bootstrap.php#L63-L66 It also checks for the presence of bootstrap.php but that's only to confirm the legacy path, which can easily be checked differently. Building the WooCommerce plugin is required because it loads a copy of the plugin during unit testing. However that's not required to be a dev copy. So for unit testing it would just as happily run with the following two (as long as the WC version matched between the two):
I wouldn't mind changing bootstrap.php to check in a different location to encounter those test files (check in a different location and otherwise fallback to where it's looking now). That way we'd just need a mapping in wp-env to tell it where the test files are. You'd lose a little flexibility of being able to run unit tests with any WC branch, but would simplify the process. |
||
``` | ||
|
||
Build the woocommerce plugin (see [this document](DEVELOPMENT.md) for additional instructions): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm assuming this should link to DEVELOPMENT.md in the WC repo? Can we set that link to the right repo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes of course 🙃. I'll update it to the full URL. |
||
- Go to the plugin directory: `cd ../woocommerce/plugins/woocommerce/` | ||
- Install dependencies: `pnpm install` | ||
- Build the plugin: `pnpm --filter=@woocommerce/plugin-woocommerce build` | ||
|
||
Go back to the Google Listings and Ads directory and create a `.wp-env.override.json` file containing the following: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is meant to be an override / local only file, can we get it included in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would probably be a good idea. I have |
||
```json | ||
{ | ||
"plugins": [ | ||
"../woocommerce/plugins/woocommerce", | ||
"." | ||
] | ||
} | ||
``` | ||
|
||
Restart your wp-env environment: `npm run wp-env start` | ||
|
||
You should now be able to run unit tests locally via the CLI: `npm run test:php`. | ||
|
||
To pass additional arguments to PHPUnit, make sure they are preceded by an additional `--`, like `npm run test:php -- --filter my_test_method`. | ||
|
||
## E2E Testing | ||
|
||
E2E testing uses [wp-env](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/) which requires [Docker](https://www.docker.com/). | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,7 @@ | |
"test:e2e-dev": "npx playwright test --config=tests/e2e/config/playwright.config.js --debug", | ||
"test:js": "wp-scripts test-unit-js --coverage", | ||
"test:js:watch": "npm run test:js -- --watch", | ||
"test:php": "wp-env run tests-wordpress --env-cwd=./wp-content/plugins/$(basename $(pwd)) ./vendor/bin/phpunit", | ||
"test-proxy": "node ./tests/proxy", | ||
"wp-env": "wp-env", | ||
"wp-env:up": "npm run -- wp-env start --update", | ||
|
@@ -171,4 +172,4 @@ | |
"node": "^16 || ^18", | ||
"npm": "^8 || ^9" | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't seem like we need to change this, as the next person (with it auto enabled) is probably going to add it again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. I think my editor auto-formatted this during save. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we explicitly mention this is for running "unit tests" so it's doesn't get confused with the E2E tests being run with wp-env?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻 Sure! It's already a sub-heading under the PHPUnit section, but making it more clear never hurts.