-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ruleset::getIncludePatterns(): add tests
- Loading branch information
Showing
2 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
/** | ||
* Test the Ruleset::getIncludePatterns() 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 PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Test the Ruleset::getIncludePatterns() method. | ||
* | ||
* @covers \PHP_CodeSniffer\Ruleset::getIncludePatterns | ||
*/ | ||
final class GetIncludePatternsTest extends TestCase | ||
{ | ||
|
||
/** | ||
* The Ruleset object. | ||
* | ||
* @var \PHP_CodeSniffer\Ruleset | ||
*/ | ||
private static $ruleset; | ||
|
||
|
||
/** | ||
* Initialize the config and ruleset objects for this test. | ||
* | ||
* @beforeClass | ||
* | ||
* @return void | ||
*/ | ||
public static function initializeConfigAndRuleset() | ||
{ | ||
// Set up the ruleset. | ||
$standard = __DIR__."/GetIncludePatternsTest.xml"; | ||
$config = new ConfigDouble(["--standard=$standard"]); | ||
self::$ruleset = new Ruleset($config); | ||
|
||
}//end initializeConfigAndRuleset() | ||
|
||
|
||
/** | ||
* Test retrieving include patterns. | ||
* | ||
* @param string|null $listener The listener to get patterns for or null for all patterns. | ||
* @param array<string, string|array<string, string>> $expected The expected function output. | ||
* | ||
* @dataProvider dataGetIncludePatterns | ||
* | ||
* @return void | ||
*/ | ||
public function testGetIncludePatterns($listener, $expected) | ||
{ | ||
$this->assertSame($expected, self::$ruleset->getIncludePatterns($listener)); | ||
|
||
}//end testGetIncludePatterns() | ||
|
||
|
||
/** | ||
* Data provider. | ||
* | ||
* @see self::testGetIncludePatterns() | ||
* | ||
* @return array<string, array<string, string|array<string, string|array<string, string>>|null>> | ||
*/ | ||
public static function dataGetIncludePatterns() | ||
{ | ||
return [ | ||
'All include patterns' => [ | ||
'listener' => null, | ||
'expected' => [ | ||
'PSR1.Classes.ClassDeclaration' => [ | ||
'./src/*/file.php' => 'absolute', | ||
'./bin/' => 'absolute', | ||
], | ||
'Generic.Formatting.SpaceAfterCast' => [ | ||
'./src/*/test\\.php$' => 'absolute', | ||
], | ||
], | ||
], | ||
'Include patterns for PSR1.Classes.ClassDeclaration' => [ | ||
'listener' => 'PSR1.Classes.ClassDeclaration', | ||
'expected' => [ | ||
'./src/*/file.php' => 'absolute', | ||
'./bin/' => 'absolute', | ||
], | ||
], | ||
'Include patterns for Generic.Formatting.SpaceAfterCast' => [ | ||
'listener' => 'Generic.Formatting.SpaceAfterCast', | ||
'expected' => ['./src/*/test\\.php$' => 'absolute'], | ||
], | ||
'Include patterns for sniff without include patterns' => [ | ||
'listener' => 'PSR1.Files.SideEffects', | ||
'expected' => [], | ||
], | ||
]; | ||
|
||
}//end dataGetIncludePatterns() | ||
|
||
|
||
}//end class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0"?> | ||
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="GetIncludePatternsTest" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd"> | ||
|
||
<rule ref="PSR1"/> | ||
|
||
<rule ref="PSR1.Classes.ClassDeclaration"> | ||
<include-pattern>./src/*/file.php</include-pattern> | ||
<include-pattern>./bin/</include-pattern> | ||
</rule> | ||
|
||
<rule ref="Generic.Formatting.SpaceAfterCast"> | ||
<include-pattern>./src/*/test\.php$</include-pattern> | ||
</rule> | ||
|
||
</ruleset> |