Skip to content

Add smoke tests for ten untested fixing sniffs - #73

Merged
dereuromark merged 1 commit into
masterfrom
smoke-tests-untested-sniffs
Aug 6, 2026
Merged

Add smoke tests for ten untested fixing sniffs#73
dereuromark merged 1 commit into
masterfrom
smoke-tests-untested-sniffs

Conversation

@dereuromark

Copy link
Copy Markdown
Contributor

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 - VoidCast and PipeOperatorSpacing had 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:

sniff errors fixable
TernarySpacing 7 7
Mock 6 4
DocBlockTagGrouping 6 6
ControlStructureSpacing 6 6
MethodDeclaration 5 4
DocComment 4 4
ConcatenationSpacing 4 4
ImplicitCastSpacing 4 4
DocBlockStructure 3 3
FunctionSpacing 2 2

Each 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:

  • DocBlockTagGrouping reports NoExtraNewlineBeforeTags as fixable but never applies the fix. checkBeginningOfDocBlock() has if ($fix) { return; } where every sibling in the file uses if (!$fix) { return; }, so the fixer body runs only when the fixer is disabled.
  • DocComment emits tab indentation when splitting a docblock, derived from the token column, regardless of the file's own indentation.
  • FunctionSpacing has a dedicated branch for adjacent interface methods that the fixture never reaches.
  • ImplicitCastSpacing does not flag ~ $mask, though the T_NONE registration reads as if it might.

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.
Copilot AI lite review requested due to automatic review settings August 6, 2026 11:13
@dereuromark
dereuromark merged commit 911fc61 into master Aug 6, 2026
6 checks passed
@dereuromark
dereuromark deleted the smoke-tests-untested-sniffs branch August 6, 2026 11:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.php filename.

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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants