PHPUnit-Polyfills
PHPUnit-Polyfills copied to clipboard
PHPUnit\Framework\MockObject\MockBuilder::onlyMethods is not polyfilled
As per https://github.com/sebastianbergmann/phpunit/pull/3687, the PHPUnit\Framework\MockObject\MockBuilder::setMethods() method was deprecated (soft in PHPUnit 8, hard in PHPUnit 9) and scheduled for removal in PHPUnit 10. It was being replaced by onlyMethods() and addMethods().
In my WordPress plugin codebase, I'm using PHPUnit from 7-9, but whereas various assertions from PHPUnit 9 are polyfilled, the onlyMethods method is not (I'm not using addMethods()).
See https://github.com/Parsely/wp-parsely/runs/3754851373?check_suite_focus=true for a CI run that failed on PHP 7.1 when the test code used onlyMethods(). PHP 7.2 (PHPUnit 8) and above passed fine.
Can these new methods please be polyfilled for earlier versions of PHPUnit?
@GaryJones I'll have a think about this, but polyfilling anything for MockBuilder would not be as straight forward as polyfilling assertions/expectations/constraint, where each of the polyfills can be used as a trait as all test classes have to extend from the PHPUnit native TestCase anyway (or for convenience via the provided TestCases).
The only way I can currently imagine doing that would be by providing a MockBuilder class in this library, which would mean that the class would have to be switched out in any test suite which would want to use the Polyfilled methods. Not sure I want to go down that road.
But as I say, I'll have a think about it.