|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Test the Ruleset::getIgnorePatterns() method. |
| 4 | + * |
| 5 | + * @author Juliette Reinders Folmer <[email protected]> |
| 6 | + * @copyright 2024 PHPCSStandards and contributors |
| 7 | + * @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence |
| 8 | + */ |
| 9 | + |
| 10 | +namespace PHP_CodeSniffer\Tests\Core\Ruleset; |
| 11 | + |
| 12 | +use PHP_CodeSniffer\Ruleset; |
| 13 | +use PHP_CodeSniffer\Tests\ConfigDouble; |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | + |
| 16 | +/** |
| 17 | + * Test the Ruleset::getIgnorePatterns() method. |
| 18 | + * |
| 19 | + * @covers \PHP_CodeSniffer\Ruleset::getIgnorePatterns |
| 20 | + */ |
| 21 | +final class GetIgnorePatternsTest extends TestCase |
| 22 | +{ |
| 23 | + |
| 24 | + /** |
| 25 | + * The Ruleset object. |
| 26 | + * |
| 27 | + * @var \PHP_CodeSniffer\Ruleset |
| 28 | + */ |
| 29 | + private static $ruleset; |
| 30 | + |
| 31 | + |
| 32 | + /** |
| 33 | + * Initialize the config and ruleset objects for this test. |
| 34 | + * |
| 35 | + * @beforeClass |
| 36 | + * |
| 37 | + * @return void |
| 38 | + */ |
| 39 | + public static function initializeConfigAndRuleset() |
| 40 | + { |
| 41 | + // Set up the ruleset. |
| 42 | + $standard = __DIR__.'/GetIgnorePatternsTest.xml'; |
| 43 | + $config = new ConfigDouble(["--standard=$standard"]); |
| 44 | + self::$ruleset = new Ruleset($config); |
| 45 | + |
| 46 | + }//end initializeConfigAndRuleset() |
| 47 | + |
| 48 | + |
| 49 | + /** |
| 50 | + * Test retrieving ignore patterns. |
| 51 | + * |
| 52 | + * @param string|null $listener The listener to get patterns for or null for all patterns. |
| 53 | + * @param array<string, string|array<string, string>> $expected The expected function output. |
| 54 | + * |
| 55 | + * @dataProvider dataGetIgnorePatterns |
| 56 | + * |
| 57 | + * @return void |
| 58 | + */ |
| 59 | + public function testGetIgnorePatterns($listener, $expected) |
| 60 | + { |
| 61 | + $this->assertSame($expected, self::$ruleset->getIgnorePatterns($listener)); |
| 62 | + |
| 63 | + }//end testGetIgnorePatterns() |
| 64 | + |
| 65 | + |
| 66 | + /** |
| 67 | + * Data provider. |
| 68 | + * |
| 69 | + * @see self::testGetIgnorePatterns() |
| 70 | + * |
| 71 | + * @return array<string, array<string, string|array<string, string|array<string, string>>|null>> |
| 72 | + */ |
| 73 | + public static function dataGetIgnorePatterns() |
| 74 | + { |
| 75 | + return [ |
| 76 | + 'All ignore patterns' => [ |
| 77 | + 'listener' => null, |
| 78 | + 'expected' => [ |
| 79 | + 'PSR1.Classes.ClassDeclaration' => [ |
| 80 | + './src/*/file.php' => 'absolute', |
| 81 | + './bin/' => 'relative', |
| 82 | + ], |
| 83 | + 'Generic.Formatting.SpaceAfterCast' => [ |
| 84 | + './src/*/test\\.php$' => 'absolute', |
| 85 | + ], |
| 86 | + './tests/' => 'absolute', |
| 87 | + './vendor/*' => 'absolute', |
| 88 | + '*/node-modules/*' => 'relative', |
| 89 | + ], |
| 90 | + ], |
| 91 | + 'Ignore patterns for PSR1.Classes.ClassDeclaration' => [ |
| 92 | + 'listener' => 'PSR1.Classes.ClassDeclaration', |
| 93 | + 'expected' => [ |
| 94 | + './src/*/file.php' => 'absolute', |
| 95 | + './bin/' => 'relative', |
| 96 | + ], |
| 97 | + ], |
| 98 | + 'Ignore patterns for Generic.Formatting.SpaceAfterCast' => [ |
| 99 | + 'listener' => 'Generic.Formatting.SpaceAfterCast', |
| 100 | + 'expected' => ['./src/*/test\\.php$' => 'absolute'], |
| 101 | + ], |
| 102 | + 'Ignore patterns for sniff without ignore patterns' => [ |
| 103 | + 'listener' => 'PSR1.Files.SideEffects', |
| 104 | + 'expected' => [], |
| 105 | + ], |
| 106 | + ]; |
| 107 | + |
| 108 | + }//end dataGetIgnorePatterns() |
| 109 | + |
| 110 | + |
| 111 | +}//end class |
0 commit comments