Skip to content

Commit 0ad4363

Browse files
committed
make assertValidValue private as it's not valuable to extend the API. One can programatically call isValid() returning bool or just create a new instance with from() throwing exception
1 parent 8d8c6ec commit 0ad4363

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

src/Enum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public static function isValid($value)
198198
* @psalm-pure
199199
* @psalm-assert T $value
200200
*/
201-
public static function assertValidValue($value): void
201+
private static function assertValidValue($value): void
202202
{
203203
if (!static::isValid($value)) {
204204
throw new \UnexpectedValueException("Value '$value' is not part of the enum " . static::class);

tests/EnumTest.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ public function testFailToCreateEnumWithInvalidValueThroughNamedConstructor($val
6060
EnumFixture::from($value);
6161
}
6262

63+
public function testFailToCreateEnumWithEnumItselfThroughNamedConstructor(): void
64+
{
65+
$this->expectException(\UnexpectedValueException::class);
66+
$this->expectExceptionMessage("Value 'foo' is not part of the enum " . EnumFixture::class);
67+
68+
EnumFixture::from(EnumFixture::FOO());
69+
}
70+
6371
/**
6472
* Contains values not existing in EnumFixture
6573
* @return array
@@ -344,19 +352,4 @@ public function testEnumValuesInheritance()
344352
$inheritedEnumFixture = InheritedEnumFixture::VALUE();
345353
new EnumFixture($inheritedEnumFixture);
346354
}
347-
348-
/**
349-
* @dataProvider isValidProvider
350-
*/
351-
public function testAssertValidValue($value, $isValid): void
352-
{
353-
if (!$isValid) {
354-
$this->expectException(\UnexpectedValueException::class);
355-
$this->expectExceptionMessage("Value '$value' is not part of the enum " . EnumFixture::class);
356-
}
357-
358-
EnumFixture::assertValidValue($value);
359-
360-
self::assertTrue(EnumFixture::isValid($value));
361-
}
362355
}

0 commit comments

Comments
 (0)