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

Improve Phake::verify error message #144

Closed
huggsboson opened this Issue Jun 6, 2014 · 2 comments

Comments

Projects
None yet
4 participants
@huggsboson
Contributor

huggsboson commented Jun 6, 2014

A very common use case for me, and others I imagine, is to verify that a method was called with some value or array. The naive way of doing this:
Phake::verify($this->mock)->methodFoo(["bar" => "baz"]);

Leads to error messages like:
Failed asserting that Expected Mock->methodFoo(equal to ) to be called exactly <1> times, actually called <0> times.
Other Invocations:
Mock->methodFoo()

For complex objects or arrays it can be very hard to tell what exactly failed. I've been resorting to:
Phake::verify($this->mock)->methodFoo(Phake::catpure($actual));
$this->assertEquals(["bar" => "baz"], $actual);

Which gives me a nice diff around where things didn't match. I don't need the diff, but at least fully printing the actual array in both places would improve things greatly. Any way to improve these error messages? I know Mockito gives a much more descriptive list of things that didn't match.

@bfeaver bfeaver added the Enhancement label Jun 8, 2014

@alexsegura

This comment has been minimized.

Show comment
Hide comment
@alexsegura

alexsegura Sep 11, 2014

👍

It would be nice to use PHPUnit's Differ for this

I've checked but it's not so easy to implement, we need to modify CallExpectation::__toString

alexsegura commented Sep 11, 2014

👍

It would be nice to use PHPUnit's Differ for this

I've checked but it's not so easy to implement, we need to modify CallExpectation::__toString

@mlively mlively modified the milestone: v2.1.0 Feb 23, 2015

mlively added a commit that referenced this issue Apr 7, 2015

Added more descriptive errors when verifications fail. It will now te…
…ll you why each recorded call was marked as a failure.

No more will the fine users of Phake have to resort to argument captures for debugging their verification.

#144
@mlively

This comment has been minimized.

Show comment
Hide comment
@mlively

mlively Apr 7, 2015

Owner

The commit above implements much improved verification messages in the case of failures.

You will now see why each call to the method failed to match your verification including diffs in most cases. For PHPUnit I am just leveraging the built in constraint errors, same for hamcrest. For our built in equality matcher I completely revamped that to use sebastian/comparator instead of my own code.

I would love to get some early feedback before I roll a release with this. You can get it with "phake/phake": "2.1.*@dev"

Owner

mlively commented Apr 7, 2015

The commit above implements much improved verification messages in the case of failures.

You will now see why each call to the method failed to match your verification including diffs in most cases. For PHPUnit I am just leveraging the built in constraint errors, same for hamcrest. For our built in equality matcher I completely revamped that to use sebastian/comparator instead of my own code.

I would love to get some early feedback before I roll a release with this. You can get it with "phake/phake": "2.1.*@dev"

@mlively mlively closed this Apr 7, 2015

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