Skip to content

Commit 53f374c

Browse files
authored
Merge pull request #351 from PHPCSStandards/feature/tests-improve-performance-fixer-diff-check
Tests: improve performance of the sniff tests
2 parents 3b2ab17 + f3eac53 commit 53f374c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tests/Standards/AbstractSniffUnitTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,13 @@ final public function testSniff()
193193
$fixedFile = $testFile.'.fixed';
194194
$filename = basename($testFile);
195195
if (file_exists($fixedFile) === true) {
196-
$diff = $phpcsFile->fixer->generateDiff($fixedFile);
197-
if (trim($diff) !== '') {
198-
$fixedFilename = basename($fixedFile);
199-
$failureMessages[] = "Fixed version of $filename does not match expected version in $fixedFilename; the diff is\n$diff";
196+
if ($phpcsFile->fixer->getContents() !== file_get_contents($fixedFile)) {
197+
// Only generate the (expensive) diff if a difference is expected.
198+
$diff = $phpcsFile->fixer->generateDiff($fixedFile);
199+
if (trim($diff) !== '') {
200+
$fixedFilename = basename($fixedFile);
201+
$failureMessages[] = "Fixed version of $filename does not match expected version in $fixedFilename; the diff is\n$diff";
202+
}
200203
}
201204
} else if (is_callable([$this, 'addWarning']) === true) {
202205
$this->addWarning("Missing fixed version of $filename to verify the accuracy of fixes, while the sniff is making fixes against the test case file");

0 commit comments

Comments
 (0)