Skip to content
This repository was archived by the owner on Feb 20, 2023. It is now read-only.

Can I please have Invocation::setParameters() #390

Closed
malkusch opened this issue Dec 2, 2017 · 5 comments
Closed

Can I please have Invocation::setParameters() #390

malkusch opened this issue Dec 2, 2017 · 5 comments

Comments

@malkusch
Copy link
Contributor

malkusch commented Dec 2, 2017

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.

@sebastianbergmann
Copy link
Owner

Can you elaborate why what you need is no longer possible?

@malkusch
Copy link
Contributor Author

malkusch commented Dec 2, 2017

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.

malkusch referenced this issue in php-mock/php-mock-phpunit Dec 7, 2017
PHPUnit-6.5 did change the signature of TestCase::getMockBuilder() by
returning an object from phpunit-mock-object-5 instead of
phpunit-mock-object-4. This broke this library:

  PHP Fatal error: Interface 'PHPUnit_Framework_MockObject_Matcher_Invocation'
  not found in /.../vendor/php-mock/php-mock-phpunit/classes/DefaultArgumentRemover.php
  on line 15

This commit adds a <phpunit-6.5 constraint to fix the current release.
PHPUnit-6.5 is currently not supported by this library. I wait for
sebastianbergmann/phpunit#2893 to decide how to support PHPUnit-6.5.

See also: #21
See also: sebastianbergmann/phpunit#2893
@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Dec 7, 2017

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?

@sebastianbergmann
Copy link
Owner

@malkusch Do you have any feedback for me?

@sebastianbergmann
Copy link
Owner

No feedback, closing.

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

No branches or pull requests

2 participants