Skip to content
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
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
Loading