Skip to content

Add StandardRulesetsQATest #868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2025
Merged
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
83 changes: 83 additions & 0 deletions tests/Core/Standards/StandardRulesetsQATest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* Tests that pre-defined standards do not throw errors.
*
* @author Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl>
* @copyright 2025 Juliette Reinders Folmer. All rights reserved.
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
*/

namespace PHP_CodeSniffer\Tests\Core\Standards;

use PHP_CodeSniffer\Ruleset;
use PHP_CodeSniffer\Tests\ConfigDouble;
use PHP_CodeSniffer\Tests\Core\Ruleset\AbstractRulesetTestCase;

/**
* Tests that pre-defined standards do not throw errors.
*
* @coversNothing
*/
final class StandardRulesetsQATest extends AbstractRulesetTestCase
{


/**
* QA check: verify that the PHPCS native rulesets do not throw any errors or other messages.
*
* This QA check will prevent issues like:
* - a sniff being removed, but still being referenced from within a PHPCS native ruleset.
* - a supported feature being removed, but still being used from within a PHPCS native ruleset.
*
* @param string $standard The name of the build-in standard to test.
*
* @dataProvider dataBuildInStandards
*
* @return void
*/
public function testBuildInStandardsDoNotContainErrors($standard)
{
ob_start();
$config = new ConfigDouble(["--standard=$standard"]);
$ruleset = new Ruleset($config);

$seenOutput = ob_get_contents();
ob_end_clean();

// Make sure no messages were thrown.
$this->assertSame('', $seenOutput);

// Make sure sniffs were registered.
$this->assertGreaterThanOrEqual(1, count($ruleset->sniffCodes));

}//end testBuildInStandardsDoNotContainErrors()


/**
* Data provider.
*
* @see self::testBuildInStandardsDoNotContainErrors()
*
* @return array<string, array<string, string>>
*/
public static function dataBuildInStandards()
{
// Get a list of all build-in, PHPCS native standards.
$sep = DIRECTORY_SEPARATOR;
$targetDir = dirname(dirname(dirname(__DIR__))).$sep.'src'.$sep.'Standards'.$sep;
$rulesetFiles = glob($targetDir.'*'.$sep.'ruleset.xml');

$data = [];
foreach ($rulesetFiles as $file) {
$standardName = basename(dirname($file));
$data[$standardName] = [
'standard' => $standardName,
];
}

return $data;

}//end dataBuildInStandards()


}//end class