Skip to content
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

The MethodsClassReflectionExtension should restrict the available methods based on the doubled type #368

Open
stof opened this issue Feb 11, 2025 · 1 comment

Comments

@stof
Copy link
Contributor

stof commented Feb 11, 2025

ClassReflection::getActiveTemplateTypeMap allows to access the template type. This would allow restricting hasMethod to the methods available in the doubled type.

Once we know the doubled type, we might also inspect the original method signature in the MethodReflection to define the appropriate signature variants:

  • create a variant where each original argument has a type being the union of the original type (referenced as U), its prophecy type (ProphecyInterface<U&object>) and Prophecy\Argument\Token\TokenInterface
  • create variants removing the last N mandatory arguments (and all optional arguments after them) and changing the type of the last argument to be \Prophecy\Argument\Token\AnyValuesToken, to allow the usage of Argument::cetera()

This would allow phpstan to report cases where your test tries to configure a call with the wrong method name or wrong arguments for it.

@stof
Copy link
Contributor Author

stof commented Feb 11, 2025

To go even further, it would be nice after that to make MethodProphecy generic based on the expected return type to detect bad configuration of willReturn, but this might be harder.

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

No branches or pull requests

1 participant