Skip to content

Commit f1b77ec

Browse files
Regenerate README file (#361)
1 parent 913cd94 commit f1b77ec

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
@@ -89,6 +89,8 @@ To make use of the WP-CLI testing framework, you need to complete the following
8989
```
9090
9191
All other [PHPCS configuration options](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-Ruleset) are, of course, available.
92+
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.
93+
9294
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.
9395
9496
7. Update your composer dependencies and regenerate your autoloader and binary folders:
@@ -176,6 +178,56 @@ Two kinds of blocks are left out of the analysis, and are listed at the end of t
176178
Blocks that declare the same class or function as another block are analysed separately from each
177179
other, so that PHPStan does not resolve a name to the wrong block's declaration.
178180

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

181233
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)