Skip to content

Commit

Permalink
F
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfnl committed Nov 22, 2024
1 parent 65b18e5 commit b55a9ba
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions tests/Core/Ruleset/RegisterSniffsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ final class RegisterSniffsTest extends TestCase
* @var array<string>
*/
private static $psr1SniffFiles = [
'Generic/Sniffs/Files/ByteOrderMarkSniff.php',
'Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php',
'Generic/Sniffs/PHP/DisallowAlternativePHPTagsSniff.php',
'Generic/Sniffs/PHP/DisallowShortOpenTagSniff.php',
'PSR1/Sniffs/Classes/ClassDeclarationSniff.php',
'PSR1/Sniffs/Files/SideEffectsSniff.php',
'PSR1/Sniffs/Methods/CamelCapsMethodNameSniff.php',
'Generic/Sniffs/PHP/DisallowAlternativePHPTagsSniff.php',
'Generic/Sniffs/PHP/DisallowShortOpenTagSniff.php',
'Generic/Sniffs/Files/ByteOrderMarkSniff.php',
'Squiz/Sniffs/Classes/ValidClassNameSniff.php',
'Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php',
];

/**
Expand All @@ -72,9 +72,13 @@ public static function initializeConfigAndRuleset()
$config = new ConfigDouble(['--standard=PSR1']);
self::$ruleset = new Ruleset($config);

// Remember the original value of the Ruleset::$sniff property as the tests may adjust it.
// Remember the original value of the Ruleset::$sniff property as the tests adjust it.
self::$originalSniffs = self::$ruleset->sniffs;

// Sort the value 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.
ksort(self::$originalSniffs);

// Update the sniff file list.
$standardsDir = dirname(dirname(dirname(__DIR__))).DIRECTORY_SEPARATOR;
$standardsDir .= 'src'.DIRECTORY_SEPARATOR.'Standards'.DIRECTORY_SEPARATOR;
Expand Down Expand Up @@ -179,14 +183,17 @@ public function testRegisteredSniffsWithExclusions()
$ruleset = new Ruleset($config);

$expected = [
'PHP_CodeSniffer\\Standards\\Generic\\Sniffs\\Files\\ByteOrderMarkSniff',
'PHP_CodeSniffer\\Standards\\Generic\\Sniffs\\NamingConventions\\UpperCaseConstantNameSniff',
'PHP_CodeSniffer\\Standards\\Generic\\Sniffs\\PHP\\DisallowAlternativePHPTagsSniff',
'PHP_CodeSniffer\\Standards\\Generic\\Sniffs\\PHP\\DisallowShortOpenTagSniff',
'PHP_CodeSniffer\\Standards\\Generic\\Sniffs\\Files\\ByteOrderMarkSniff',
'PHP_CodeSniffer\\Standards\\Squiz\\Sniffs\\Classes\\ValidClassNameSniff',
'PHP_CodeSniffer\\Standards\\Generic\\Sniffs\\NamingConventions\\UpperCaseConstantNameSniff',
];

$this->assertSame($expected, array_keys($ruleset->sniffs));
$actual = array_keys($ruleset->sniffs);
sort($actual);

$this->assertSame($expected, $actual);

}//end testRegisteredSniffsWithExclusions()

Expand All @@ -213,8 +220,8 @@ public function testRegisteredSniffsBothRestrictionsAndExclusions()
];

$expected = [
'PHP_CodeSniffer\\Standards\\PSR1\\Sniffs\\Classes\\ClassDeclarationSniff',
'PHP_CodeSniffer\\Standards\\Generic\\Sniffs\\PHP\\DisallowShortOpenTagSniff',
'PHP_CodeSniffer\\Standards\\PSR1\\Sniffs\\Classes\\ClassDeclarationSniff',
];

self::$ruleset->registerSniffs(self::$psr1SniffAbsolutePaths, $restrictions, $exclusions);
Expand Down Expand Up @@ -262,7 +269,7 @@ public function testRegisteredSniffsFiltersOutFilePathsWithoutSniffsDir()
$extraPathsBaseDir = __DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR;
$extraPaths = [
'DirectoryExpansion/.hiddenAbove/src/MyStandard/Utils/NotInSniffsDirSniff.php',
'DirectoryExpansion/.hiddenAbove/src/MyStandard/Utils/SubDir\NotInSniffsDirSniff.php',
'DirectoryExpansion/.hiddenAbove/src/MyStandard/Utils/SubDir/NotInSniffsDirSniff.php',
];
$extraPaths = self::relativeToAbsoluteSniffFiles($extraPathsBaseDir, $extraPaths);

Expand Down

0 comments on commit b55a9ba

Please sign in to comment.