Skip to content

Commit

Permalink
Merge pull request #753 from PHPCSStandards/feature/ruleset-setsniff-…
Browse files Browse the repository at this point in the history
…property-edge-case-test-unused-sniff

Ruleset::setSniffProperty(): add test for edge case / unused sniff
  • Loading branch information
jrfnl authored Dec 7, 2024
2 parents 6273fd9 + 48c5e81 commit 32c5cd9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/Core/Ruleset/SetSniffPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,39 @@ public function testSetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForCateg
}//end testSetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForCategory()


/**
* Test that attempting to set a property for a sniff which isn't registered will be ignored.
*
* @return void
*/
public function testDirectCallIgnoredPropertyForUnusedSniff()
{
$sniffCode = 'Generic.Formatting.SpaceAfterCast';
$sniffClass = 'PHP_CodeSniffer\\Standards\\Generic\\Sniffs\\Formatting\\SpaceAfterCastSniff';

// Set up the ruleset.
$config = new ConfigDouble(['--standard=PSR1']);
$ruleset = new Ruleset($config);

$ruleset->setSniffProperty(
$sniffClass,
'ignoreNewlines',
[
'scope' => 'sniff',
'value' => true,
]
);

// Verify that there are sniffs registered.
$this->assertGreaterThan(0, count($ruleset->sniffCodes), 'No sniff codes registered');

// Verify that our target sniff has NOT been registered after attempting to set the property.
$this->assertArrayNotHasKey($sniffCode, $ruleset->sniffCodes, 'Unused sniff was registered in sniffCodes, but shouldn\'t have been');
$this->assertArrayNotHasKey($sniffClass, $ruleset->sniffs, 'Unused sniff was registered in sniffs, but shouldn\'t have been');

}//end testDirectCallIgnoredPropertyForUnusedSniff()


/**
* Test that setting a property via a direct call to the Ruleset::setSniffProperty() method
* sets the property correctly when using the new $settings array format.
Expand Down

0 comments on commit 32c5cd9

Please sign in to comment.