assert
assert copied to clipboard
Add support for enums in error message
Context
In many projects, I use an assertion about an object property value. The error message in not explicit about why the assertion failed. I think it would be a nice feature to handle enum name in the error message.
$foo = new Foo(BarEnum::Bar);
Assert::same($foo->getA(), BarEnum::Baz);
// Uncaught Webmozart\Assert\InvalidArgumentException: Expected a value identical to App\BarEnum. Got: App\BarEnum
Solution
Maybe the error message could look like this: Expected a value identical to App\BarEnum::Baz. Got: App\BarEnum::Bar
.
I think the enum name is the most simple solution to implement as all enum type have a name.
If you agree with the proposed solution, I can opened a PR for this feature request.