Add smoke tests for ten untested fixing sniffs - #73
Merged
Conversation
The standard ships 86 sniffs against 38 test classes, and the gap is worst where it hurts most: sniffs that rewrite source. A fixer nobody exercises can break without anything noticing, which is exactly how VoidCast and PipeOperatorSpacing came to match nothing at all on PHP 8.5 from the day they were written. Covers the ten heaviest rewriters by fixable-error count: TernarySpacing, DocBlockTagGrouping, DocComment, ControlStructureSpacing, ConcatenationSpacing, Mock, MethodDeclaration, ImplicitCastSpacing, FunctionSpacing and DocBlockStructure. Each fixture triggers the distinct error codes its sniff can emit and also carries constructs the sniff has to leave alone, so an over-eager matcher fails the test rather than passing it quietly. No sniff behavior changes here. Where a fixture documents something that looks wrong, it asserts what the sniff does today rather than what it arguably should; those are followed up separately. 128 tests, up from 108.
There was a problem hiding this comment.
Pull request overview
Adds new smoke-test coverage for ten previously untested “fixing” sniffs in the PhpCollective standard, with before/after fixtures to exercise each sniff’s fixable error codes and ensure fixers don’t regress silently.
Changes:
- Add 10 new PHPUnit test classes to assert both “finds fixable errors” and “can fix errors” behavior for the targeted sniffs.
- Add before/after fixtures under
tests/_data/for each sniff to validate fixer output and preserve “must leave alone” constructs. - Add a MockSniff-specific test override to run the fixture under a
*Test.phpfilename.
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/PhpCollective/Sniffs/WhiteSpace/TernarySpacingSniffTest.php | New smoke test for TernarySpacing sniff detection + fixer. |
| tests/PhpCollective/Sniffs/WhiteSpace/ImplicitCastSpacingSniffTest.php | New smoke test for ImplicitCastSpacing sniff detection + fixer. |
| tests/PhpCollective/Sniffs/WhiteSpace/FunctionSpacingSniffTest.php | New smoke test for FunctionSpacing sniff detection + fixer. |
| tests/PhpCollective/Sniffs/WhiteSpace/ConcatenationSpacingSniffTest.php | New smoke test for ConcatenationSpacing sniff detection + fixer. |
| tests/PhpCollective/Sniffs/Testing/MockSniffTest.php | New smoke test for Mock sniff, including custom fixture path handling. |
| tests/PhpCollective/Sniffs/ControlStructures/ControlStructureSpacingSniffTest.php | New smoke test for ControlStructureSpacing sniff detection + fixer. |
| tests/PhpCollective/Sniffs/Commenting/DocCommentSniffTest.php | New smoke test for DocComment sniff detection + fixer. |
| tests/PhpCollective/Sniffs/Commenting/DocBlockTagGroupingSniffTest.php | New smoke test for DocBlockTagGrouping sniff detection + fixer. |
| tests/PhpCollective/Sniffs/Commenting/DocBlockStructureSniffTest.php | New smoke test for DocBlockStructure sniff detection + fixer. |
| tests/PhpCollective/Sniffs/Classes/MethodDeclarationSniffTest.php | New smoke test for MethodDeclaration sniff detection + fixer. |
| tests/_data/TernarySpacing/before.php | Fixture inputs that should produce 7 fixable errors for TernarySpacing. |
| tests/_data/TernarySpacing/after.php | Expected fixed output for TernarySpacing fixture. |
| tests/_data/Mock/before.php | Fixture inputs that should produce 6 errors (4 fixable) for Mock sniff. |
| tests/_data/Mock/after.php | Expected fixed output for Mock fixture. |
| tests/_data/MethodDeclaration/before.php | Fixture inputs that should produce 5 errors (4 fixable) for MethodDeclaration. |
| tests/_data/MethodDeclaration/after.php | Expected fixed output for MethodDeclaration fixture. |
| tests/_data/ImplicitCastSpacing/before.php | Fixture inputs that should produce 4 fixable errors for ImplicitCastSpacing. |
| tests/_data/ImplicitCastSpacing/after.php | Expected fixed output for ImplicitCastSpacing fixture. |
| tests/_data/FunctionSpacing/before.php | Fixture inputs that should produce 2 fixable errors for FunctionSpacing. |
| tests/_data/FunctionSpacing/after.php | Expected fixed output for FunctionSpacing fixture. |
| tests/_data/DocComment/before.php | Fixture inputs that should produce 4 fixable errors for DocComment. |
| tests/_data/DocComment/after.php | Expected fixed output for DocComment fixture. |
| tests/_data/DocBlockTagGrouping/before.php | Fixture inputs that should produce 6 fixable errors for DocBlockTagGrouping. |
| tests/_data/DocBlockTagGrouping/after.php | Expected fixed output for DocBlockTagGrouping fixture. |
| tests/_data/DocBlockStructure/before.php | Fixture inputs that should produce 3 fixable errors for DocBlockStructure. |
| tests/_data/DocBlockStructure/after.php | Expected fixed output for DocBlockStructure fixture. |
| tests/_data/ControlStructureSpacing/before.php | Fixture inputs that should produce 6 fixable errors for ControlStructureSpacing. |
| tests/_data/ControlStructureSpacing/after.php | Expected fixed output for ControlStructureSpacing fixture. |
| tests/_data/ConcatenationSpacing/before.php | Fixture inputs that should produce 4 fixable errors for ConcatenationSpacing. |
| tests/_data/ConcatenationSpacing/after.php | Expected fixed output for ConcatenationSpacing fixture. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+42
to
+44
| if (!is_dir(TMP)) { | ||
| mkdir(TMP, 0770, true); | ||
| } |
This was referenced Aug 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
86 sniffs, 38 test classes. The gap matters most for the sniffs that rewrite source: a fixer nobody exercises can break silently. That is not hypothetical -
VoidCastandPipeOperatorSpacinghad matched nothing at all on PHP 8.5 since the day they were written, and only #71 caught it.This covers the ten heaviest rewriters, ranked by how many fixable errors they can emit:
TernarySpacingMockDocBlockTagGroupingControlStructureSpacingMethodDeclarationDocCommentConcatenationSpacingImplicitCastSpacingDocBlockStructureFunctionSpacingEach fixture triggers the distinct error codes its sniff emits, and each also carries constructs the sniff must leave alone - a valid ternary, a correctly grouped docblock, a non-mock return type - so an over-eager matcher fails rather than passing quietly.
128 tests, up from 108.
No behavior changes
Where a fixture documents something that looks wrong, it asserts what the sniff does today, not what it arguably should. Writing these turned up four such observations; the first is a real defect and gets its own PR:
DocBlockTagGroupingreportsNoExtraNewlineBeforeTagsas fixable but never applies the fix.checkBeginningOfDocBlock()hasif ($fix) { return; }where every sibling in the file usesif (!$fix) { return; }, so the fixer body runs only when the fixer is disabled.DocCommentemits tab indentation when splitting a docblock, derived from the token column, regardless of the file's own indentation.FunctionSpacinghas a dedicated branch for adjacent interface methods that the fixture never reaches.ImplicitCastSpacingdoes not flag~ $mask, though theT_NONEregistration reads as if it might.