Open linaori opened 6 years ago
Actually I find this to be really helpful :) but I agree this is very verbose 🤔 maybe the diff could be limited to what actually is different (when the object types match).
PHPUnit assertions are really readable when using PHPStorm because I can open a visual diff 😋 maybe this is an option also.
Part of the problem lies with prophecy itself, e.g. the classname that it reports is the name of the double
rather than the original class: Double\ActionLogProcessorInterface\P4850
<- prophecy could theoretically figure out the name of the original class from this and pass it along with the rest of the error payload. There's an open issue relating to this: https://github.com/phpspec/prophecy/issues/154
The readability, as is with the case with PhpSpec, is down to PHPUnit. The error thrown by Prophecy contains this whole diff that you see above but the test framework (PHPUnit or Spec) can choose what to show from this. I commented a while ago on PhpSpecs repo about this: https://github.com/phpspec/phpspec/issues/1121.
I'm using Prophecy with PHPStorm and experiencing a similar problem with argument assertion. It would be very useful to get assertions diffs with PHPStorm support.
As a workaround, I did the following assertion using PHPUnit method:
$double->someMethod(Argument::that(function ($value) use ($expectedValue) {
$this->assertEquals($expectedValue, $value);
}))
with such approach I'm getting PHPStorm diffs support as well:
@dbalabka your workaround makes it impossible to configure multiple calls on the double though, because your callable does not respect the signature of the argument matcher (you throw an exception when it does not match instead of returning false
)
The hard thing about doing this output are that multiple calls can be allowed (with different kinds of matchers) and that the matchers are an extension point so formatters might not know about them to provide a shorter output.
Whenever an expectation is not matched, the arguments are dumped, but they are dumped with so much information, that the error is nearly unreadable. I love prophecy, but the more I work with this, the more I dislike it because I can't properly see the differences.
Now I'm not sure if the outputting is done by PHPUnit or Prophecy, so if I'm at the wrong place here, I'll reopen this issue in the PHPUnit repo.
Example (Yes, I'm making you scroll down for the rest):
My expectation:
I it took me a good 5 minutes to find out what was wrong here, with lots and lots of scrolling in my Terminal. I do not care for the contents of the arguments, like really, it's nearly useless (at least in this scenario. My matcher is a
type
match and it didn't match, I had the wrong import.I believe it would be a lot more useful for this to display the differences between types:
Maybe it could even show a diff underneath it:
In case of actual argument matching, I'm still not interested in the object contents. Let's say I have 2 different objects of the same type, it should be sufficient to show that the hashes do not match (or if loosely checked, which properties). I can manually debug the values if needed and dump stuff.