Menu

← Back to phpunit.*

Error Identifier: phpunit.dataProviderStatic

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 provideData
	 */
	public function testSomething(string $value): void
	{
		self::assertNotEmpty($value);
	}

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

Why is it reported? #

PHPUnit 10 and newer require data provider methods to be static. The referenced data provider method is not declared as static. Non-static data providers are deprecated since PHPUnit 10 and will cause errors in future versions.

How to fix it #

Add the static keyword to the data provider method:

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

-	public function provideData(): iterable
+	public static function provideData(): iterable
 	{
 		yield ['bar'];
 	}
 }

How to ignore this error #

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

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

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.