-
Notifications
You must be signed in to change notification settings - Fork 38
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
feat: make prophesize() static for compatibility with PHPUnit 10 data providers #56
Conversation
I dropped support for PHPUnit 9 because it's not possible to override its existing |
@sebastianbergmann would you accept a patch backporting this change in PHPUnit 9? This would allow keeping support for PHPUnit 9 and 10 in this package (it's currently not possible because |
Are we talking about a single-line change that adds the |
It will probably be a bit more than one line, but that's basically the idea yes: 182527d |
That is a patch for prophecy-phpunit, not for PHPUnit. Just send a pull request for PHPUnit's |
It might not be as easy as I hoped, or even possible, because |
As #56 has been refused (a decision that is totally understandable), this PR is now ready to be merged. To ease the upgrade:
To upgrade from PHPUnit 9 to 10, the process will then be:
@stof if you need help on this, I can do it |
This change is broken. Prophecy does not make a distinction between mocks (which can have expectations to check) or stubs (which cannot have them). Any double created in the data providers would not be properly associated to the Prophet object using during the test run (things could be even worse than that as the static property might make it associated to the first test being run in the class, even though it would not even be associated to that data provider). Making |
We also hit this need in the Drupal community, in our journey to support PHPUnit 10. On top of the need to support a static context, there's also a problem with checking expectations on number of calls on mocks. In https://www.drupal.org/project/drupal/issues/3368713, we are discussing to create a singleton hubbing all the Prophet objects created in dataproviders, and invoking each during the teardown to abide with Prophecy's recommended implementation. Would be good if we could have an 'official' way to do it supported here. |
Checking the number of expected calls requires the double to be associated with the test, and this is the primary reason why this is not supported in data providers. |
@dunglas I don't understand your comment. You are saying that this PR is ready to be merged because some PR has been rejected. But the rejected PR you link to is this one. |
I think he refers to sebastianbergmann/phpunit#5452 |
We started using Prophecy to ease the upgrade to PHPUnit 10 and I now realize it's not compatible with PHPUnit 10, what is the status of this PR? |
This PR is not about compatibility with PHPUnit 10. Prophecy does not make a distinction between mocks and stubs in its API and so should not be used in data providers just like PHPUnit mocks should not be used there (and PHPUnit's |
PHPUnit 10 deprecated non-static data providers, and creating stubs in data providers is common.
To allow using Prophecy in data providers, this patch makes the
prophesize()
method static, as PHPUnit made for its owncreateStub()
method.This also dramatically eases migration to PHPUnit 10 for projects using Prophecy.
Calling
$this->prohesize()
still works because PHP allows calling static methods as if they weren't static.