From c320cdbc75ad311836c128f8b42a930bbaebe0dd Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Thu, 8 Feb 2024 13:42:05 +0000 Subject: [PATCH 1/3] Add warning when ".fixed" file not found --- tests/Standards/AbstractSniffUnitTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Standards/AbstractSniffUnitTest.php b/tests/Standards/AbstractSniffUnitTest.php index b57c2ac659..2af5e41eff 100644 --- a/tests/Standards/AbstractSniffUnitTest.php +++ b/tests/Standards/AbstractSniffUnitTest.php @@ -197,8 +197,10 @@ final public function testSniff() $fixedFilename = basename($fixedFile); $failureMessages[] = "Fixed version of $filename does not match expected version in $fixedFilename; the diff is\n$diff"; } + } else { + $this->addWarning("Unable to verify auto-fixer results. File not found: $fixedFile"); } - } + }//end if // Restore the config. $config->setSettings($oldConfig); From 4e9ba9077251ee01e9f37883655787fc6047138e Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Thu, 8 Feb 2024 19:09:47 +0000 Subject: [PATCH 2/3] Avoid incompatibility with PHPUnit v4.x --- tests/Standards/AbstractSniffUnitTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Standards/AbstractSniffUnitTest.php b/tests/Standards/AbstractSniffUnitTest.php index 2af5e41eff..178295ac16 100644 --- a/tests/Standards/AbstractSniffUnitTest.php +++ b/tests/Standards/AbstractSniffUnitTest.php @@ -197,7 +197,7 @@ final public function testSniff() $fixedFilename = basename($fixedFile); $failureMessages[] = "Fixed version of $filename does not match expected version in $fixedFilename; the diff is\n$diff"; } - } else { + } else if (is_callable([$this, 'addWarning']) === true) { $this->addWarning("Unable to verify auto-fixer results. File not found: $fixedFile"); } }//end if From 60f4ff74b7220e252a18a5c6cef30862e6d55164 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Thu, 8 Feb 2024 19:22:58 +0000 Subject: [PATCH 3/3] Update text per @jrfnl suggestion --- tests/Standards/AbstractSniffUnitTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Standards/AbstractSniffUnitTest.php b/tests/Standards/AbstractSniffUnitTest.php index 178295ac16..c400758468 100644 --- a/tests/Standards/AbstractSniffUnitTest.php +++ b/tests/Standards/AbstractSniffUnitTest.php @@ -190,15 +190,15 @@ 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("Unable to verify auto-fixer results. File not found: $fixedFile"); + $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