Skip to content

Commit 49f47e0

Browse files
committed
Fix wp-env warning
1 parent 6d82946 commit 49f47e0

File tree

9 files changed

+45
-23
lines changed

9 files changed

+45
-23
lines changed

.distignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ tests
2222
.phpunit.result.cache
2323
.typos.toml
2424
.wp-env.json
25+
.wp-env.tests.json
2526
.wp-env.override.json
27+
.wp-env.tests.override.json
2628
behat.yml
2729
codecov.yml
2830
composer.lock

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
/.nvmrc export-ignore
1818
/.typos.toml export-ignore
1919
/.wp-env.json export-ignore
20+
/.wp-env.tests.json export-ignore
2021
/composer.lock export-ignore
2122
/package.json export-ignore
2223
/package-lock.json export-ignore

.github/workflows/php-test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- '.github/workflows/php-test.yml'
1111
- '**.php'
1212
- '.wp-env.json'
13+
- '.wp-env.tests.json'
1314
- '**/package.json'
1415
- 'package-lock.json'
1516
- 'phpcs-rulesets/*.xml'
@@ -26,6 +27,7 @@ on:
2627
- '.github/workflows/php-test.yml'
2728
- '**.php'
2829
- '.wp-env.json'
30+
- '.wp-env.tests.json'
2931
- '**/package.json'
3032
- 'package-lock.json'
3133
- 'phpcs-rulesets/*.xml'
@@ -91,9 +93,9 @@ jobs:
9193
- name: Start WordPress
9294
run: |
9395
if [[ ${{ matrix.coverage == true }} == true ]]; then
94-
npm run wp-env start -- --xdebug=coverage
96+
npm run wp-env start -- --config=.wp-env.tests.json --xdebug=coverage
9597
else
96-
npm run wp-env start
98+
npm run wp-env start -- --config=.wp-env.tests.json
9799
fi
98100
99101
- name: Run tests

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ temp/
6464
############
6565

6666
.wp-env.override.json
67+
.wp-env.tests.override.json

.wp-env.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{
2-
"core": null,
3-
"plugins": [ "." ],
4-
"env": {
5-
"tests": {
6-
"phpVersion": "7.4"
7-
}
8-
}
9-
}
2+
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
3+
"core": null,
4+
"plugins": [ "." ],
5+
"testsEnvironment": false
6+
}

.wp-env.tests.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
3+
"core": null,
4+
"plugins": [ "." ],
5+
"testsEnvironment": false,
6+
"phpVersion": "7.4",
7+
"port": 8889
8+
}

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,23 @@ npm install
5555

