Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ stubs/ # PHPUnit stub files for type definitions
## Configuration Files

- **`extension.neon`** — Main extension configuration registered via phpstan/extension-installer. Defines parameters, services (type extensions, helpers), and stub files.
- **`rules.neon`** — Strict PHPUnit-specific rules. Loaded separately; users opt in by including this file.
- **`rules.neon`** — Strict PHPUnit-specific rules. Loaded separately; users opt in by including this file. Every rule is registered as a service and tagged through `conditionalTags` with its own `phpunit.<ruleName>` parameter (defined in `extension.neon`, defaulting to `%phpunit.allRules%`). A new rule needs a service, a conditional tag, a parameter, a schema entry and a README table row; `RuleTogglesTest` fails if the toggle is missing.
- **`phpstan.neon`** — Self-analysis configuration (level 8, with strict rules and deprecation rules).
- **`phpstan-baseline.neon`** — Baseline for known PHPStan errors in the project itself.
- **`phpunit.xml`** — PHPUnit configuration for running the test suite.
Expand Down
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,45 @@ To perform framework-specific checks, include also this file:
```

</details>

## Enabling rules one-by-one

All rules from `rules.neon` are enabled by default. Each of them can be disabled individually:

```neon
parameters:
phpunit:
assertSameWithCount: false
```

To enable only the rules you want, disable all of them and then turn the ones you want back on:

```neon
parameters:
phpunit:
allRules: false
classCoversExists: true
```

Rules added in future releases are covered by `allRules` as well, so with `allRules: false` no new rule is enabled until you opt in.

| Parameter | Rule | Enabled by default |
|---|---|---|
| `assertSameBooleanExpected` | `AssertSameBooleanExpectedRule` | yes |
| `assertSameNullExpected` | `AssertSameNullExpectedRule` | yes |
| `assertSameWithCount` | `AssertSameWithCountRule` | yes |
| `classCoversExists` | `ClassCoversExistsRule` | yes |
| `classMethodCoversExists` | `ClassMethodCoversExistsRule` | yes |
| `mockMethodCall` | `MockMethodCallRule` | yes |
| `noMissingSpaceInClassAnnotation` | `NoMissingSpaceInClassAnnotationRule` | yes |
| `noMissingSpaceInMethodAnnotation` | `NoMissingSpaceInMethodAnnotationRule` | yes |
| `shouldCallParentMethods` | `ShouldCallParentMethodsRule` | yes |
| `dataProviderDeclaration` | `DataProviderDeclarationRule` | yes |
| `attributeRequiresPhpVersion` | `AttributeRequiresPhpVersionRule` | yes |
| `dataProviderData` | `DataProviderDataRule` | with [Bleeding Edge](https://phpstan.org/blog/what-is-bleeding-edge) |
| `classAttributeRequiresPhpVersion` | `ClassAttributeRequiresPhpVersionRule` | with Bleeding Edge |
| `emptyDataProvider` | `EmptyDataProviderRule` | with Bleeding Edge |
| `assertEqualsIsDiscouraged` | `AssertEqualsIsDiscouragedRule` | with Bleeding Edge and [phpstan-strict-rules](https://github.com/phpstan/phpstan-strict-rules) |
| `assertEmptyIsDiscouraged` | `AssertEmptyIsDiscouragedRule` | with Bleeding Edge and phpstan-strict-rules |

Setting a parameter to `true` enables the rule regardless of Bleeding Edge and phpstan-strict-rules.
34 changes: 34 additions & 0 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@ parameters:
phpunit:
convertUnionToIntersectionType: true
reportMissingDataProviderReturnType: false
allRules: true
assertSameBooleanExpected: %phpunit.allRules%
assertSameNullExpected: %phpunit.allRules%
assertSameWithCount: %phpunit.allRules%
classCoversExists: %phpunit.allRules%
classMethodCoversExists: %phpunit.allRules%
mockMethodCall: %phpunit.allRules%
noMissingSpaceInClassAnnotation: %phpunit.allRules%
noMissingSpaceInMethodAnnotation: %phpunit.allRules%
shouldCallParentMethods: %phpunit.allRules%
dataProviderDeclaration: %phpunit.allRules%
attributeRequiresPhpVersion: %phpunit.allRules%
assertEqualsIsDiscouraged: [%phpunit.allRules%, %strictRulesInstalled%, %featureToggles.bleedingEdge%]
assertEmptyIsDiscouraged: [%phpunit.allRules%, %strictRulesInstalled%, %featureToggles.bleedingEdge%]
dataProviderData: [%phpunit.allRules%, %featureToggles.bleedingEdge%]
classAttributeRequiresPhpVersion: [%phpunit.allRules%, %featureToggles.bleedingEdge%]
emptyDataProvider: [%phpunit.allRules%, %featureToggles.bleedingEdge%]
additionalConstructors:
- PHPUnit\Framework\TestCase::setUp
earlyTerminatingMethodCalls:
Expand All @@ -26,6 +43,23 @@ parametersSchema:
phpunit: structure([
convertUnionToIntersectionType: bool(),
reportMissingDataProviderReturnType: bool(),
allRules: bool(),
assertSameBooleanExpected: anyOf(bool(), arrayOf(bool())),
assertSameNullExpected: anyOf(bool(), arrayOf(bool())),
assertSameWithCount: anyOf(bool(), arrayOf(bool())),
classCoversExists: anyOf(bool(), arrayOf(bool())),
classMethodCoversExists: anyOf(bool(), arrayOf(bool())),
mockMethodCall: anyOf(bool(), arrayOf(bool())),
noMissingSpaceInClassAnnotation: anyOf(bool(), arrayOf(bool())),
noMissingSpaceInMethodAnnotation: anyOf(bool(), arrayOf(bool())),
shouldCallParentMethods: anyOf(bool(), arrayOf(bool())),
dataProviderDeclaration: anyOf(bool(), arrayOf(bool())),
attributeRequiresPhpVersion: anyOf(bool(), arrayOf(bool())),
assertEqualsIsDiscouraged: anyOf(bool(), arrayOf(bool())),
assertEmptyIsDiscouraged: anyOf(bool(), arrayOf(bool())),
dataProviderData: anyOf(bool(), arrayOf(bool())),
classAttributeRequiresPhpVersion: anyOf(bool(), arrayOf(bool())),
emptyDataProvider: anyOf(bool(), arrayOf(bool())),
])

services:
Expand Down
83 changes: 57 additions & 26 deletions rules.neon
Original file line number Diff line number Diff line change
@@ -1,45 +1,73 @@
rules:
- PHPStan\Rules\PHPUnit\AssertSameBooleanExpectedRule
- PHPStan\Rules\PHPUnit\AssertSameNullExpectedRule
- PHPStan\Rules\PHPUnit\AssertSameWithCountRule
- PHPStan\Rules\PHPUnit\ClassCoversExistsRule
- PHPStan\Rules\PHPUnit\ClassMethodCoversExistsRule
- PHPStan\Rules\PHPUnit\MockMethodCallRule
- PHPStan\Rules\PHPUnit\NoMissingSpaceInClassAnnotationRule
- PHPStan\Rules\PHPUnit\NoMissingSpaceInMethodAnnotationRule
- PHPStan\Rules\PHPUnit\ShouldCallParentMethodsRule

conditionalTags:
PHPStan\Rules\PHPUnit\AssertSameBooleanExpectedRule:
phpstan.rules.rule: %phpunit.assertSameBooleanExpected%
PHPStan\Rules\PHPUnit\AssertSameNullExpectedRule:
phpstan.rules.rule: %phpunit.assertSameNullExpected%
PHPStan\Rules\PHPUnit\AssertSameWithCountRule:
phpstan.rules.rule: %phpunit.assertSameWithCount%
PHPStan\Rules\PHPUnit\ClassCoversExistsRule:
phpstan.rules.rule: %phpunit.classCoversExists%
PHPStan\Rules\PHPUnit\ClassMethodCoversExistsRule:
phpstan.rules.rule: %phpunit.classMethodCoversExists%
PHPStan\Rules\PHPUnit\MockMethodCallRule:
phpstan.rules.rule: %phpunit.mockMethodCall%
PHPStan\Rules\PHPUnit\NoMissingSpaceInClassAnnotationRule:
phpstan.rules.rule: %phpunit.noMissingSpaceInClassAnnotation%
PHPStan\Rules\PHPUnit\NoMissingSpaceInMethodAnnotationRule:
phpstan.rules.rule: %phpunit.noMissingSpaceInMethodAnnotation%
PHPStan\Rules\PHPUnit\ShouldCallParentMethodsRule:
phpstan.rules.rule: %phpunit.shouldCallParentMethods%
PHPStan\Rules\PHPUnit\DataProviderDeclarationRule:
phpstan.rules.rule: %phpunit.dataProviderDeclaration%
PHPStan\Rules\PHPUnit\AttributeRequiresPhpVersionRule:
phpstan.rules.rule: %phpunit.attributeRequiresPhpVersion%
PHPStan\Rules\PHPUnit\AssertEqualsIsDiscouragedRule:
phpstan.rules.rule: [%strictRulesInstalled%, %featureToggles.bleedingEdge%]
phpstan.rules.rule: %phpunit.assertEqualsIsDiscouraged%
PHPStan\Rules\PHPUnit\AssertEmptyIsDiscouragedRule:
phpstan.rules.rule: [%strictRulesInstalled%, %featureToggles.bleedingEdge%]

phpstan.rules.rule: %phpunit.assertEmptyIsDiscouraged%
PHPStan\Rules\PHPUnit\DataProviderDataRule:
phpstan.rules.rule: %featureToggles.bleedingEdge%

phpstan.rules.rule: %phpunit.dataProviderData%
PHPStan\Rules\PHPUnit\ClassAttributeRequiresPhpVersionRule:
phpstan.rules.rule: %featureToggles.bleedingEdge%

phpstan.rules.rule: %phpunit.classAttributeRequiresPhpVersion%
PHPStan\Rules\PHPUnit\EmptyDataProviderRule:
phpstan.rules.rule: %featureToggles.bleedingEdge%
phpstan.rules.rule: %phpunit.emptyDataProvider%

services:
-
class: PHPStan\Rules\PHPUnit\AssertSameBooleanExpectedRule

-
class: PHPStan\Rules\PHPUnit\AssertSameNullExpectedRule

-
class: PHPStan\Rules\PHPUnit\AssertSameWithCountRule

-
class: PHPStan\Rules\PHPUnit\ClassCoversExistsRule

-
class: PHPStan\Rules\PHPUnit\ClassMethodCoversExistsRule

-
class: PHPStan\Rules\PHPUnit\MockMethodCallRule

-
class: PHPStan\Rules\PHPUnit\NoMissingSpaceInClassAnnotationRule

-
class: PHPStan\Rules\PHPUnit\NoMissingSpaceInMethodAnnotationRule

-
class: PHPStan\Rules\PHPUnit\ShouldCallParentMethodsRule

-
class: PHPStan\Rules\PHPUnit\DataProviderDeclarationRule
arguments:
checkFunctionNameCase: %checkFunctionNameCase%
deprecationRulesInstalled: %deprecationRulesInstalled%
tags:
- phpstan.rules.rule

-
class: PHPStan\Rules\PHPUnit\AttributeRequiresPhpVersionRule
tags:
- phpstan.rules.rule

-
class: PHPStan\Rules\PHPUnit\ClassAttributeRequiresPhpVersionRule

-
class: PHPStan\Rules\PHPUnit\AssertEqualsIsDiscouragedRule
Expand All @@ -50,5 +78,8 @@ services:
-
class: PHPStan\Rules\PHPUnit\DataProviderDataRule

-
class: PHPStan\Rules\PHPUnit\ClassAttributeRequiresPhpVersionRule

-
class: PHPStan\Rules\PHPUnit\EmptyDataProviderRule
Loading