Skip to content

Commit 57c5713

Browse files
committed
Add StandardRulesetsQATest
This adds a QA test to verify that the build-in rulesets do not throw any errors to prevent a change in the sniffs, which needs an update to a ruleset, from going unnoticed. Ref: * #58 (comment)
1 parent d9522a6 commit 57c5713

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Tests that pre-defined standards do not throw errors.
4+
*
5+
* @author Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl>
6+
* @copyright 2025 Juliette Reinders Folmer. All rights reserved.
7+
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
8+
*/
9+
10+
namespace PHP_CodeSniffer\Tests\Core\Standards;
11+
12+
use PHP_CodeSniffer\Ruleset;
13+
use PHP_CodeSniffer\Tests\ConfigDouble;
14+
use PHP_CodeSniffer\Tests\Core\Ruleset\AbstractRulesetTestCase;
15+
16+
/**
17+
* Tests that pre-defined standards do not throw errors.
18+
*
19+
* @coversNothing
20+
*/
21+
final class StandardRulesetsQATest extends AbstractRulesetTestCase
22+
{
23+
24+
25+
/**
26+
* QA check: verify that the PHPCS native rulesets do not throw any errors or other messages.
27+
*
28+
* This QA check will prevent issues like:
29+
* - a sniff being removed, but still being referenced from within a PHPCS native ruleset.
30+
* - a supported feature being removed, but still being used from within a PHPCS native ruleset.
31+
*
32+
* @param string $standard The name of the build-in standard to test.
33+
*
34+
* @dataProvider dataBuildInStandards
35+
*
36+
* @return void
37+
*/
38+
public function testBuildInStandardsDoNotContainErrors($standard)
39+
{
40+
ob_start();
41+
$config = new ConfigDouble(["--standard=$standard"]);
42+
$ruleset = new Ruleset($config);
43+
44+
$seenOutput = ob_get_contents();
45+
ob_end_clean();
46+
47+
// Make sure no messages were thrown.
48+
$this->assertSame('', $seenOutput);
49+
50+
// Make sure sniffs were registered.
51+
$this->assertGreaterThanOrEqual(1, count($ruleset->sniffCodes));
52+
53+
}//end testBuildInStandardsDoNotContainErrors()
54+
55+
56+
/**
57+
* Data provider.
58+
*
59+
* @see self::testBuildInStandardsDoNotContainErrors()
60+
*
61+
* @return array<string, array<string, string>>
62+
*/
63+
public static function dataBuildInStandards()
64+
{
65+
// Get a list of all build-in, PHPCS native standards.
66+
$sep = DIRECTORY_SEPARATOR;
67+
$targetDir = dirname(dirname(dirname(__DIR__))).$sep.'src'.$sep.'Standards'.$sep;
68+
$rulesetFiles = glob($targetDir.'*'.$sep.'ruleset.xml');
69+
70+
$data = [];
71+
foreach ($rulesetFiles as $file) {
72+
$standardName = basename(dirname($file));
73+
$data[$standardName] = [
74+
'standard' => $standardName,
75+
];
76+
}
77+
78+
return $data;
79+
80+
}//end dataBuildInStandards()
81+
82+
83+
}//end class

0 commit comments

Comments
 (0)