Can I please have Invocation::setParameters()
malkusch opened this issue · 5 comments
Hi
I have a library which extents phpunit to mock PHP functions. This library has to remove a parameter from an invocation. This could be easily done in phpunit-mock-objects-4, but in v5 there's no public interface for that.
Could I kindly ask to add PHPUnit\Framework\MockObject\Invocation::setParameters(array)? I would happily provide a PR.
Can you elaborate why what you need is no longer possible?
Ok in short I need to remove one argument from the invocation. That's no more possible as there's no public API to do that. In v4 there was the public $parameters field. Now it's private and there's only a getParameters() on the interface. That's the technical explanation.
Now about my use case: That library I'm maintaining is about mocking functions with the PHPUnit API. It was a long way to get this right for every edgne case (references, varargs and optional parameters) and one step on that way was detecting arguments with default values and removing them from the invocation.
I think you should know how hairy this code generation can be from your own PHPUnit\Framework\MockObject\Generator. I see that you rely on Reflection::getDefaultValue(). I can't do that, so I use a marker argument and would simply remove that. I'm not 100% sure why I can't rely on getDefaultValue(). AFAIR it was about builtin functions which don't give that value away with reflection and don't have null as default value.
It was wrong that PHPUnit_Framework_MockObject_Invocation_Static::$parameters and other attributes were public before. This change will not be reverted.
PHPUnit_Framework_MockObject_Invocation_Static (now PHPUnit\Framework\MockObject\Invocation\StaticInvocation) is a private implementation detail of phpunit-mock-objects (which in turn is a private implementation detail of PHPUnit) that should not be manipulated outside the scope of phpunit-mock-objects. This is why I am reluctant to add the mutator method you ask for.
Are you absolutely sure that you cannot achieve what you need without manipulating PHPUnit\Framework\MockObject\Invocation objects?
@malkusch Do you have any feedback for me?
No feedback, closing.