88use PHPStan \Rules \Rule ;
99use PHPStan \Testing \RuleTestCase ;
1010use PHPStan \Type \FileTypeMapper ;
11+ use const PHP_VERSION_ID ;
1112
1213/**
1314 * @extends RuleTestCase<CompositeRule>
@@ -19,21 +20,22 @@ class DataProviderDataRuleTest extends RuleTestCase
1920 protected function getRule (): Rule
2021 {
2122 $ reflectionProvider = $ this ->createReflectionProvider ();
23+ $ phpunitVersion = new PHPUnitVersion ($ this ->phpunitVersion );
2224
2325 /** @var list<Rule<Node>> $rules */
2426 $ rules = [
2527 new DataProviderDataRule (
2628 new TestMethodsHelper (
2729 self ::getContainer ()->getByType (FileTypeMapper::class),
28- new PHPUnitVersion ( $ this -> phpunitVersion )
30+ $ phpunitVersion
2931 ),
3032 new DataProviderHelper (
3133 $ reflectionProvider ,
3234 self ::getContainer ()->getByType (FileTypeMapper::class),
3335 self ::getContainer ()->getService ('defaultAnalysisParser ' ),
34- new PHPUnitVersion ( $ this -> phpunitVersion )
36+ $ phpunitVersion
3537 ),
36-
38+ $ phpunitVersion ,
3739 ),
3840 self ::getContainer ()->getByType (CallMethodsRule::class) /** @phpstan-ignore phpstanApi.classConstant */
3941 ];
@@ -176,30 +178,26 @@ public function testRule(): void
176178 public function testRulePhp8 (): void
177179 {
178180 if (PHP_VERSION_ID < 80000 ) {
179- self ::markTestSkipped ();
181+ self ::markTestSkipped (' PHPUnit11 requires PHP 8.0. ' );
180182 }
181183
182184 $ this ->phpunitVersion = 10 ;
183185
184186 $ this ->analyse ([__DIR__ . '/data/data-provider-data-named.php ' ], [
185187 [
186- 'Parameter $input of method DataProviderDataTestPhp8\NamedArgsInProvider::testFoo() expects string, int given. ' ,
188+ 'Parameter #1 $expectedResult of method DataProviderDataTestPhp8\NamedArgsInProvider::testFoo() expects string, int given. ' ,
187189 44
188190 ],
189191 [
190- 'Parameter $input of method DataProviderDataTestPhp8\NamedArgsInProvider::testFoo() expects string, false given. ' ,
192+ 'Parameter #1 $expectedResult of method DataProviderDataTestPhp8\NamedArgsInProvider::testFoo() expects string, false given. ' ,
191193 44
192194 ],
193195 [
194- 'Unknown parameter $wrong in call to method DataProviderDataTestPhp8\TestWrongOffsetNameArrayShapeIterable::testBar(). ' ,
195- 58
196- ],
197- [
198- 'Missing parameter $si (int) in call to method DataProviderDataTestPhp8\TestWrongOffsetNameArrayShapeIterable::testBar(). ' ,
196+ 'Parameter #1 $si of method DataProviderDataTestPhp8\TestWrongOffsetNameArrayShapeIterable::testBar() expects int, string given. ' ,
199197 58
200198 ],
201199 [
202- 'Parameter $si of method DataProviderDataTestPhp8\TestWrongTypeInArrayShapeIterable::testBar() expects int, string given. ' ,
200+ 'Parameter #1 $si of method DataProviderDataTestPhp8\TestWrongTypeInArrayShapeIterable::testBar() expects int, string given. ' ,
203201 79
204202 ],
205203 ]);
@@ -274,7 +272,36 @@ public function testTrimmingArgs(): void
274272 ]);
275273 }
276274
277- /**
275+ public function testNamedArgumentsInDataProviders (): void
276+ {
277+ $ this ->phpunitVersion = 10 ;
278+
279+ $ this ->analyse ([__DIR__ . '/data/data-provider-named-args.php ' ], [
280+ [
281+ 'Parameter #1 $int of method DataProviderNamedArgs\FooTest::testFoo() expects int, string given. ' ,
282+ 26
283+ ],
284+ [
285+ 'Parameter #2 $string of method DataProviderNamedArgs\FooTest::testFoo() expects string, int given. ' ,
286+ 26
287+ ],
288+ ]);
289+ }
290+
291+ public function testNamedArgumentsInDataProvidersPhpUnit11OrNewer (): void
292+ {
293+ if (PHP_VERSION_ID < 80000 ) {
294+ self ::markTestSkipped ('PHPUnit11 requires PHP 8.0. ' );
295+ }
296+
297+ $ this ->phpunitVersion = 11 ;
298+
299+ $ this ->analyse ([__DIR__ . '/data/data-provider-named-args.php ' ], [
300+ ]);
301+ }
302+
303+
304+ /**
278305 * @return string[]
279306 */
280307 public static function getAdditionalConfigFiles (): array
0 commit comments