Skip to content

Commit 32c5cd9

Browse files
authored
Merge pull request #753 from PHPCSStandards/feature/ruleset-setsniff-property-edge-case-test-unused-sniff
Ruleset::setSniffProperty(): add test for edge case / unused sniff
2 parents 6273fd9 + 48c5e81 commit 32c5cd9

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/Core/Ruleset/SetSniffPropertyTest.php

+33
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,39 @@ public function testSetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForCateg
202202
}//end testSetPropertyDoesNotThrowErrorOnInvalidPropertyWhenSetForCategory()
203203

204204

205+
/**
206+
* Test that attempting to set a property for a sniff which isn't registered will be ignored.
207+
*
208+
* @return void
209+
*/
210+
public function testDirectCallIgnoredPropertyForUnusedSniff()
211+
{
212+
$sniffCode = 'Generic.Formatting.SpaceAfterCast';
213+
$sniffClass = 'PHP_CodeSniffer\\Standards\\Generic\\Sniffs\\Formatting\\SpaceAfterCastSniff';
214+
215+
// Set up the ruleset.
216+
$config = new ConfigDouble(['--standard=PSR1']);
217+
$ruleset = new Ruleset($config);
218+
219+
$ruleset->setSniffProperty(
220+
$sniffClass,
221+
'ignoreNewlines',
222+
[
223+
'scope' => 'sniff',
224+
'value' => true,
225+
]
226+
);
227+
228+
// Verify that there are sniffs registered.
229+
$this->assertGreaterThan(0, count($ruleset->sniffCodes), 'No sniff codes registered');
230+
231+
// Verify that our target sniff has NOT been registered after attempting to set the property.
232+
$this->assertArrayNotHasKey($sniffCode, $ruleset->sniffCodes, 'Unused sniff was registered in sniffCodes, but shouldn\'t have been');
233+
$this->assertArrayNotHasKey($sniffClass, $ruleset->sniffs, 'Unused sniff was registered in sniffs, but shouldn\'t have been');
234+
235+
}//end testDirectCallIgnoredPropertyForUnusedSniff()
236+
237+
205238
/**
206239
* Test that setting a property via a direct call to the Ruleset::setSniffProperty() method
207240
* sets the property correctly when using the new $settings array format.

0 commit comments

Comments
 (0)