Skip to content

Commit

Permalink
make assertValidValue private as it's not valuable to extend the API.…
Browse files Browse the repository at this point in the history
… One can programatically call `isValid()` returning bool or just create a new instance with `from()` throwing exception
  • Loading branch information
drealecs committed Feb 14, 2021
1 parent 8d8c6ec commit bbd35d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static function isValid($value)
* @psalm-pure
* @psalm-assert T $value
*/
public static function assertValidValue($value): void
private static function assertValidValue($value): void
{
if (!static::isValid($value)) {
throw new \UnexpectedValueException("Value '$value' is not part of the enum " . static::class);
Expand Down
22 changes: 8 additions & 14 deletions tests/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ public function testFailToCreateEnumWithInvalidValueThroughNamedConstructor($val
EnumFixture::from($value);
}

public function testFailToCreateEnumWithEnumItselfThroughNamedConstructor(): void
{
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage("Value 'foo' is not part of the enum " . EnumFixture::class);

EnumFixture::from(EnumFixture::FOO());
}

/**
* Contains values not existing in EnumFixture
* @return array
Expand Down Expand Up @@ -345,18 +353,4 @@ public function testEnumValuesInheritance()
new EnumFixture($inheritedEnumFixture);
}

/**
* @dataProvider isValidProvider
*/
public function testAssertValidValue($value, $isValid): void
{
if (!$isValid) {
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage("Value '$value' is not part of the enum " . EnumFixture::class);
}

EnumFixture::assertValidValue($value);

self::assertTrue(EnumFixture::isValid($value));
}
}

0 comments on commit bbd35d0

Please sign in to comment.