Menu

Error Identifier: phpunit.dataProviderClass

← Back to phpunit.*

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\Attributes\DataProviderExternal;
use PHPUnit\Framework\TestCase;

class FooTest extends TestCase
{
	#[DataProviderExternal(NonExistingClass::class, 'provideData')]
	public function testSomething(string $value): void
	{
		self::assertNotEmpty($value);
	}
}

Why is it reported? #

The #[DataProviderExternal] attribute or @dataProvider annotation 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
 {
-	#[DataProviderExternal(NonExistingClass::class, 'provideData')]
+	#[DataProviderExternal(BarTest::class, 'provideData')]
 	public function testSomething(string $value): void
 	{
 		self::assertNotEmpty($value);
 	}
 }

Or, if the data provider method is in the same class, use #[DataProvider] instead:

+use PHPUnit\Framework\Attributes\DataProvider;

 class FooTest extends TestCase
 {
-	#[DataProviderExternal(NonExistingClass::class, '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
Theme
A
© 2026 PHPStan s.r.o.