Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPUnit\Framework\MockObject\MockBuilder::onlyMethods is not polyfilled #58

Open
GaryJones opened this issue Sep 30, 2021 · 1 comment

Comments

@GaryJones
Copy link
Contributor

As per sebastianbergmann/phpunit#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?

@jrfnl
Copy link
Collaborator

jrfnl commented Sep 30, 2021

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants