55namespace Rector \Tests \Php81 \Rector \Array_ \ArrayToFirstClassCallableRector ;
66
77use Iterator ;
8+ use PhpParser \Node \ArrayItem ;
9+ use PhpParser \Node \Expr \Array_ ;
10+ use PhpParser \Node \Expr \Variable ;
11+ use PhpParser \Node \Scalar \String_ ;
812use PHPUnit \Framework \Attributes \DataProvider ;
13+ use Rector \NodeTypeResolver \Node \AttributeKey ;
14+ use Rector \Php81 \Rector \Array_ \ArrayToFirstClassCallableRector ;
915use Rector \Testing \PHPUnit \AbstractRectorTestCase ;
1016
1117final class ArrayToFirstClassCallableRectorTest extends AbstractRectorTestCase
@@ -21,6 +27,39 @@ public static function provideData(): Iterator
2127 return self ::yieldFilesFromDirectory (__DIR__ . '/Fixture ' );
2228 }
2329
30+ #[DataProvider('provideSkippedArrays ' )]
31+ public function testSkipWithoutScope (Array_ $ array ): void
32+ {
33+ $ rector = $ this ->make (ArrayToFirstClassCallableRector::class);
34+
35+ $ this ->assertNull ($ rector ->refactor ($ array ));
36+ }
37+
38+ /**
39+ * @return Iterator<string, array{Array_}>
40+ */
41+ public static function provideSkippedArrays (): Iterator
42+ {
43+ $ caller = new ArrayItem (new Variable ('this ' ));
44+ $ method = new ArrayItem (new String_ ('run ' ));
45+
46+ yield 'empty array ' => [new Array_ ()];
47+ yield 'one item ' => [new Array_ ([$ caller ])];
48+ yield 'three items ' => [new Array_ ([$ caller , $ method , $ method ])];
49+
50+ foreach ([
51+ AttributeKey::IS_CLASS_CONST_VALUE ,
52+ AttributeKey::IS_DEFAULT_PROPERTY_VALUE ,
53+ AttributeKey::IS_PARAM_DEFAULT ,
54+ AttributeKey::IS_UNPACKED_ARG_VALUE ,
55+ ] as $ attribute ) {
56+ yield $ attribute => [
57+ new Array_ ([$ caller , $ method ], [
58+ $ attribute => true ,
59+ ])];
60+ }
61+ }
62+
2463 public function provideConfigFilePath (): string
2564 {
2665 return __DIR__ . '/config/configured_rule.php ' ;
0 commit comments