= 11, * which rejects non-static data providers. */ class DataProviderCompatibilityTest extends TestCase { /** * @return iterable */ public static function provideTestCaseClasses(): iterable { yield [IntegrationTestCase::class]; yield [NodeTestCase::class]; } /** * @dataProvider provideTestCaseClasses * * @param class-string $class */ #[DataProvider('provideTestCaseClasses')] public function testDataProviderAttributesReferenceStaticMethods(string $class): void { // Read attribute metadata via reflection without instantiating the attribute, // so the check also runs under PHPUnit < 10 where the attribute class is absent. $found = false; foreach ((new \ReflectionClass($class))->getMethods() as $method) { foreach ($method->getAttributes(DataProvider::class) as $attribute) { $found = true; $provider = $attribute->getArguments()[0]; $r = new \ReflectionMethod($class, $provider); $this->assertTrue($r->isStatic(), \sprintf('Data provider "%s::%s()" referenced by "%s()" must be static for PHPUnit >= 11.', $class, $provider, $method->getName())); $this->assertSame(0, $r->getNumberOfRequiredParameters(), \sprintf('Data provider "%s::%s()" must not require arguments.', $class, $provider)); } } $this->assertTrue($found, \sprintf('"%s" should declare at least one "#[DataProvider]" attribute.', $class)); } }