-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
setMethods(), setMethodsExcept(), addMethod(), onlyMethods() #3911
Comments
Summary from the both issues.
Originally the issue @DFoxinator wanted to solve was to
Thus two methods
For example we can not mock this kind of class anymore
Previously we could have mock this class like this
But now we can't write a code equivalent to above mock
For this above class
|
@bikalbasnet I am sorry but your first example in #3911 (comment) makes no sense to me. Can you provide an example for the issue that does not use interceptors such as |
@sebastianbergmann Sorry at the moment, I can't think of other cases that does not involve magic methods, but let me simplify the Let's say this our class that we need want to mock
Previously we could mock above class like this
But now we can't write the UTs equivalent to above. I want to do something like this but it's not possible.
because I get error
|
The specific issue we ran into is with a class we're testing that has a client class as a dependency. The client class has a number of real public methods, but then also a lot of public magic methods. For the test to remain as-is, we'd need to mock both real methods and magic methods on the client class. Specifically, this was an issue for us with the AWS SDK. It mixes real public methods and real magic methods, and some of our code calls combinations of both of those in the same test on the same client instance. |
|
Any ideas/example of what that would look like? I'm not sure I understand completely. |
Does not make sense to me anymore, sorry for the noise. |
Here is the example mentioned by @DFoxinator in #3911 (comment): Class S3Client contains 175 magic methods and bunch of real methods from interface S3ClientInterface. Our class uses both magic, and real methods from S3Client what causes us next issues:
rather than to create one mock in
And, of course, a new test is required so that to test wrapper All these issues are resolved if both |
Is there consensus that |
👍 to make it combinable |
@bikalbasnet are you going to update/make a PR for this? |
@DFoxinator I was thinking I could re open my PR 🤔 #3907 |
Whatever works. |
I failed at keeping track of the discussion of this subject as it is currently (or rather was until the creation of this ticket) scattered across #3858, #3886, #3897, and #3907. I have decided to close these issues and pull requests and would kindly ask you to discuss this topic here in this new issue. I apologize for any inconvenience that this may cause. I hope that we come to a conclusion on how to proceed quickly. At that time I will gladly and promptly merge a pull request that implements what is agreed upon here.
In #3687, @DFoxinator implemented
MockBuilder::addMethods()
andMockBuilder::onlyMethods()
as alternatives toMockBuilder::setMethods()
. These new methods were published as part of PHPUnit 8.3.When developers started using
MockBuilder::addMethods()
andMockBuilder::onlyMethods()
with PHPUnit 8.3, they ran into limitations for which the aforementioned separate issues and pull requests were created.Can somebody please summarize these limitations here? Thanks!
The text was updated successfully, but these errors were encountered: