Menu

← Back to phpunit.*

Error Identifier: phpunit.dataProviderClass

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.

This error is reported by phpstan/phpstan-phpunit.

Code example #

<?php declare(strict_types = 1);

use PHPUnit\Framework\TestCase;

class FooTest extends TestCase
{
	/**
	 * @dataProvider NonExistingClass::provideData
	 */
	public function testSomething(string $value): void
	{
		self::assertNotEmpty($value);
	}
}

Why is it reported? #

The @dataProvider annotation or #[DataProvider] attribute references a class that does not exist. PHPStan cannot resolve the class name, so the data provider method cannot be found.

In the example above, NonExistingClass is not a valid class, so the data provider NonExistingClass::provideData cannot be resolved.

How to fix it #

Use a valid, fully-qualified class name in the data provider reference:

 class FooTest extends TestCase
 {
 	/**
-	 * @dataProvider NonExistingClass::provideData
+	 * @dataProvider BarTest::provideData
 	 */
 	public function testSomething(string $value): void
 	{
 		self::assertNotEmpty($value);
 	}
 }

Or, if the data provider method is in the same class, remove the class prefix:

 class FooTest extends TestCase
 {
 	/**
-	 * @dataProvider NonExistingClass::provideData
+	 * @dataProvider provideData
 	 */
 	public function testSomething(string $value): void
 	{
 		self::assertNotEmpty($value);
 	}

 	public static function provideData(): iterable
 	{
 		yield ['value'];
 	}
 }

How to ignore this error #

You can use the identifier phpunit.dataProviderClass to ignore this error using a comment:

// @phpstan-ignore phpunit.dataProviderClass
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.dataProviderClass

Rules that report this error #

  • PHPStan\Rules\PHPUnit\DataProviderDataRule [1] phpstan/phpstan-phpunit
  • PHPStan\Rules\PHPUnit\DataProviderDeclarationRule [1] phpstan/phpstan-phpunit

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.