Skip to content
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 support for enums in error message #289

Open
SVillette opened this issue Jul 7, 2023 · 1 comment · May be fixed by #292
Open

Add support for enums in error message #289

SVillette opened this issue Jul 7, 2023 · 1 comment · May be fixed by #292

Comments

@SVillette
Copy link

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.

@downace
Copy link

downace commented Sep 18, 2023

I've encountered similar issue:

Assert::oneOf(BarEnum::A, [BarEnum::B, BarEnum::C]);
// Expected one of: BarEnum, BarEnum. Got: BarEnum

Would be much better:

// Expected one of: BarEnum::B, BarEnum::C. Got: BarEnum::A

@gordinskiy gordinskiy linked a pull request Sep 23, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants