PHPUnit: Data Provider Deprecation Failing CI
PHPUnit 10/11 tightened data providers: provider methods must be public static, and the migration toward attributes (#[DataProvider]) deprecates some doc-comment usages. With deprecations promoted to failures, a previously-passing provider turns CI red.
What this error means
CI fails (or warns and is configured to fail) with messages about a data provider being deprecated, "Data Provider method must be static", or the provider returning an invalid shape. The same test passed on an older PHPUnit.
1) App\Tests\MathTest::testAdd
Data Provider method App\Tests\MathTest::additionCases() is not static.
# PHPUnit 10+: non-static providers are deprecated/disallowedCommon causes
The provider method is not static
PHPUnit 10+ requires data-provider methods to be public static. A non-static provider is deprecated and fails under strict deprecation handling.
Doc-comment @dataProvider is being phased out
Newer PHPUnit prefers the #[DataProvider] attribute; some doc-comment provider patterns are deprecated, surfacing as failures when deprecations fail the build.
How to fix it
Make the provider public static
Declare the provider static and have it return an iterable of argument arrays.
public static function additionCases(): array
{
return [[1, 2, 3], [0, 0, 0]];
}Use the #[DataProvider] attribute
Migrate from the doc-comment to the attribute form supported in PHPUnit 10/11.
use PHPUnit\Framework\Attributes\DataProvider;
#[DataProvider('additionCases')]
public function testAdd(int \$a, int \$b, int \$expected): void {}Verify the provider shape
- Return an array/iterable where each element is the argument list for one case.
- Keep deprecation handling strict so remaining non-static providers surface.
- Run the suite on the target PHPUnit version to catch all provider deprecations.
How to prevent it
- Declare all data providers
public static. - Prefer the #[DataProvider] attribute over doc-comment annotations on PHPUnit 10/11.
- Run the suite on the PHPUnit version CI uses so provider deprecations surface early.