Skip to content

Commit

Permalink
Improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
cerbero90 committed Nov 22, 2024
1 parent fa8046c commit e34ade9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Concerns/SelfAware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/BackedEnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/PureEnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit e34ade9

Please sign in to comment.