PATH:
opt
/
cpanel
/
ea-wappspector
/
vendor
/
squizlabs
/
php_codesniffer
/
tests
/
Core
/
Ruleset
<?php /** * Test the Ruleset::expandRulesetReference() method. * * @author Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl> * @copyright 2024 PHPCSStandards and contributors * @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence */ namespace PHP_CodeSniffer\Tests\Core\Ruleset; use PHP_CodeSniffer\Ruleset; use PHP_CodeSniffer\Tests\ConfigDouble; use PHP_CodeSniffer\Tests\Core\Ruleset\AbstractRulesetTestCase; /** * Test various aspects of the Ruleset::expandRulesetReference() method not covered by other tests. * * @covers \PHP_CodeSniffer\Ruleset::expandRulesetReference */ final class ExpandRulesetReferenceTest extends AbstractRulesetTestCase { /** * Test handling of path references relative to the originally included ruleset. * * @return void */ public function testRulesetRelativePathReferences() { // Set up the ruleset. $standard = __DIR__.'/ExpandRulesetReferenceTest.xml'; $config = new ConfigDouble(["--standard=$standard"]); $ruleset = new Ruleset($config); $expected = [ 'ExternalA.CheckSomething.Valid' => 'Fixtures\\ExternalA\\Sniffs\\CheckSomething\\ValidSniff', 'TestStandard.ValidSniffs.RegisterEmptyArray' => 'Fixtures\\TestStandard\\Sniffs\\ValidSniffs\\RegisterEmptyArraySniff', 'ExternalB.CheckMore.Valid' => 'Fixtures\\ExternalB\\Sniffs\\CheckMore\\ValidSniff', ]; $this->assertSame($expected, $ruleset->sniffCodes); }//end testRulesetRelativePathReferences() /** * Test that an exception is thrown if a ruleset contains an unresolvable reference. * * @param string $standard The standard to use for the test. * @param string $replacement The reference which will be used in the exception message. * * @dataProvider dataUnresolvableReferenceThrowsException * * @return void */ public function testUnresolvableReferenceThrowsException($standard, $replacement) { // Set up the ruleset. $standard = __DIR__.'/'.$standard; $config = new ConfigDouble(["--standard=$standard"]); $exceptionMessage = 'ERROR: Referenced sniff "%s" does not exist.'.PHP_EOL; $exceptionMessage .= 'ERROR: No sniffs were registered.'.PHP_EOL.PHP_EOL; $this->expectRuntimeExceptionMessage(sprintf($exceptionMessage, $replacement)); new Ruleset($config); }//end testUnresolvableReferenceThrowsException() /** * Data provider. * * @see testUnresolvableReferenceThrowsException() * * @return array<string, array<string, string>> */ public static function dataUnresolvableReferenceThrowsException() { $data = [ 'Referencing a non-existent XML file' => [ 'standard' => 'ExpandRulesetReferenceMissingFileTest.xml', 'replacement' => './MissingFile.xml', ], 'Referencing an invalid directory starting with "~"' => [ 'standard' => 'ExpandRulesetReferenceInvalidHomePathRefTest.xml', 'replacement' => '~/src/Standards/Squiz/Sniffs/Files/', ], 'Referencing an unknown standard' => [ 'standard' => 'ExpandRulesetReferenceUnknownStandardTest.xml', 'replacement' => 'UnknownStandard', ], 'Referencing a non-existent category in a known standard' => [ 'standard' => 'ExpandRulesetReferenceUnknownCategoryTest.xml', 'replacement' => 'TestStandard.UnknownCategory', ], 'Referencing a non-existent sniff in a known standard' => [ 'standard' => 'ExpandRulesetReferenceUnknownSniffTest.xml', 'replacement' => 'TestStandard.InvalidSniffs.UnknownRule', ], 'Referencing an invalid error code - no standard name' => [ 'standard' => 'ExpandRulesetReferenceInvalidErrorCode1Test.xml', 'replacement' => '.Invalid.Undetermined.Found', ], 'Referencing an invalid error code - no category name' => [ 'standard' => 'ExpandRulesetReferenceInvalidErrorCode2Test.xml', 'replacement' => 'Standard..Undetermined.Found', ], 'Referencing an invalid error code - no sniff name' => [ 'standard' => 'ExpandRulesetReferenceInvalidErrorCode3Test.xml', 'replacement' => 'Standard.Invalid..Found', ], ]; // Add tests which are only relevant for case-sensitive OSes. if (stripos(PHP_OS, 'WIN') === false) { $data['Referencing an existing sniff, but there is a case mismatch (OS-dependent) [1]'] = [ 'standard' => 'ExpandRulesetReferenceCaseMismatch1Test.xml', 'replacement' => 'psr12.functions.nullabletypedeclaration', ]; $data['Referencing an existing sniff, but there is a case mismatch (OS-dependent) [2]'] = [ 'standard' => 'ExpandRulesetReferenceCaseMismatch2Test.xml', 'replacement' => 'PSR12.Functions.ReturntypeDeclaration', ]; } return $data; }//end dataUnresolvableReferenceThrowsException() }//end class
[+]
..
[-] ProcessRulesetShouldProcessElementTest.xml
[edit]
[-] ProcessRulesetAutoExpandSniffsDirectoryTest.xml
[edit]
[-] ProcessRulesetExcludeSniffGroupTest.xml
[edit]
[-] PropertyTypeHandlingTest.xml
[edit]
[-] ExplainCustomRulesetTest.xml
[edit]
[-] ShowSniffDeprecationsInvalidDeprecationVersionTest.xml
[edit]
[-] RegisterSniffsMissingInterfaceTest.php
[edit]
[-] ExpandRulesetReferenceCaseMismatch2Test.xml
[edit]
[-] PopulateTokenListenersTest.php
[edit]
[-] ExpandSniffDirectoryTest.xml
[edit]
[-] ExpandRulesetReferenceInvalidErrorCode1Test.xml
[edit]
[-] SetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForStandardTest.xml
[edit]
[-] ExpandRulesetReferenceTest.php
[edit]
[-] RegisterSniffsMissingInterfaceValidTest.xml
[edit]
[-] ExpandRulesetReferenceHomePathTest.php
[edit]
[-] ExpandRulesetReferenceUnknownCategoryTest.xml
[edit]
[-] ExpandSniffDirectoryTest.php
[edit]
[-] RuleInclusionAbsoluteWindowsTest.php
[edit]
[-] AbstractRulesetTestCase.php
[edit]
[-] ProcessRulesetTest.php
[edit]
[-] ShowSniffDeprecationsEmptyRemovalVersionTest.xml
[edit]
[-] GetIncludePatternsTest.xml
[edit]
[-] RegisterSniffsRejectsInvalidSniffNoImplementsNoRegisterOrProcessTest.xml
[edit]
[-] RegisterSniffsTest.php
[edit]
[+]
Fixtures
[-] SetPropertyAppliesPropertyToMultipleSniffsInCategoryTest.xml
[edit]
[-] ShowSniffDeprecationsTest.xml
[edit]
[-] ExpandRulesetReferenceMissingFileTest.xml
[edit]
[-] ProcessRulesetBrokenRulesetEmptyFileTest.xml
[edit]
[-] ExpandRulesetReferenceInternalIgnoreTest.xml
[edit]
[-] ExpandRulesetReferenceInternalTest.php
[edit]
[-] ProcessRulesetMiscTest.xml
[edit]
[-] SetPropertyAllowedViaStdClassTest.xml
[edit]
[-] PopulateTokenListenersRegisterNoArrayTest.xml
[edit]
[-] RegisterSniffsRejectsInvalidSniffNoImplementsNoProcessTest.xml
[edit]
[-] ExpandRulesetReferenceUnknownSniffTest.xml
[edit]
[-] ProcessRulesetBrokenRulesetSingleErrorTest.xml
[edit]
[-] ExpandRulesetReferenceCaseMismatch1Test.xml
[edit]
[-] SetPropertyNotAllowedViaAttributeTest.xml
[edit]
[-] GetIgnorePatternsTest.xml
[edit]
[-] RuleInclusionAbsoluteLinuxTest.xml
[edit]
[-] ShowSniffDeprecationsEmptyDeprecationVersionTest.xml
[edit]
[-] PopulateTokenListenersSupportedTokenizersTest.php
[edit]
[-] ShowSniffDeprecationsInvalidRemovalVersionTest.xml
[edit]
[-] ShowSniffDeprecationsTest.php
[edit]
[-] ProcessRuleInvalidTypeTest.php
[edit]
[-] RegisterSniffsRejectsInvalidSniffTest.php
[edit]
[-] SetPropertyAllowedAsDeclaredTest.xml
[edit]
[-] ShowSniffDeprecationsReportWidthTest.xml
[edit]
[-] ProcessRuleInvalidTypeTest.xml
[edit]
[-] ExpandRulesetReferenceInternalStandardTest.xml
[edit]
[-] ExpandRulesetReferenceInvalidErrorCode2Test.xml
[edit]
[-] PopulateTokenListenersNamingConventionsTest.xml
[edit]
[-] SetSniffPropertyTest.php
[edit]
[-] ProcessRuleShouldProcessElementTest.xml
[edit]
[-] RuleInclusionTest-include.xml
[edit]
[-] ShowSniffDeprecationsInvalidDeprecationMessageTest.xml
[edit]
[-] PopulateTokenListenersSupportedTokenizersTest.xml
[edit]
[-] RuleInclusionTest.xml
[edit]
[-] ProcessRulesetAutoloadFileNotFoundTest.xml
[edit]
[-] RuleInclusionTest.php
[edit]
[-] PopulateTokenListenersNamingConventionsTest.php
[edit]
[-] ExplainSingleSniffTest.xml
[edit]
[-] GetIncludePatternsTest.php
[edit]
[-] GetIgnorePatternsTest.php
[edit]
[-] RegisterSniffsRejectsInvalidSniffNoImplementsNoRegisterTest.xml
[edit]
[-] ExpandRulesetReferenceHomePathFailTest.xml
[edit]
[-] ProcessRuleShouldProcessElementTest.php
[edit]
[-] ExpandRulesetReferenceUnknownStandardTest.xml
[edit]
[-] ExplainTest.php
[edit]
[-] PopulateTokenListenersTest.xml
[edit]
[-] ExpandRulesetReferenceHomePathTest.xml
[edit]
[-] ConstructorTest.php
[edit]
[-] PropertyTypeHandlingTest.php
[edit]
[-] ProcessRulesetAutoloadTest.php
[edit]
[-] PropertyTypeHandlingInlineTest.xml
[edit]
[-] SetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForCategoryTest.xml
[edit]
[-] RegisterSniffsMissingInterfaceInvalidTest.xml
[edit]
[-] ProcessRulesetAutoloadTest.xml
[edit]
[-] SetPropertyAllowedViaMagicMethodTest.xml
[edit]
[-] ProcessRulesetInvalidNoSniffsDirTest.xml
[edit]
[-] ShowSniffDeprecationsOrderTest.xml
[edit]
[-] ExpandRulesetReferenceInvalidErrorCode3Test.xml
[edit]
[-] RuleInclusionAbsoluteLinuxTest.php
[edit]
[-] SetPropertyThrowsErrorOnInvalidPropertyTest.xml
[edit]
[-] ProcessRulesetBrokenRulesetTest.php
[edit]
[-] ConstructorNoSniffsTest.xml
[edit]
[-] ExpandRulesetReferenceInvalidHomePathRefTest.xml
[edit]
[-] ExpandRulesetReferenceTest.xml
[edit]
[-] ProcessRulesetBrokenRulesetMultiErrorTest.xml
[edit]
[-] RuleInclusionAbsoluteWindowsTest.xml
[edit]
[-] ProcessRulesetShouldProcessElementTest.php
[edit]
[-] DisplayCachedMessagesTest.php
[edit]