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
Add dump helper #1221
base: main
Are you sure you want to change the base?
Add dump helper #1221
Conversation
I like the concept, not sure on the implementation/api though. As I understand, it will only work if the $connection
->shouldReceive('update')
->with('arg1', 'arg2')
->once()->andDump(); // probably wouldn't do anything if the expectation was not matched?
There's no doubt this is something Mockery needs, a clear way of determining why your expectation wasn't met and has come up in the past, with things like #1033 and #936. Perhaps, this could be a something to start with and something we ship quickly, with the later view of something much better. Could we think on the naming a little? I'm not against $connection->shouldReceive('update')->thenDumpAndThrow();
$connection->shouldReceive('update')->thenThrowDebugException(); |
Yes, it's somewhat of a "let's see how the chain behaves this far". You might also do
I actually tried doing things like that, but all of my attempts seemed to affect too many parts and seeing that #1000 was reverted I decided to go with the simplest approach so it wouldn't break anything.
Yeah, a short and descriptive name would be nice :) |
This PR proposes a new expectation method to help in debugging expectations. When your expectation doesn't match and you want to understand what was actually called, call
->andDump()
on your expectation like this:The dump method will throw an exception showing the called method, args and the stack trace.
The rest of the chain will have no effect as
andDump()
returns a clone of the expectation. Thus unlike with dumping in anandReturn
or putting a dumping matcher inside thewith()
, this does not require commenting out or modifying your non-matchingwith
and other method calls.