From def8714f53561dc010398bf78a1bc257c3d71127 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 5 Sep 2025 04:07:55 +0200 Subject: [PATCH] :fire: Hot Fix: remove FileList tests PR 1113 introduced a set of tests for the `FileList` class to accompany a bug fix. However, it now looks like these tests break the ability to run sniff tests for external standards using the PHPCS native test framework. This is problematic and even more so as this will silently fail in CI, as PHPUnit 9 and lower exits with a `0` exit code when no tests are found. For now, I'm removing the tests for the `FileList` class, while keeping the bugfix. I've confirmed this fixes the issue by running the tests of two external standards which both use the PHPCS native test framework. Both were not running their tests with PHPCS 3.13.3 and the tests run correctly again with the `FileList` class tests removed. --- .../FileList/AbstractFileListTestCase.php | 55 ------- tests/Core/Files/FileList/AddFileTest.php | 138 ------------------ tests/Core/Files/FileList/ConstructTest.php | 122 ---------------- tests/Core/Files/FileList/FilterDouble.php | 31 ---- tests/Core/Files/FileList/Fixtures/file1.php | 3 - tests/Core/Files/FileList/Fixtures/file2.php | 3 - 6 files changed, 352 deletions(-) delete mode 100644 tests/Core/Files/FileList/AbstractFileListTestCase.php delete mode 100644 tests/Core/Files/FileList/AddFileTest.php delete mode 100644 tests/Core/Files/FileList/ConstructTest.php delete mode 100644 tests/Core/Files/FileList/FilterDouble.php delete mode 100644 tests/Core/Files/FileList/Fixtures/file1.php delete mode 100644 tests/Core/Files/FileList/Fixtures/file2.php diff --git a/tests/Core/Files/FileList/AbstractFileListTestCase.php b/tests/Core/Files/FileList/AbstractFileListTestCase.php deleted file mode 100644 index abced07317..0000000000 --- a/tests/Core/Files/FileList/AbstractFileListTestCase.php +++ /dev/null @@ -1,55 +0,0 @@ -filter = __DIR__.'/FilterDouble.php'; - self::$ruleset = new Ruleset(self::$config); - } - - }//end initializeConfigAndRuleset() - - -}//end class diff --git a/tests/Core/Files/FileList/AddFileTest.php b/tests/Core/Files/FileList/AddFileTest.php deleted file mode 100644 index 4346fbbf95..0000000000 --- a/tests/Core/Files/FileList/AddFileTest.php +++ /dev/null @@ -1,138 +0,0 @@ -files = []; - $this->fileList = new FileList(self::$config, self::$ruleset); - - }//end initializeFileList() - - - /** - * Test adding a file to the list. - * - * @param string $fileName The name of the file to add. - * @param object|null $fileObject An optional file object to add instead of creating a new one. - * - * @dataProvider dataAddFile - * - * @return void - */ - public function testAddFile($fileName, $fileObject=null) - { - $this->assertCount(0, $this->fileList); - - $this->fileList->addFile($fileName, $fileObject); - - $fileListArray = iterator_to_array($this->fileList); - - $this->assertCount(1, $this->fileList, 'File count mismatch'); - $this->assertArrayHasKey($fileName, $fileListArray, 'File not found in list'); - - if (isset($fileObject) === true) { - $this->assertSame($fileObject, $fileListArray[$fileName], 'File object mismatch'); - } else { - $this->assertInstanceOf( - 'PHP_CodeSniffer\Files\File', - $fileListArray[$fileName], - 'File object not found in list' - ); - } - - }//end testAddFile() - - - /** - * Data provider for testAddFile. - * - * @return array> - */ - public static function dataAddFile() - { - self::initializeConfigAndRuleset(); - - return [ - 'Regular file' => [ - 'fileName' => 'test1.php', - ], - 'STDIN' => [ - 'fileName' => 'STDIN', - ], - 'Regular file with file object' => [ - 'fileName' => 'test1.php', - 'fileObject' => new File('test1.php', self::$ruleset, self::$config), - ], - ]; - - }//end dataAddFile() - - - /** - * Test that it is not possible to add the same file twice. - * - * @return void - */ - public function testAddFileShouldNotAddTheSameFileTwice() - { - $file1 = 'test1.php'; - $file2 = 'test2.php'; - $expectedFiles = [ - $file1, - $file2, - ]; - - // Add $file1 once. - $this->fileList->addFile($file1); - $this->assertCount(1, $this->fileList); - $this->assertSame([$file1], array_keys(iterator_to_array($this->fileList))); - - // Try to add $file1 again. Should be ignored. - $this->fileList->addFile($file1); - $this->assertCount(1, $this->fileList); - $this->assertSame([$file1], array_keys(iterator_to_array($this->fileList))); - - // Add $file2. Should be added. - $this->fileList->addFile($file2); - $this->assertCount(2, $this->fileList); - $this->assertSame($expectedFiles, array_keys(iterator_to_array($this->fileList))); - - }//end testAddFileShouldNotAddTheSameFileTwice() - - -}//end class diff --git a/tests/Core/Files/FileList/ConstructTest.php b/tests/Core/Files/FileList/ConstructTest.php deleted file mode 100644 index f40a400993..0000000000 --- a/tests/Core/Files/FileList/ConstructTest.php +++ /dev/null @@ -1,122 +0,0 @@ - $files List of file paths in the Config class. - * @param array $expectedFiles List of expected file paths in the FileList. - * - * @dataProvider dataConstruct - * - * @return void - */ - public function testConstruct($files, $expectedFiles) - { - self::$config->files = $files; - - $fileList = new FileList(self::$config, self::$ruleset); - - $this->assertSame(self::$config, $fileList->config, 'Config object mismatch'); - $this->assertSame(self::$ruleset, $fileList->ruleset, 'Ruleset object mismatch'); - - $this->assertCount(count($expectedFiles), $fileList, 'File count mismatch'); - - $i = 0; - - // Sort the values to make the tests stable as different OSes will read directories - // in a different order and the order is not relevant for these tests. Just the values. - $fileListArray = iterator_to_array($fileList); - ksort($fileListArray); - - foreach ($fileListArray as $filePath => $fileObject) { - $this->assertSame( - $expectedFiles[$i], - $filePath, - sprintf('File path mismatch: expected "%s", got "%s"', $expectedFiles[$i], $filePath) - ); - $this->assertInstanceOf( - 'PHP_CodeSniffer\Files\File', - $fileObject, - sprintf('File object for "%s" is not an instance of PHP_CodeSniffer\Files\File', $filePath) - ); - $i++; - } - - }//end testConstruct() - - - /** - * Data provider for testConstruct. - * - * @return array>> - */ - public static function dataConstruct() - { - $fixturesDir = __DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR; - - return [ - 'No files' => [ - 'files' => [], - 'expectedFiles' => [], - ], - 'Two files' => [ - 'files' => [ - 'file1.php', - 'file2.php', - ], - 'expectedFiles' => [ - 'file1.php', - 'file2.php', - ], - ], - 'A directory' => [ - 'files' => [$fixturesDir], - 'expectedFiles' => [ - $fixturesDir.'file1.php', - $fixturesDir.'file2.php', - ], - ], - 'Same file twice' => [ - 'files' => [ - 'file1.php', - 'file1.php', - ], - 'expectedFiles' => [ - 'file1.php', - ], - ], - 'File and then directory containing that file' => [ - 'files' => [ - $fixturesDir.'file1.php', - $fixturesDir, - ], - 'expectedFiles' => [ - $fixturesDir.'file1.php', - $fixturesDir.'file2.php', - ], - ], - ]; - - }//end dataConstruct() - - -}//end class diff --git a/tests/Core/Files/FileList/FilterDouble.php b/tests/Core/Files/FileList/FilterDouble.php deleted file mode 100644 index 99952ef63c..0000000000 --- a/tests/Core/Files/FileList/FilterDouble.php +++ /dev/null @@ -1,31 +0,0 @@ -