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

Unclear error message when MethodNotFound #154

Open
ciaranmcnulty opened this issue Jan 25, 2015 · 9 comments
Open

Unclear error message when MethodNotFound #154

ciaranmcnulty opened this issue Jan 25, 2015 · 9 comments

Comments

@ciaranmcnulty
Copy link
Member

Currently when Prophecy\Exception\Doubler\MethodNotFoundException is thrown the message and exception includes the class of the double, not the interface or class being doubled.

This leads to messages like:

 method `Double\Person\P1::getName()` is not defined.

When it would be clearer for users to have something like:

 method `\Person::getName()` is not defined.
@ciaranmcnulty
Copy link
Member Author

I'm interested in catching and handling this error inside PhpSpec, but don't currently have a way to get the class/interface on which the method should be defined.

@ciaranmcnulty
Copy link
Member Author

Oh and anecdotally, this is something that is difficult for new learners; they find the message hard to interpret.

@everzet
Copy link
Member

everzet commented Jan 25, 2015

Care to PR?

@ciaranmcnulty
Copy link
Member Author

It's on my list but thought I'd report first in case someone could pick it up :-)

@flohw
Copy link

flohw commented Feb 16, 2016

I encounter a similar problem recently. Let me know if I should create another issue.

When I mock a class but make a typo on the full class name (namespace and class name) then call my method to mock on my ObjectProphecy I get the same exception (MethodNotFoundException). I think it should throw another one like ClassNotFoundException before the MethodNotFoundException. The error could be understood more quickly.

@nickedwards
Copy link

nickedwards commented May 18, 2016

@flohw I just had this issue too. Scratching my head for a minute there, and this pointed me in the right direction, so thanks!

I agree that in this instance it should throw something like ClassNotFoundException instead. MethodNotFoundException didn't really make sense in that situation. However, I guess thats a minor issue.

@jon-acker
Copy link
Contributor

This is certainly a head-scratcher for newbies - has anyone picked it up? If not I can give it a go.

@joachim-n
Copy link

I've had a poke around at this but I'm stumped.

At the point where the exception is thrown, we have access to the ObjectProphecy, but AFAICT to get from that the name of the class or interface for the prophecy would require getting them from its $lazyDouble property, which isn't accessible.

Would be useful to get some direction from maintainers on how to get this to work.

My first idea would be to implement __toString() on ObjectProphecy to output a human-friendly string representation of the prophecy for general debugging use.

@stof
Copy link
Member

stof commented Sep 21, 2020

Rather than __toString (which will enable casting to string in any context, which might lead to weird issue), I'd rather add a getter returning the expected class name

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

No branches or pull requests

7 participants