5656
With the above commands, you can use the plugin in any development environment as you like. The recommended way is to use the built-in development environment, which is based on the [`@wordpress/env` package](https://www.npmjs.com/package/@wordpress/env), as that will allow you to use the preconfigured commands to e.g. run unit tests, linting etc. You will need to have Docker installed to use this environment.
5757

58-
You can start the built-in environment as follows:
58+
Start the **development** site:
59+
5960
```
6061
npm run wp-env start
6162
```
6263

63-
If you want to stop the environment again, you can use:
64+
Start the **tests** stack:
65+
66+
```
67+
npm run wp-env:start:tests
68+
```
69+
70+
Stop each stack when finished:
71+
6472
```
6573
npm run wp-env stop
74+
npm run wp-env:stop:tests
6675
```
6776

6877
For further information on contributing, please see the [contributing guide](/CONTRIBUTING.md).

docs/running-unit-tests.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Follow these instructions to configure and run tests:
88

99
1. You would need npm installed in your computer.
1010
2. Ensure that you have installed all npm dependencies with `npm ci`.
11-
3. You need to have Docker installed and running wp-env environment `npm run wp-env start`.
11+
3. You need Docker installed. Start the tests wp-env stack with `npm run wp-env:start:tests`.
1212
4. Run tests with npm command `npm run test-php`.
1313

1414
The full test suite is run against PRs as a GitHub action ([example](https://github.com/WordPress/plugin-check/actions/runs/9660204610)) so tests can be run against all supported environments. Passing tests is a requirement for merging PRs. Being able to run them locally is meant to help developers while working on or debugging tests, prior to submitting their code for review.
@@ -18,8 +18,8 @@ The full test suite is run against PRs as a GitHub action ([example](https://git
1818
We have this structure for the tests folder:
1919

2020
- `tests/phpunit` Unit tests for the plugin.
21-
- `tests/phpunit/tests/` All PHPUnit tests that run as part of the suite.
22-
- `tests/phpunit/testdata/` Example classes or plugins that can be used in tests.
23-
- `tests/phpunit/utils/` Shared helpers that can be used across different test classes.
21+
- `tests/phpunit/tests/` All PHPUnit tests that run as part of the suite.
22+
- `tests/phpunit/testdata/` Example classes or plugins that can be used in tests.
23+
- `tests/phpunit/utils/` Shared helpers that can be used across different test classes.
2424

2525
Ensure that you create your check and unit test at same time.

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@
1616
},
1717
"scripts": {
1818
"wp-env": "wp-env",
19+
"wp-env:start:tests": "wp-env start --config=.wp-env.tests.json",
20+
"wp-env:stop:tests": "wp-env stop --config=.wp-env.tests.json",
1921
"lint-js": "wp-scripts lint-js",
2022
"format-js": "npm run lint-js -- --fix",
2123
"lint-gherkin": "gherkin-lint",
22-
"phpstan": "wp-env run tests-cli --env-cwd=wp-content/plugins/$(basename \"$(pwd)\")/ composer run-script phpstan",
23-
"lint-php": "wp-env run tests-cli --env-cwd=wp-content/plugins/$(basename \"$(pwd)\")/ composer run-script lint",
24-
"format-php": "wp-env run tests-cli --env-cwd=wp-content/plugins/$(basename \"$(pwd)\")/ composer run-script format",
25-
"test-php": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename \"$(pwd)\") vendor/bin/phpunit -c phpunit.xml.dist",
26-
"test-php-coverage": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename \"$(pwd)\") vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover build/logs/php-coverage.xml",
27-
"test-php-multisite": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename \"$(pwd)\") vendor/bin/phpunit -c tests/phpunit/multisite.xml",
28-
"test-php-multisite-coverage": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename \"$(pwd)\") vendor/bin/phpunit -c tests/phpunit/multisite.xml --coverage-clover build/logs/php-coverage-multisite.xml"
24+
"phpstan": "wp-env --config=.wp-env.tests.json run cli --env-cwd=wp-content/plugins/$(basename \"$(pwd)\")/ composer run-script phpstan",
25+
"lint-php": "wp-env --config=.wp-env.tests.json run cli --env-cwd=wp-content/plugins/$(basename \"$(pwd)\")/ composer run-script lint",
26+
"format-php": "wp-env --config=.wp-env.tests.json run cli --env-cwd=wp-content/plugins/$(basename \"$(pwd)\")/ composer run-script format",
27+
"test-php": "wp-env --config=.wp-env.tests.json run cli --env-cwd=/var/www/html/wp-content/plugins/$(basename \"$(pwd)\") vendor/bin/phpunit -c phpunit.xml.dist",
28+
"test-php-coverage": "wp-env --config=.wp-env.tests.json run cli --env-cwd=/var/www/html/wp-content/plugins/$(basename \"$(pwd)\") vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover build/logs/php-coverage.xml",
29+
"test-php-multisite": "wp-env --config=.wp-env.tests.json run cli --env-cwd=/var/www/html/wp-content/plugins/$(basename \"$(pwd)\") vendor/bin/phpunit -c tests/phpunit/multisite.xml",
30+
"test-php-multisite-coverage": "wp-env --config=.wp-env.tests.json run cli --env-cwd=/var/www/html/wp-content/plugins/$(basename \"$(pwd)\") vendor/bin/phpunit -c tests/phpunit/multisite.xml --coverage-clover build/logs/php-coverage-multisite.xml"
2931
}
3032
}

0 commit comments

Comments
 (0)