Skip to content

Commit 127f666

Browse files
committed
add more testcase for generic types
1 parent 1c4fbea commit 127f666

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

tests/PHPStan/Rules/Functions/MissingFunctionReturnTypehintRuleTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ public function testRule(): void
6666
'Function MissingFunctionReturnTypehint\returnsGeneratorOfIntegersByStringNoPrototype() return type with generic class Generator does not specify its types: TKey, TValue, TSend, TReturn',
6767
169,
6868
],
69+
[
70+
'Function MissingFunctionReturnTypehint\returnsIteratorNoPrototype() return type with generic interface Iterator does not specify its types: TKey, TValue, TSend, TReturn',
71+
186,
72+
],
73+
[
74+
'Function MissingFunctionReturnTypehint\returnsIteratorAggregateNoPrototype() return type with generic interface IteratorAggregate does not specify its types: TKey, TValue, TSend, TReturn',
75+
199,
76+
],
77+
[
78+
'Function MissingFunctionReturnTypehint\returnsTraversableNoPrototype() return type has no value type specified in iterable type Traversable',
79+
212,
80+
],
81+
[
82+
'Function MissingFunctionReturnTypehint\returnsTraversableNoPrototype() return type with generic interface Traversable does not specify its types: TKey, TValue, TSend, TReturn',
83+
212,
84+
],
6985
]);
7086
}
7187

tests/PHPStan/Rules/Functions/data/missing-function-return-typehint.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,49 @@ function returnsGeneratorOfIntegersByStringNoPrototype(): \Generator
176176
/**
177177
* @return \Generator<string, int>
178178
*/
179-
function returnsGeneratorOfIntegersByStringwithPrototype(): \Generator
179+
function returnsGeneratorOfIntegersByStringWithPrototype(): \Generator
180180
{
181181
yield '1' => 1;
182182
yield '2' => 2;
183183
yield '3' => 3;
184184
}
185+
186+
function returnsIteratorNoPrototype(): \Iterator
187+
{
188+
yield 'test';
189+
}
190+
191+
/**
192+
* @return \Iterator<array-key,string>
193+
*/
194+
function returnsIteratorWithPrototype(): \Iterator
195+
{
196+
yield 'test';
197+
}
198+
199+
function returnsIteratorAggregateNoPrototype(): \IteratorAggregate
200+
{
201+
return new \ArrayObject([]);
202+
}
203+
204+
/**
205+
* @return \IteratorAggregate<array-key,string>
206+
*/
207+
function returnsIteratorAggregateWithPrototype(): \IteratorAggregate
208+
{
209+
return new \ArrayObject([]);
210+
}
211+
212+
function returnsTraversableNoPrototype(): \Traversable
213+
{
214+
yield 'test';
215+
}
216+
217+
/**
218+
* @return \Traversable<array-key,string>
219+
*/
220+
function returnsTraversableWithPrototype(): \Traversable
221+
{
222+
yield 'test';
223+
}
185224
}

0 commit comments

Comments
 (0)