Skip to content

Commit 328c528

Browse files
authored
Test-suite - Show warning when ".fixed" file not found (#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.
1 parent 385270b commit 328c528

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tests/Standards/AbstractSniffUnitTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,17 @@ final public function testSniff()
190190

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

203205
// Restore the config.
204206
$config->setSettings($oldConfig);

0 commit comments

Comments
 (0)