Skip to content

Commit 1e0ff2d

Browse files
committed
Merge branch 'main' into claude/wp-cli-ai-contributor-experience-2d3ces
Brings in the README regeneration from #361, which adds the section #340 had only written into .readme-partials/USING.md. It merged cleanly with this branch's own README additions. Checked afterwards that every section the partial defines still matches its generated counterpart byte for byte, so the next regeneration stays a no-op.
2 parents a88c6b2 + f1b77ec commit 1e0ff2d

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ To make use of the WP-CLI testing framework, you need to complete the following
9191
```
9292
9393
All other [PHPCS configuration options](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-Ruleset) are, of course, available.
94+
The PHP snippets embedded in your feature files are checked along with the rest of the package. See [Checking the code style of the PHP blocks in feature files](#checking-the-code-style-of-the-php-blocks-in-feature-files) below.
95+
9496
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.
9597
9698
7. Update your composer dependencies and regenerate your autoloader and binary folders:
@@ -179,6 +181,56 @@ Two kinds of blocks are left out of the analysis, and are listed at the end of t
179181
Blocks that declare the same class or function as another block are analysed separately from each
180182
other, so that PHPStan does not resolve a name to the wrong block's declaration.
181183

184+
### Checking the code style of the PHP blocks in feature files
185+
186+
`composer phpcs` also checks the PHP snippets that feature files embed in docstrings, and
187+
`composer phpcbf` fixes them in place. No configuration is needed, and like the analysis above the
188+
blocks are padded so that findings are reported against the feature file itself:
189+
190+
```text
191+
FILE: features/command.feature
192+
----------------------------------------------------------------------
193+
FOUND 1 ERROR AFFECTING 1 LINE
194+
----------------------------------------------------------------------
195+
438 | ERROR | [x] Expected 1 space after IF keyword; 0 found
196+
----------------------------------------------------------------------
197+
```
198+
199+
Only a docstring belonging to a step that creates a `.php` file is checked:
200+
201+
```gherkin
202+
Given a wp-content/mu-plugins/test-harness.php file:
203+
"""
204+
<?php
205+
WP_CLI::add_command( 'test-harness', 'Test_Harness' );
206+
"""
207+
```
208+
209+
Unlike the analysis above, a docstring that merely opens with `<?php` does not count. Those are
210+
routinely an expectation about the contents of a file rather than a file, and reformatting one would
211+
make it stop matching what it is checked against.
212+
213+
The defaults leave out the sniffs that look at a block as if it were a file of its own, along with
214+
those that ask of a fixture what is only worth asking of production code. They live in
215+
`phpcs/feature-files.sh` and are shared by the check and the fixer, so that the two cannot disagree
216+
over which sniff applies. A package replaces them wholesale by adding a `phpcs-feature-files.xml`
217+
(or `phpcs-feature-files.xml.dist`) ruleset to its root:
218+
219+
```xml
220+
<?xml version="1.0"?>
221+
<ruleset name="WP-CLI-PROJECT-NAME-feature-files">
222+
<arg name="warning-severity" value="0"/>
223+
224+
<rule ref="WP_CLI_CS">
225+
<exclude name="Generic.Files.InlineHTML"/>
226+
<exclude name="Squiz.Commenting.FileComment"/>
227+
</rule>
228+
</ruleset>
229+
```
230+
231+
The blocks are left alone when a run is narrowed down to a path, as in `composer phpcs -- src/`,
232+
since such an argument is about the files of the package itself.
233+
182234
### Controlling what to test
183235

184236
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

Comments
 (0)