|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Tests for the \PHP_CodeSniffer\Filters\Filter class. |
| 4 | + * |
| 5 | + * @copyright 2025 PHPCSStandards and contributors |
| 6 | + * @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/HEAD/licence.txt BSD Licence |
| 7 | + */ |
| 8 | + |
| 9 | +namespace PHP_CodeSniffer\Tests\Core\Filters\Filter; |
| 10 | + |
| 11 | +use PHP_CodeSniffer\Filters\Filter; |
| 12 | +use PHP_CodeSniffer\Tests\Core\Filters\AbstractFilterTestCase; |
| 13 | +use RecursiveArrayIterator; |
| 14 | + |
| 15 | +/** |
| 16 | + * Tests handling of hidden files. |
| 17 | + * |
| 18 | + * @covers \PHP_CodeSniffer\Filters\Filter |
| 19 | + */ |
| 20 | +final class ShouldProcessHiddenFileTest extends AbstractFilterTestCase |
| 21 | +{ |
| 22 | + |
| 23 | + |
| 24 | + /** |
| 25 | + * Verify that if a hidden is explicitly requested for scan, it is accepted. |
| 26 | + * |
| 27 | + * @return void |
| 28 | + */ |
| 29 | + public function testHiddenFileIsAcceptedWhenExplicitlyRequested() |
| 30 | + { |
| 31 | + $hiddenFile = self::getBaseDir() . '/.config.php'; |
| 32 | + |
| 33 | + $fakeDI = new RecursiveArrayIterator([$hiddenFile]); |
| 34 | + $filter = new Filter($fakeDI, $hiddenFile, self::$config, self::$ruleset); |
| 35 | + |
| 36 | + $this->assertSame([$hiddenFile], $this->getFilteredResultsAsArray($filter)); |
| 37 | + } |
| 38 | + |
| 39 | + |
| 40 | + /** |
| 41 | + * Verify that when (recursively) scanning a directory, hidden files are filtered out. |
| 42 | + * |
| 43 | + * @return void |
| 44 | + */ |
| 45 | + public function testHiddenFileIsRejectedWhenRecursingDirectory() |
| 46 | + { |
| 47 | + $baseDir = self::getBaseDir(); |
| 48 | + $fakeFileList = [ |
| 49 | + $baseDir . '/.config.php', |
| 50 | + $baseDir . '/autoload.php', |
| 51 | + $baseDir . '/scripts', |
| 52 | + $baseDir . '/scripts/.script-config.php', |
| 53 | + ]; |
| 54 | + $fakeDI = new RecursiveArrayIterator($fakeFileList); |
| 55 | + $filter = new Filter($fakeDI, self::getBaseDir(), self::$config, self::$ruleset); |
| 56 | + |
| 57 | + $expectedOutput = [ |
| 58 | + $baseDir . '/autoload.php', |
| 59 | + $baseDir . '/scripts', |
| 60 | + ]; |
| 61 | + |
| 62 | + $this->assertSame($expectedOutput, $this->getFilteredResultsAsArray($filter)); |
| 63 | + } |
| 64 | +} |
0 commit comments