-
Notifications
You must be signed in to change notification settings - Fork 242
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
Problem with promises when cloning doubles #496
Comments
What's the point of cloning a double? |
I guess the SUT does the doubling? |
@ciaranmcnulty if it is as you guess, is pretty much useless to clone the double as the internal one (the SUT one) would be a totally different instance. |
Well, as DateTime is a value object, your example would be much cleaner by not using a double at all, but using an actual DateTime object. The issue you have here is that cloning the double still creates a double linked to the same ObjectProphecy, and so they don't have independent states. |
@ciaranmcnulty Yes, that's the case.
@stof That's true, but I picked
That's happening exactly. Unfortunately deep cloning is not supported by PHP out of the box, so I can't fix it that way. Introducing a factory method could be a workaround. |
@elvetemedve if we were cloning the ObjectProphecy when cloning the method, this might solve some things, but it might introduce other issues. |
I think that cloning the ObjectProphecy (no matter if shallow or deep clone) has no value. |
Looking at it more in details, it seems very hard to implement @ciaranmcnulty should we generate a |
Exactly. So I'm in favor of this
|
When a Double object is cloned, the attached promises won't be cloned. Therefore the two objects are stitched together.
The example below demonstrates the problem.
Actual Output
Expected Output
Environment
Prophecy version: 1.11.1
PHP version: 7.4.9
The text was updated successfully, but these errors were encountered: