-
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
Method with a class argument and default value can't be mocked #568
Comments
I'm trying to debug this issue, and I cannot find any way to replicate the original behavior in the mock. The reflection gives you access only to prophecy/src/Prophecy/Doubler/Generator/ClassCodeGenerator.php Lines 112 to 114 in d4f454f
so this means calling |
Producing a |
I proposed my change in #615
Mh no, you can't still pass null there, you have to explicitly declare it: https://3v4l.org/p2vdM |
@Jean85 the mock class being used in the test won't have the signature used in your code snippet. Your PR produces this code: https://3v4l.org/hNgNI |
Oh right my mistake! Would a manual throw (of a TypeError?) in the method body be an acceptable workaround? |
symfony/var-exporter implemented some magic to export the signature of a We won't be able to reuse their ProxyHelper directly in the code generator due to the layer of abstraction between the Reflection API and the Prophecy class representation (see the ClassMirror), but we might copy this logic as part of a support in our architecture. |
The only effect that the IMO copying that code would be dangerous, is pretty obscure and hard to maintain; being able to use Also, that method is present only since 6.2... It doesn't have dependencies, but it requires PHP 8.1 :( |
Currently, the ClassMirror system is built so that the representation of classes is decoupled from Reflection. Patches could potentially introduce new methods if they want.
This is because PHP Reflection does not provide any dedicated way of accessing this info |
Hi,
since 8.1, PHP supports the usage of the
new
operator in initializers (https://php.watch/rfcs/new_in_initializers).Given this dummy class:
class DummyClass {}
And an interface with a method using a
DummyClass
instance as default argument of a method:And a service using the interface as a dependency:
The following test fails with a fatal PHP error in the
phpspec/prophecy
code:The error message is:
The text was updated successfully, but these errors were encountered: