Skip to content

Commit b072dc2

Browse files
committed
re-add the public static method assertValidValue
1 parent 4f2c572 commit b072dc2

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/Enum.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function __construct($value)
6868
$value = $value->getValue();
6969
}
7070

71-
$this->key = static::assertValidValue($value);
71+
$this->key = static::assertValidValueReturningKey($value);
7272

7373
/** @psalm-var T */
7474
$this->value = $value;
@@ -213,7 +213,18 @@ public static function isValid($value)
213213
* @psalm-pure
214214
* @psalm-assert T $value
215215
*/
216-
private static function assertValidValue($value): string
216+
public static function assertValidValue($value): void
217+
{
218+
self::assertValidValueReturningKey($value);
219+
}
220+
221+
/**
222+
* Asserts valid enum value
223+
*
224+
* @psalm-pure
225+
* @psalm-assert T $value
226+
*/
227+
private static function assertValidValueReturningKey($value): string
217228
{
218229
if (false === ($key = static::search($value))) {
219230
throw new \UnexpectedValueException("Value '$value' is not part of the enum " . static::class);

tests/EnumTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -369,4 +369,19 @@ public function testEnumValuesInheritance()
369369
$inheritedEnumFixture = InheritedEnumFixture::VALUE();
370370
new EnumFixture($inheritedEnumFixture);
371371
}
372+
373+
/**
374+
* @dataProvider isValidProvider
375+
*/
376+
public function testAssertValidValue($value, $isValid): void
377+
{
378+
if (!$isValid) {
379+
$this->expectException(\UnexpectedValueException::class);
380+
$this->expectExceptionMessage("Value '$value' is not part of the enum " . EnumFixture::class);
381+
}
382+
383+
EnumFixture::assertValidValue($value);
384+
385+
self::assertTrue(EnumFixture::isValid($value));
386+
}
372387
}

0 commit comments

Comments
 (0)