Menu

← Back to phpunit.*

Error Identifier: phpunit.dataProviderPublic

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 testFoo(int $value): void
	{
		$this->assertGreaterThan(0, $value);
	}

	private function provideData(): array
	{
		return [[1], [2], [3]];
	}
}

Why is it reported? #

This rule is part of phpstan-phpunit.

A @dataProvider annotation references a method that is not public. PHPUnit requires data provider methods to be public so that the test runner can access them.

How to fix it #

Change the data provider method’s visibility to public:

 <?php declare(strict_types = 1);
 
-	private function provideData(): array
+	public function provideData(): array
 	{
 		return [[1], [2], [3]];
 	}

How to ignore this error #

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

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

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.