website/errors/phpunit.dataProviderStatic.md
This error is reported by phpstan/phpstan-phpunit.
<?php declare(strict_types = 1);
use PHPUnit\Framework\Attributes\DataProvider;
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'];
}
}
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.
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'];
}
}