Skip to content

CONTRIBUTING: add some more info about writing tests #958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,14 @@ To run the tests specific to the use of `PHP_CODESNIFFER_CBF === true`:
vendor/bin/phpunit --group CBF --exclude-group nothing
```

#### Other notes about writing tests

* The `Config` class uses a number of static properties and can have a performance impact on the tests too.
To get round both these issues, use the `ConfigDouble` class instead.
Generally speaking, only tests which test the behaviour of the `Config` class itself where it relates to the static properties, should use the real `Config` class for testing.
In such cases, the `PHP_CodeSniffer\Tests\Core\Config\AbstractRealConfigTestCase` should be used as the base test class.
* Tests for the `Runner` class often can't create their own `Config` object in the tests, so run into the same issue.
Those tests should use the `PHP_CodeSniffer\Tests\Core\Runner\AbstractRunnerTestCase` base class, which will ensure the Config is clean.

### Submitting Your Pull Request

Expand Down