Skip to content

Commit 8ed93db

Browse files
authored
Merge pull request #690 from PHPCSStandards/feature/ruleinclusiontests-improvements
RuleInclusionTest: record code coverage + one more test case
2 parents 56784f1 + 7e29324 commit 8ed93db

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

tests/Core/Ruleset/RuleInclusionTest.php

+29-19
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,37 @@ final class RuleInclusionTest extends TestCase
4747
/**
4848
* Initialize the config and ruleset objects based on the `RuleInclusionTest.xml` ruleset file.
4949
*
50-
* @beforeClass
50+
* @before
5151
*
5252
* @return void
5353
*/
5454
public static function initializeConfigAndRuleset()
5555
{
56-
$standard = __DIR__.'/'.basename(__FILE__, '.php').'.xml';
57-
self::$standard = $standard;
56+
if (self::$standard === '') {
57+
$standard = __DIR__.'/'.basename(__FILE__, '.php').'.xml';
58+
self::$standard = $standard;
5859

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

64-
$repoRootDir = basename(dirname(dirname(dirname(__DIR__))));
65+
$repoRootDir = basename(dirname(dirname(dirname(__DIR__))));
6566

66-
$newPath = $repoRootDir;
67-
if (DIRECTORY_SEPARATOR === '\\') {
68-
$newPath = str_replace('\\', '/', $repoRootDir);
69-
}
67+
$newPath = $repoRootDir;
68+
if (DIRECTORY_SEPARATOR === '\\') {
69+
$newPath = str_replace('\\', '/', $repoRootDir);
70+
}
7071

71-
$adjusted = str_replace('%path_root_dir%', $newPath, $contents);
72+
$adjusted = str_replace('%path_root_dir%', $newPath, $contents);
7273

73-
if (file_put_contents($standard, $adjusted) === false) {
74-
self::markTestSkipped('On the fly ruleset adjustment failed');
75-
}
74+
if (file_put_contents($standard, $adjusted) === false) {
75+
self::markTestSkipped('On the fly ruleset adjustment failed');
76+
}
7677

77-
$config = new ConfigDouble(["--standard=$standard"]);
78-
self::$ruleset = new Ruleset($config);
78+
$config = new ConfigDouble(["--standard=$standard"]);
79+
self::$ruleset = new Ruleset($config);
80+
}//end if
7981

8082
}//end initializeConfigAndRuleset()
8183

@@ -101,7 +103,7 @@ public function resetRuleset()
101103
*/
102104
public function testHasSniffCodes()
103105
{
104-
$this->assertCount(48, self::$ruleset->sniffCodes);
106+
$this->assertCount(49, self::$ruleset->sniffCodes);
105107

106108
}//end testHasSniffCodes()
107109

@@ -318,6 +320,10 @@ public static function dataRegisteredSniffCodes()
318320
'Generic.Metrics.CyclomaticComplexity',
319321
'PHP_CodeSniffer\Standards\Generic\Sniffs\Metrics\CyclomaticComplexitySniff',
320322
],
323+
[
324+
'Squiz.Files.FileExtension',
325+
'PHP_CodeSniffer\Standards\Squiz\Sniffs\Files\FileExtensionSniff',
326+
],
321327
[
322328
'Generic.NamingConventions.CamelCapsFunctionName',
323329
'PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff',
@@ -468,6 +474,10 @@ public static function dataSettingInvalidPropertiesOnStandardsAndCategoriesSilen
468474
'sniffClass' => 'PHP_CodeSniffer\Standards\PSR12\Sniffs\Operators\OperatorSpacingSniff',
469475
'propertyName' => 'setforallincategory',
470476
],
477+
'Set property for all sniffs in included category directory' => [
478+
'sniffClass' => 'PHP_CodeSniffer\Standards\Squiz\Sniffs\Files\FileExtensionSniff',
479+
'propertyName' => 'setforsquizfilessniffs',
480+
],
471481
];
472482

473483
}//end dataSettingInvalidPropertiesOnStandardsAndCategoriesSilentlyFails()

tests/Core/Ruleset/RuleInclusionTest.xml

+9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
</properties>
2828
</rule>
2929

30+
<!-- Sniff directory include. -->
31+
<rule ref="./src/Standards/Squiz/Sniffs/Files/">
32+
<properties>
33+
<property name="setforsquizfilessniffs" value="true" />
34+
</properties>
35+
</rule>
36+
37+
<!-- Sniff file include. -->
3038
<rule ref="./src/Standards/Generic/Sniffs/Files/LineLengthSniff.php">
3139
<properties>
3240
<property name="lineLimit" value="10" />
@@ -39,6 +47,7 @@
3947
</properties>
4048
</rule>
4149

50+
<!-- Ruleset file include. -->
4251
<rule ref="./RuleInclusionTest-include.xml">
4352
<!-- Property being set for all sniffs included in this ruleset. -->
4453
<properties>

0 commit comments

Comments
 (0)