website/errors/phpunit.dataProviderClass.md
This error is reported by phpstan/phpstan-phpunit.
<?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);
}
}
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.
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'];
+ }
}