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
Tests: set up mechanism to allow for testing CBF specific code
See the description of how this works in the `CONTRIBUTING` file for more information.
Includes adjustments to the GH Actions workflows to ensure the CBF specific tests are:
* Always run for the `quicktest` and "normal" test runs.
* Run for code coverage and that the code coverage reports are send in a way that they can be merged correctly.
Includes adding a "requires CS mode" condition to a few tests which would otherwise fail in CBF mode.
Copy file name to clipboardExpand all lines: .github/CONTRIBUTING.md
+30
Original file line number
Diff line number
Diff line change
@@ -346,6 +346,36 @@ However, there are a few places which include OS-specific conditions, most notab
346
346
347
347
Tests which cover code which have Windows specific conditions should be marked with a `@group Windows` annotation to allow for running those tests separately/selectively in CI.
348
348
349
+
#### Tests covering code which has CS/CBF specific behaviour
350
+
351
+
There are a few places in PHPCS where code uses a global `PHP_CODESNIFFER_CBF` constant to determine what to do.
352
+
This makes testing this code more complicated.
353
+
354
+
Tests which will only work correctly when `PHP_CODESNIFFER_CBF === false` should get the following test skip condition at the top of the test method:
355
+
```php
356
+
if (PHP_CODESNIFFER_CBF === true) {
357
+
$this->markTestSkipped('This test needs CS mode to run');
358
+
}
359
+
```
360
+
361
+
Tests which are specifically intended to cover code run when `PHP_CODESNIFFER_CBF === true` should:
362
+
1. Be annotated with `@group CBF`.
363
+
2. Have a test skip condition at the top of the test method like so:
364
+
```php
365
+
if (PHP_CODESNIFFER_CBF === false) {
366
+
$this->markTestSkipped('This test needs CBF mode to run');
367
+
}
368
+
```
369
+
370
+
By default, the tests are run with the `PHP_CODESNIFFER_CBF` constant set to `false` and tests in the `@group CBF` will not be run.
371
+
372
+
To run the tests specific to the use of `PHP_CODESNIFFER_CBF === true`:
373
+
1. Set `<php><envname="PHP_CODESNIFFER_CBF"value="1"/></php>` in a `phpunit.xml` file or set the ENV variable on an OS-level.
0 commit comments