Menu
Error Identifier: phpunit.dataProviderMethod
Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.
Code example #
<?php declare(strict_types = 1);
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase
{
/**
* @dataProvider provideData
*/
public function testSomething(string $value): void
{
self::assertNotEmpty($value);
}
public static function provideItems(): iterable
{
yield ['foo'];
}
}
Why is it reported? #
The @dataProvider annotation or #[DataProvider] attribute references a method that does not exist on the test class. PHPUnit will fail at runtime when it cannot find the data provider method.
How to fix it #
Ensure the data provider method name matches exactly:
/**
- * @dataProvider provideData
+ * @dataProvider provideItems
*/
public function testSomething(string $value): void
{
self::assertNotEmpty($value);
}
Or create the missing method:
+public static function provideData(): iterable
+{
+ yield ['foo'];
+}
How to ignore this error #
You can use the identifier phpunit.dataProviderMethod to ignore this error using a comment:
// @phpstan-ignore phpunit.dataProviderMethod
codeThatProducesTheError();
You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:
parameters:
ignoreErrors:
-
identifier: phpunit.dataProviderMethod