Private/protected dataProvider on PHP 8.1 allowed on purpose or not?
ondrejmirtes opened this issue · 4 comments
Q | A |
---|---|
PHPUnit version | 9.5 |
PHP version | 8.1 |
Installation Method | Composer |
Summary
I have a question. The documentation states:
A data provider method must be public and either return an array of arrays or an object that implements the Iterator interface and yields an array for each iteration step.
But on PHP 8.1, private and protected dataProviders work just fine. Is this on purpose, or is it a mistake?
The reason why it works is probably that PHP 8.1 made calling ReflectionMethod::setAccessible
a no-op - all methods can be invoked out of the box.
The reason why I'm asking is because we're trying to codify these rules in a custom PHPStan rule. So I'd like to know, going into the future, are private/protected dataProviders continue working, or is PHPUnit gonna close this loophole?
Thank you.
Probably by mistake. I will look into this. Thanks!
BTW: PHPUnit 10 deprecates non-static methods as data providers. So eventually data providers must be public and static.
Yes, phpstan-phpunit already reports non-static dataProviders if it's installed alongside PHPUnit 10 and phpstan-deprecation-rules 😊
are private/protected dataProviders continue working
No
is PHPUnit gonna close this loophole
Yes
Awesome, thanks!