@@ -280,142 +280,4 @@ public function testDirectCallWithNewArrayFormatSetsProperty()
280280 }//end testDirectCallWithNewArrayFormatSetsProperty()
281281
282282
283- /**
284- * Test that setting a property via a direct call to the Ruleset::setSniffProperty() method
285- * sets the property correctly when using the old $settings array format.
286- *
287- * Tested by silencing the deprecation notice as otherwise the test would fail on the deprecation notice.
288- *
289- * @param mixed $propertyValue Value for the property to set.
290- *
291- * @dataProvider dataDirectCallWithOldArrayFormatSetsProperty
292- *
293- * @return void
294- */
295- public function testDirectCallWithOldArrayFormatSetsProperty ($ propertyValue )
296- {
297- $ name = 'AllowedAsDeclared ' ;
298- $ sniffCode = "TestStandard.SetProperty. {$ name }" ;
299- $ sniffClass = 'Fixtures\TestStandard\Sniffs\SetProperty \\' .$ name .'Sniff ' ;
300-
301- // Set up the ruleset.
302- $ standard = __DIR__ ."/SetProperty {$ name }Test.xml " ;
303- $ config = new ConfigDouble (["--standard= $ standard " ]);
304- $ ruleset = new Ruleset ($ config );
305-
306- $ propertyName = 'arbitrarystring ' ;
307-
308- @$ ruleset ->setSniffProperty (
309- $ sniffClass ,
310- $ propertyName ,
311- $ propertyValue
312- );
313-
314- // Verify that the sniff has been registered.
315- $ this ->assertGreaterThan (0 , count ($ ruleset ->sniffCodes ), 'No sniff codes registered ' );
316-
317- // Verify that our target sniff has been registered.
318- $ this ->assertArrayHasKey ($ sniffCode , $ ruleset ->sniffCodes , 'Target sniff not registered ' );
319- $ this ->assertSame ($ sniffClass , $ ruleset ->sniffCodes [$ sniffCode ], 'Target sniff not registered with the correct class ' );
320-
321- // Test that the property as declared in the ruleset has been set on the sniff.
322- $ this ->assertArrayHasKey ($ sniffClass , $ ruleset ->sniffs , 'Sniff class not listed in registered sniffs ' );
323-
324- $ sniffObject = $ ruleset ->sniffs [$ sniffClass ];
325- $ this ->assertSame ($ propertyValue , $ sniffObject ->$ propertyName , 'Property value not set to expected value ' );
326-
327- }//end testDirectCallWithOldArrayFormatSetsProperty()
328-
329-
330- /**
331- * Data provider.
332- *
333- * @see self::testDirectCallWithOldArrayFormatSetsProperty()
334- *
335- * @return array<string, array<string, mixed>>
336- */
337- public static function dataDirectCallWithOldArrayFormatSetsProperty ()
338- {
339- return [
340- 'Property value is not an array (boolean) ' => [
341- 'propertyValue ' => false ,
342- ],
343- 'Property value is not an array (string) ' => [
344- 'propertyValue ' => 'a string ' ,
345- ],
346- 'Property value is an empty array ' => [
347- 'propertyValue ' => [],
348- ],
349- 'Property value is an array without keys ' => [
350- 'propertyValue ' => [
351- 'value ' ,
352- false ,
353- ],
354- ],
355- 'Property value is an array without the "scope" or "value" keys ' => [
356- 'propertyValue ' => [
357- 'key1 ' => 'value ' ,
358- 'key2 ' => false ,
359- ],
360- ],
361- 'Property value is an array without the "scope" key ' => [
362- 'propertyValue ' => [
363- 'key1 ' => 'value ' ,
364- 'value ' => true ,
365- ],
366- ],
367- 'Property value is an array without the "value" key ' => [
368- 'propertyValue ' => [
369- 'scope ' => 'value ' ,
370- 'key2 ' => 1234 ,
371- ],
372- ],
373- ];
374-
375- }//end dataDirectCallWithOldArrayFormatSetsProperty()
376-
377-
378- /**
379- * Test that setting a property via a direct call to the Ruleset::setSniffProperty() method
380- * throws a deprecation notice when using the old $settings array format.
381- *
382- * Note: as PHPUnit stops as soon as it sees the deprecation notice, the setting of the property
383- * value is not tested here.
384- *
385- * @return void
386- */
387- public function testDirectCallWithOldArrayFormatThrowsDeprecationNotice ()
388- {
389- $ exceptionClass = 'PHPUnit\Framework\Error\Deprecated ' ;
390- if (class_exists ($ exceptionClass ) === false ) {
391- $ exceptionClass = 'PHPUnit_Framework_Error_Deprecated ' ;
392- }
393-
394- $ exceptionMsg = 'the format of the $settings parameter has changed from (mixed) $value to array( \'scope \' => \'sniff|standard \', \'value \' => $value). Please update your integration code. See PR #3629 for more information. ' ;
395-
396- if (method_exists ($ this , 'expectException ' ) === true ) {
397- $ this ->expectException ($ exceptionClass );
398- $ this ->expectExceptionMessage ($ exceptionMsg );
399- } else {
400- // PHPUnit < 5.2.0.
401- $ this ->setExpectedException ($ exceptionClass , $ exceptionMsg );
402- }
403-
404- $ name = 'AllowedAsDeclared ' ;
405- $ sniffClass = 'Fixtures\TestStandard\Sniffs\SetProperty \\' .$ name .'Sniff ' ;
406-
407- // Set up the ruleset.
408- $ standard = __DIR__ ."/SetProperty {$ name }Test.xml " ;
409- $ config = new ConfigDouble (["--standard= $ standard " ]);
410- $ ruleset = new Ruleset ($ config );
411-
412- $ ruleset ->setSniffProperty (
413- $ sniffClass ,
414- 'arbitrarystring ' ,
415- ['key ' => 'value ' ]
416- );
417-
418- }//end testDirectCallWithOldArrayFormatThrowsDeprecationNotice()
419-
420-
421283}//end class
0 commit comments