From e34ade94c603d59dc5527c2f6c0ded9f62ed4ac1 Mon Sep 17 00:00:00 2001 From: Andrea Marco Sartori Date: Fri, 22 Nov 2024 17:26:34 +0100 Subject: [PATCH] Improve error message --- src/Concerns/SelfAware.php | 2 +- tests/BackedEnumTest.php | 4 ++-- tests/PureEnumTest.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Concerns/SelfAware.php b/src/Concerns/SelfAware.php index 2527f22..9953132 100644 --- a/src/Concerns/SelfAware.php +++ b/src/Concerns/SelfAware.php @@ -147,7 +147,7 @@ public function resolveMetaAttribute(string $meta): mixed } } - throw new ValueError(sprintf('"%s" is not a valid meta for enum "%s"', $meta, self::class)); + throw new ValueError(sprintf('The case %s::%s has no "%s" meta set', self::class, $this->name, $meta)); } /** diff --git a/tests/BackedEnumTest.php b/tests/BackedEnumTest.php index e880fe8..67e5b17 100644 --- a/tests/BackedEnumTest.php +++ b/tests/BackedEnumTest.php @@ -394,7 +394,7 @@ }); it('handles the call to an inaccessible case method', fn() => BackedEnum::one->unknownMethod()) - ->throws(Error::class, '"unknownMethod" is not a valid meta for enum "Cerbero\Enum\BackedEnum"'); + ->throws(Error::class, 'The case Cerbero\Enum\BackedEnum::one has no "unknownMethod" meta set'); it('runs custom logic when calling an inaccessible case method', function() { Enums::onCall(function(object $case, string $name, array $arguments) { @@ -450,7 +450,7 @@ ->toBe('red'); it('throws a value error when attempting to retrieve an invalid item', fn() => BackedEnum::one->resolveItem('invalid')) - ->throws(ValueError::class, '"invalid" is not a valid meta for enum "Cerbero\Enum\BackedEnum"'); + ->throws(ValueError::class, 'The case Cerbero\Enum\BackedEnum::one has no "invalid" meta set'); it('retrieves the value of a backed case or the name of a pure case', function() { expect(BackedEnum::one->value())->toBe(1); diff --git a/tests/PureEnumTest.php b/tests/PureEnumTest.php index f6b9d9c..0ecd1da 100644 --- a/tests/PureEnumTest.php +++ b/tests/PureEnumTest.php @@ -403,7 +403,7 @@ }); it('handles the call to an inaccessible case method', fn() => PureEnum::one->unknownMethod()) - ->throws(Error::class, '"unknownMethod" is not a valid meta for enum "Cerbero\Enum\PureEnum"'); + ->throws(Error::class, 'The case Cerbero\Enum\PureEnum::one has no "unknownMethod" meta set'); it('runs custom logic when calling an inaccessible case method', function() { Enums::onCall(function(object $case, string $name, array $arguments) { @@ -458,7 +458,7 @@ ->toBe('red'); it('throws a value error when attempting to retrieve an invalid item', fn() => PureEnum::one->resolveItem('invalid')) - ->throws(ValueError::class, '"invalid" is not a valid meta for enum "Cerbero\Enum\PureEnum"'); + ->throws(ValueError::class, 'The case Cerbero\Enum\PureEnum::one has no "invalid" meta set'); it('retrieves the value of a backed case or the name of a pure case', function() { expect(PureEnum::one->value())->toBe('one');