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 d8c33f5
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: .readme-partials/USING.md
+71-1Lines changed: 71 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:
Copy file name to clipboardExpand all lines: README.md
+71-1Lines changed: 71 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,11 +24,13 @@ To make use of the WP-CLI testing framework, you need to complete the following
24
24
"lint": "run-linter-tests",
25
25
"phpcs": "run-phpcs-tests",
26
26
"phpcbf": "run-phpcbf-cleanup",
27
+
"phpstan": "run-phpstan-tests",
27
28
"phpunit": "run-php-unit-tests",
28
29
"prepare-tests": "install-package-tests",
29
30
"test": [
30
31
"@lint",
31
32
"@phpcs",
33
+
"@phpstan",
32
34
"@phpunit",
33
35
"@behat"
34
36
]
@@ -87,7 +89,9 @@ To make use of the WP-CLI testing framework, you need to complete the following
87
89
```
88
90
89
91
All other [PHPCS configuration options](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-Ruleset) are, of course, available.
90
-
6. Update your composer dependencies and regenerate your autoloader and binary folders:
92
+
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.
93
+
94
+
7. Update your composer dependencies and regenerate your autoloader and binary folders:
91
95
```bash
92
96
composer update
93
97
```
@@ -103,9 +107,75 @@ You can use the following commands to control the tests:
103
107
* `composer lint` - Run only the linting test suite.
104
108
* `composer phpcs` - Run only the code sniffer test suite.
105
109
* `composer phpcbf` - Run only the code sniffer cleanup.
110
+
* `composer phpstan` - Run only the static analysis.
106
111
* `composer phpunit` - Run only the unit test suite.
107
112
* `composer behat` - Run only the functional test suite.
108
113
114
+
### Analysing the PHP blocks in feature files
115
+
116
+
Feature files embed PHP snippets in docstrings, which none of the static analysis tools normally
117
+
look at:
118
+
119
+
```gherkin
120
+
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
139
+
it wants to change. An empty file is enough to run with the defaults, and a level of its own looks
140
+
like this:
141
+
142
+
```neon
143
+
parameters:
144
+
level: 4
145
+
```
146
+
147
+
Do note that snippets in feature files are fixtures, not production code, and that they run inside a
148
+
WordPress installation the analysis knows nothing about. Expect to have to ignore errors that are
149
+
not actually wrong, such as functions a scenario deliberately leaves undefined.
150
+
151
+
An ignore matches against the extracted file rather than the feature file it came from. Those files
152
+
are named `<feature file>_L<first line>_E<last line>.php`, with the feature file relative to the
153
+
`features` directory, so ignoring an error for a whole feature file takes a pattern:
154
+
155
+
```neon
156
+
parameters:
157
+
ignoreErrors:
158
+
-
159
+
identifier: function.notFound
160
+
path: */shutdown-handler.feature_L*.php
161
+
```
162
+
163
+
Since the blocks are analysed in more than one run (see below), an ignore that no run matches is not
164
+
reported. A pattern that matches nothing at all therefore goes unnoticed, so it is worth checking
165
+
that the error it targets is really gone.
166
+
167
+
Two kinds of blocks are left out of the analysis, and are listed at the end of the run:
168
+
169
+
* Blocks that are not standalone PHP, such as snippets holding a placeholder that Behat substitutes
170
+
(`get_the_title( {POST_ID} )`) or code that is deliberately broken to test error handling. PHPStan
171
+
stops analysing altogether when a single file fails to parse, so these have to be skipped.
172
+
* Docstrings that neither belong to a step creating a `.php` file nor open with `<?php`, since those
173
+
are not necessarily PHP at all. The second rule covers PHP files that are not named `*.php`, such
174
+
as the `.maintenance` file of a WordPress installation.
175
+
176
+
Blocks that declare the same class or function as another block are analysed separately from each
177
+
other, so that PHPStan does not resolve a name to the wrong block's declaration.
178
+
109
179
### Controlling what to test
110
180
111
181
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:
0 commit comments