webmozarts / assert

Assertions to validate method input/output with nice error messages.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uninformative message when failing to assert that an object and a string are equal

willemstuursma opened this issue · comments

We have lots of Assert::eq("EUR", $currency); where $currency implements __toString().

The comparison works well, but in case of inequality the error message is really unclear: Expected a value equal to Money\Currency. Got: "EUR"

It would be great \Webmozart\Assert\Assert::valueToString() would check on this.

If you agree, I can provide a PR.

Thank you for this issue. I think it could be a bit tricky but I do understand your use case. I would be happy to review a PR.

Side note about this bit:

We have lots of Assert::eq("EUR", $currency);

They should be Assert::eq($currency, "EUR");

Indeed, the order of arguments (actual, expected) is the reverse of PHPUnit (see #8 for example, and #29 for discussion).