|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Tests for the \PHP_CodeSniffer\Filters\Filter class. |
| 4 | + * |
| 5 | + * @copyright 2025 PHPCSStandards Contributors |
| 6 | + * @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/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 files without extension. |
| 17 | + * |
| 18 | + * @covers \PHP_CodeSniffer\Filters\Filter |
| 19 | + */ |
| 20 | +final class ShouldProcessFileWithoutExtensionTest extends AbstractFilterTestCase |
| 21 | +{ |
| 22 | + |
| 23 | + |
| 24 | + /** |
| 25 | + * Verify that if a file without file extension is explicitly requested for scan, it is accepted. |
| 26 | + * |
| 27 | + * @return void |
| 28 | + */ |
| 29 | + public function testFileWithoutExtensionIsAcceptedWhenExplicitlyRequested() |
| 30 | + { |
| 31 | + $fileWithoutExt = self::getBaseDir().'/bin/phpcs'; |
| 32 | + |
| 33 | + $fakeDI = new RecursiveArrayIterator([$fileWithoutExt]); |
| 34 | + $filter = new Filter($fakeDI, $fileWithoutExt, self::$config, self::$ruleset); |
| 35 | + |
| 36 | + $this->assertSame([$fileWithoutExt], $this->getFilteredResultsAsArray($filter)); |
| 37 | + |
| 38 | + }//end testFileWithoutExtensionIsAcceptedWhenExplicitlyRequested() |
| 39 | + |
| 40 | + |
| 41 | + /** |
| 42 | + * Verify that when (recursively) scanning a directory, files without extension are filtered out. |
| 43 | + * |
| 44 | + * @return void |
| 45 | + */ |
| 46 | + public function testFileWithoutExtensionIsRejectedWhenRecursingDirectory() |
| 47 | + { |
| 48 | + $baseDir = self::getBaseDir(); |
| 49 | + $fakeFileList = [ |
| 50 | + $baseDir.'/autoload.php', |
| 51 | + $baseDir.'/bin', |
| 52 | + $baseDir.'/bin/phpcs', |
| 53 | + $baseDir.'/scripts', |
| 54 | + $baseDir.'/scripts/build-phar.php', |
| 55 | + ]; |
| 56 | + $fakeDI = new RecursiveArrayIterator($fakeFileList); |
| 57 | + $filter = new Filter($fakeDI, self::getBaseDir(), self::$config, self::$ruleset); |
| 58 | + |
| 59 | + $expectedOutput = [ |
| 60 | + $baseDir.'/autoload.php', |
| 61 | + $baseDir.'/bin', |
| 62 | + $baseDir.'/scripts', |
| 63 | + $baseDir.'/scripts/build-phar.php', |
| 64 | + ]; |
| 65 | + |
| 66 | + $this->assertSame($expectedOutput, $this->getFilteredResultsAsArray($filter)); |
| 67 | + |
| 68 | + }//end testFileWithoutExtensionIsRejectedWhenRecursingDirectory() |
| 69 | + |
| 70 | + |
| 71 | +}//end class |
0 commit comments