Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions tests/Core/Ruleset/RuleInclusionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,37 @@ final class RuleInclusionTest extends TestCase
/**
* Initialize the config and ruleset objects based on the `RuleInclusionTest.xml` ruleset file.
*
* @beforeClass
* @before
*
* @return void
*/
public static function initializeConfigAndRuleset()
{
$standard = __DIR__.'/'.basename(__FILE__, '.php').'.xml';
self::$standard = $standard;
if (self::$standard === '') {
$standard = __DIR__.'/'.basename(__FILE__, '.php').'.xml';
self::$standard = $standard;

// On-the-fly adjust the ruleset test file to be able to test
// sniffs included with relative paths.
$contents = file_get_contents($standard);
self::$contents = $contents;
// On-the-fly adjust the ruleset test file to be able to test
// sniffs included with relative paths.
$contents = file_get_contents($standard);
self::$contents = $contents;

$repoRootDir = basename(dirname(dirname(dirname(__DIR__))));
$repoRootDir = basename(dirname(dirname(dirname(__DIR__))));

$newPath = $repoRootDir;
if (DIRECTORY_SEPARATOR === '\\') {
$newPath = str_replace('\\', '/', $repoRootDir);
}
$newPath = $repoRootDir;
if (DIRECTORY_SEPARATOR === '\\') {
$newPath = str_replace('\\', '/', $repoRootDir);
}

$adjusted = str_replace('%path_root_dir%', $newPath, $contents);
$adjusted = str_replace('%path_root_dir%', $newPath, $contents);

if (file_put_contents($standard, $adjusted) === false) {
self::markTestSkipped('On the fly ruleset adjustment failed');
}
if (file_put_contents($standard, $adjusted) === false) {
self::markTestSkipped('On the fly ruleset adjustment failed');
}

$config = new ConfigDouble(["--standard=$standard"]);
self::$ruleset = new Ruleset($config);
$config = new ConfigDouble(["--standard=$standard"]);
self::$ruleset = new Ruleset($config);
}//end if

}//end initializeConfigAndRuleset()

Expand All @@ -101,7 +103,7 @@ public function resetRuleset()
*/
public function testHasSniffCodes()
{
$this->assertCount(48, self::$ruleset->sniffCodes);
$this->assertCount(49, self::$ruleset->sniffCodes);

}//end testHasSniffCodes()

Expand Down Expand Up @@ -318,6 +320,10 @@ public static function dataRegisteredSniffCodes()
'Generic.Metrics.CyclomaticComplexity',
'PHP_CodeSniffer\Standards\Generic\Sniffs\Metrics\CyclomaticComplexitySniff',
],
[
'Squiz.Files.FileExtension',
'PHP_CodeSniffer\Standards\Squiz\Sniffs\Files\FileExtensionSniff',
],
[
'Generic.NamingConventions.CamelCapsFunctionName',
'PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff',
Expand Down Expand Up @@ -468,6 +474,10 @@ public static function dataSettingInvalidPropertiesOnStandardsAndCategoriesSilen
'sniffClass' => 'PHP_CodeSniffer\Standards\PSR12\Sniffs\Operators\OperatorSpacingSniff',
'propertyName' => 'setforallincategory',
],
'Set property for all sniffs in included category directory' => [
'sniffClass' => 'PHP_CodeSniffer\Standards\Squiz\Sniffs\Files\FileExtensionSniff',
'propertyName' => 'setforsquizfilessniffs',
],
];

}//end dataSettingInvalidPropertiesOnStandardsAndCategoriesSilentlyFails()
Expand Down
9 changes: 9 additions & 0 deletions tests/Core/Ruleset/RuleInclusionTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
</properties>
</rule>

<!-- Sniff directory include. -->
<rule ref="./src/Standards/Squiz/Sniffs/Files/">
<properties>
<property name="setforsquizfilessniffs" value="true" />
</properties>
</rule>

<!-- Sniff file include. -->
<rule ref="./src/Standards/Generic/Sniffs/Files/LineLengthSniff.php">
<properties>
<property name="lineLimit" value="10" />
Expand All @@ -39,6 +47,7 @@
</properties>
</rule>

<!-- Ruleset file include. -->
<rule ref="./RuleInclusionTest-include.xml">
<!-- Property being set for all sniffs included in this ruleset. -->
<properties>
Expand Down