Skip to content

Commit

Permalink
Test-suite - Show warning when ".fixed" file not found (PHPCSStandard…
Browse files Browse the repository at this point in the history
…s#336)

This commit updates the `AbstractSniffUnitTest` class used for the sniff tests to show a non-build-failing warning when a test case file would lead to fixable errors/warnings, but there is no `.fixed` version available for the test case file to verify the fixes being made.

This is a preliminary step towards making missing `.fixed` files a test failing error in PHPCS 4.0.

Note: the warning will only show when tests are being run on PHPUnit 7.3.0 or higher.
  • Loading branch information
fredden authored and DannyvdSluijs committed Apr 29, 2024
1 parent d816d7d commit 1a722e6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tests/Standards/AbstractSniffUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,17 @@ final public function testSniff()

// Check for a .fixed file to check for accuracy of fixes.
$fixedFile = $testFile.'.fixed';
$filename = basename($testFile);
if (file_exists($fixedFile) === true) {
$diff = $phpcsFile->fixer->generateDiff($fixedFile);
if (trim($diff) !== '') {
$filename = basename($testFile);
$fixedFilename = basename($fixedFile);
$failureMessages[] = "Fixed version of $filename does not match expected version in $fixedFilename; the diff is\n$diff";
}
} else if (is_callable([$this, 'addWarning']) === true) {
$this->addWarning("Missing fixed version of $filename to verify the accuracy of fixes, while the sniff is making fixes against the test case file");
}
}
}//end if

// Restore the config.
$config->setSettings($oldConfig);
Expand Down

0 comments on commit 1a722e6

Please sign in to comment.