File tree Expand file tree Collapse file tree
rules-tests/TypeDeclarationDocblocks/Rector/Class_/AddReturnDocblockDataProviderRector/Fixture
rules/TypeDeclarationDocblocks/Rector/Class_ Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \TypeDeclarationDocblocks \Rector \Class_ \AddReturnDocblockDataProviderRector \Fixture ;
4+
5+ use PHPUnit \Framework \Attributes \DataProvider ;
6+ use PHPUnit \Framework \TestCase ;
7+
8+ final class AlreadyReturnTypedGenerator extends TestCase
9+ {
10+ #[DataProvider('provideData ' )]
11+ public function testSomething ()
12+ {
13+ }
14+
15+ public static function provideData (): \Generator
16+ {
17+ yield ['data1 ' , 'data2 ' ];
18+ yield ['item4 ' , 'item5 ' ];
19+ }
20+ }
21+
22+ ?>
23+ -----
24+ <?php
25+
26+ namespace Rector \Tests \TypeDeclarationDocblocks \Rector \Class_ \AddReturnDocblockDataProviderRector \Fixture ;
27+
28+ use PHPUnit \Framework \Attributes \DataProvider ;
29+ use PHPUnit \Framework \TestCase ;
30+
31+ final class AlreadyReturnTypedGenerator extends TestCase
32+ {
33+ #[DataProvider('provideData ' )]
34+ public function testSomething ()
35+ {
36+ }
37+
38+ /**
39+ * @return \Generator<array<int, string>>
40+ */
41+ public static function provideData (): \Generator
42+ {
43+ yield ['data1 ' , 'data2 ' ];
44+ yield ['item4 ' , 'item5 ' ];
45+ }
46+ }
47+
48+ ?>
Original file line number Diff line number Diff line change @@ -154,7 +154,7 @@ public function refactor(Node $node): ?Node
154154 if ($ yields !== []) {
155155 $ yieldType = $ this ->yieldTypeResolver ->resolveFromYieldNodes ($ yields , $ dataProviderClassMethod );
156156
157- if ($ yieldType instanceof FullyQualifiedGenericObjectType && $ yieldType ->getClassName () === 'Generator ' ) {
157+ if ($ yieldType instanceof FullyQualifiedGenericObjectType && $ yieldType ->getClassName () === 'Generator ' && ! $ dataProviderClassMethod -> returnType instanceof Node ) {
158158 // most likely, a static iterator is used in data test fixtures
159159 $ yieldType = new FullyQualifiedGenericObjectType ('Iterator ' , $ yieldType ->getTypes ());
160160 }
You can’t perform that action at this time.
0 commit comments