Detect invalid phpunit `@dataProvider`
Feature request
we should error about dataProvider annotations without a corresponding method
https://phpstan.org/r/9870d218-28c5-4636-88e9-85f73ce78bc9
Did PHPStan help you today? Did it make you happy in any way?
No response
Why doesn't PHPUnit warn / error about this?
it does:
➜ phpstan-phpunit git:(2.0.x) ✗ vendor/bin/phpunit test.php
PHPUnit 9.6.16 by Sebastian Bergmann and contributors.
Warning: No code coverage driver available
E 1 / 1 (100%)
Time: 00:00.002, Memory: 6.00 MB
There was 1 error:
1) Error
The data provider specified for test::testTrim is invalid.
PHPUnit\Util\Exception: Method test::wrongDataProvider() does not exist
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
Also, since PHPUnit 11, it checks if data provider "named arguments" match the param names. And if not, PHPUnit fails hard. So that might also be part of the "invalid dataprovider rule".
class FooTest extends TestCase
{
public static function provideData(): iterable
{
yield [
'receivingKey' => 'foobar', // fails, the param is named $receiving
];
}
#[DataProvider('provideData')]
public function testWhater(string $receiving)
{
// ...
}
}
my initial request is invalid. it already works as expected:
------ -----------------------------------------------------------
Line test.php
------ -----------------------------------------------------------
9 @dataProvider wrongDataProvider related method not found.
🪪 phpunit.dataProviderMethod
------ -----------------------------------------------------------
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.