You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 0328764
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: .readme-partials/USING.md
+114-1Lines changed: 114 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,11 +13,13 @@ To make use of the WP-CLI testing framework, you need to complete the following
13
13
"lint": "run-linter-tests",
14
14
"phpcs": "run-phpcs-tests",
15
15
"phpcbf": "run-phpcbf-cleanup",
16
+
"phpstan": "run-phpstan-tests",
16
17
"phpunit": "run-php-unit-tests",
17
18
"prepare-tests": "install-package-tests",
18
19
"test": [
19
20
"@lint",
20
21
"@phpcs",
22
+
"@phpstan",
21
23
"@phpunit",
22
24
"@behat"
23
25
]
@@ -76,7 +78,9 @@ To make use of the WP-CLI testing framework, you need to complete the following
76
78
```
77
79
78
80
All other [PHPCS configuration options](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-Ruleset) are, of course, available.
79
-
6. Update your composer dependencies and regenerate your autoloader and binary folders:
81
+
6. Optionally add a `phpstan-feature-files.neon.dist` file to the package root to also run PHPStan over the PHP snippets embedded in your feature files. See [Analysing the PHP blocks in feature files](#analysing-the-php-blocks-in-feature-files) below.
82
+
83
+
7. Update your composer dependencies and regenerate your autoloader and binary folders:
80
84
```bash
81
85
composer update
82
86
```
@@ -92,9 +96,75 @@ You can use the following commands to control the tests:
92
96
* `composer lint` - Run only the linting test suite.
93
97
* `composer phpcs` - Run only the code sniffer test suite.
94
98
* `composer phpcbf` - Run only the code sniffer cleanup.
99
+
* `composer phpstan` - Run only the static analysis.
95
100
* `composer phpunit` - Run only the unit test suite.
96
101
* `composer behat` - Run only the functional test suite.
97
102
103
+
### Analysing the PHP blocks in feature files
104
+
105
+
Feature files embed PHP snippets in docstrings, which none of the static analysis tools normally
106
+
look at:
107
+
108
+
```gherkin
109
+
Given a wp-content/mu-plugins/test-harness.php file:
The defaults in `phpstan/feature-files.neon` are applied first, so the file only needs to hold what
128
+
it wants to change. An empty file is enough to run with the defaults, and a level of its own looks
129
+
like this:
130
+
131
+
```neon
132
+
parameters:
133
+
level: 4
134
+
```
135
+
136
+
Do note that snippets in feature files are fixtures, not production code, and that they run inside a
137
+
WordPress installation the analysis knows nothing about. Expect to have to ignore errors that are
138
+
not actually wrong, such as functions a scenario deliberately leaves undefined.
139
+
140
+
An ignore matches against the extracted file rather than the feature file it came from. Those files
141
+
are named `<feature file>_L<first line>_E<last line>.php`, with the feature file relative to the
142
+
`features` directory, so ignoring an error for a whole feature file takes a pattern:
143
+
144
+
```neon
145
+
parameters:
146
+
ignoreErrors:
147
+
-
148
+
identifier: function.notFound
149
+
path: */shutdown-handler.feature_L*.php
150
+
```
151
+
152
+
Since the blocks are analysed in more than one run (see below), an ignore that no run matches is not
153
+
reported. A pattern that matches nothing at all therefore goes unnoticed, so it is worth checking
154
+
that the error it targets is really gone.
155
+
156
+
Two kinds of blocks are left out of the analysis, and are listed at the end of the run:
157
+
158
+
* Blocks that are not standalone PHP, such as snippets holding a placeholder that Behat substitutes
159
+
(`get_the_title( {POST_ID} )`) or code that is deliberately broken to test error handling. PHPStan
160
+
stops analysing altogether when a single file fails to parse, so these have to be skipped.
161
+
* Docstrings that neither belong to a step creating a `.php` file nor open with `<?php`, since those
162
+
are not necessarily PHP at all. The second rule covers PHP files that are not named `*.php`, such
163
+
as the `.maintenance` file of a WordPress installation.
164
+
165
+
Blocks that declare the same class or function as another block are analysed separately from each
166
+
other, so that PHPStan does not resolve a name to the wrong block's declaration.
167
+
98
168
### Controlling what to test
99
169
100
170
To send one or more arguments to one of the test tools, prepend the argument(s) with a double dash. As an example, here's how to run the functional tests for a specific feature file only:
@@ -119,6 +189,49 @@ Here's how to run your tests against the latest trunk version of WordPress:
119
189
WP_VERSION=trunk composer behat
120
190
```
121
191
192
+
#### WordPress Archive
193
+
194
+
Instead of downloading WordPress from WordPress.org, you can run the tests against an arbitrary
195
+
WordPress ZIP archive by setting the `WP_CLI_TEST_CORE_ZIP` environment variable. It accepts either
196
+
a path to a local archive or an HTTP(S) URL.
197
+
198
+
This is useful to test against a WordPress build that has not been released, such as the ZIP file
Copy file name to clipboardExpand all lines: AGENTS.md
+21-2Lines changed: 21 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,9 +13,27 @@ When contributing to this package, please adhere to the following guidelines:
13
13
14
14
### Building and running
15
15
16
-
Before submitting any changes, it is crucial to validate them by running the full suite of static code analysis and tests. To run the full suite of checks, execute the following command: `composer test`.
16
+
Run the narrowest check that covers your change:
17
17
18
-
This single command ensures that your changes meet all the quality gates of the project. While you can run the individual steps separately, it is highly recommended to use this single command to ensure a comprehensive validation.
18
+
| You changed | Run |
19
+
| --- | --- |
20
+
| Any PHP file |`composer phpcs -- <file>` and `composer phpstan`|
21
+
| Logic with unit test coverage |`composer phpunit -- --filter <TestName>`|
22
+
| One feature file |`composer behat -- features/<name>.feature`|
23
+
| One scenario |`composer behat -- features/<name>.feature:<line>`|
24
+
25
+
After a failure, `composer behat-rerun` re-runs only the scenarios that failed, and `composer behat -- --stop-on-failure` bails out at the first one instead of working through the rest.
26
+
27
+
`composer test` runs every suite, the whole Behat suite included. In most packages that means installing WordPress from scratch once per scenario, which takes tens of minutes and needs `jq`, a MySQL or MariaDB client with a prepared test database, and network access to WordPress.org. Run it before opening a pull request when you have touched something cross-cutting. Do not run it to check a two-line change.
28
+
29
+
Set these first, so the tools report problems compactly instead of drawing progress bars and ANSI color into output you are going to read back:
30
+
31
+
```bash
32
+
export NO_COLOR=1
33
+
export WP_CLI_TEST_QUIET=1
34
+
```
35
+
36
+
Note that a green `composer test` is not the same as a green CI. `actionlint` and `typos` also run on every pull request and are not part of it.
19
37
20
38
### Useful Composer Commands
21
39
@@ -24,6 +42,7 @@ The project uses Composer to manage dependencies and run scripts. The following
24
42
*`composer install`: Install dependencies.
25
43
*`composer test`: Run the full test suite, including linting, code style checks, static analysis, and unit/behavior tests.
26
44
*`composer lint`: Check for syntax errors.
45
+
*`composer lint-gherkin`: Check the Behat feature files for style violations.
27
46
*`composer phpcs`: Check for code style violations.
0 commit comments