|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Test the Ruleset::expandRulesetReference() method. |
| 4 | + * |
| 5 | + * @author Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl> |
| 6 | + * @copyright 2025 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 PHP_CodeSniffer\Tests\Core\Ruleset\AbstractRulesetTestCase; |
| 15 | + |
| 16 | +/** |
| 17 | + * Test handling of "internal" references in the Ruleset::expandRulesetReference() method. |
| 18 | + * |
| 19 | + * @covers \PHP_CodeSniffer\Ruleset::expandRulesetReference |
| 20 | + */ |
| 21 | +final class ExpandRulesetReferenceInternalTest extends AbstractRulesetTestCase |
| 22 | +{ |
| 23 | + |
| 24 | + |
| 25 | + /** |
| 26 | + * Verify that a ruleset reference starting with "Internal." (including the dot) doesn't cause any sniffs to be registered. |
| 27 | + * |
| 28 | + * @return void |
| 29 | + */ |
| 30 | + public function testInternalRefDoesNotGetExpanded() |
| 31 | + { |
| 32 | + // Set up the ruleset. |
| 33 | + $standard = __DIR__.'/ExpandRulesetReferenceInternalIgnoreTest.xml'; |
| 34 | + $config = new ConfigDouble(["--standard=$standard"]); |
| 35 | + $ruleset = new Ruleset($config); |
| 36 | + |
| 37 | + $expected = ['Generic.PHP.BacktickOperator' => 'PHP_CodeSniffer\\Standards\\Generic\\Sniffs\\PHP\\BacktickOperatorSniff']; |
| 38 | + |
| 39 | + $this->assertSame($expected, $ruleset->sniffCodes); |
| 40 | + |
| 41 | + }//end testInternalRefDoesNotGetExpanded() |
| 42 | + |
| 43 | + |
| 44 | + /** |
| 45 | + * While definitely not recommended, including a standard named "Internal", _does_ allow for sniffs to be registered. |
| 46 | + * |
| 47 | + * Note: customizations (exclusions/property setting etc) for individual sniffs may not always be handled correctly, |
| 48 | + * which is why naming a standard "Internal" is definitely not recommended. |
| 49 | + * |
| 50 | + * @return void |
| 51 | + */ |
| 52 | + public function testInternalStandardDoesGetExpanded() |
| 53 | + { |
| 54 | + // Set up the ruleset. |
| 55 | + $standard = __DIR__.'/ExpandRulesetReferenceInternalStandardTest.xml'; |
| 56 | + $config = new ConfigDouble(["--standard=$standard"]); |
| 57 | + $ruleset = new Ruleset($config); |
| 58 | + |
| 59 | + $expected = ['Internal.Valid.Valid' => 'Fixtures\\Internal\\Sniffs\\Valid\\ValidSniff']; |
| 60 | + |
| 61 | + $this->assertSame($expected, $ruleset->sniffCodes); |
| 62 | + |
| 63 | + }//end testInternalStandardDoesGetExpanded() |
| 64 | + |
| 65 | + |
| 66 | +}//end class |
0 commit comments