Skip to content

Commit

Permalink
Merge pull request #78 from KartaviK/feature/nullable
Browse files Browse the repository at this point in the history
Set opportunity to create enum statically with null value
  • Loading branch information
mnapoli authored Oct 27, 2018
2 parents c35dc89 + f8c4a11 commit a8284c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public static function search($value)
public static function __callStatic($name, $arguments)
{
$array = static::toArray();
if (isset($array[$name])) {
if (isset($array[$name]) || \array_key_exists($name, $array)) {
return new static($array[$name]);
}

Expand Down
13 changes: 13 additions & 0 deletions tests/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,17 @@ public function testJsonSerialize()
$this->assertJsonStringEqualsJsonString('""', json_encode(new EnumFixture(EnumFixture::PROBLEMATIC_EMPTY_STRING)));
$this->assertJsonStringEqualsJsonString('false', json_encode(new EnumFixture(EnumFixture::PROBLEMATIC_BOOLEAN_FALSE)));
}

public function testNullableEnum()
{
$this->assertNull(EnumFixture::PROBLEMATIC_NULL()->getValue());
$this->assertNull((new EnumFixture(EnumFixture::PROBLEMATIC_NULL))->getValue());
$this->assertNull((new EnumFixture(EnumFixture::PROBLEMATIC_NULL))->jsonSerialize());
}

public function testBooleanEnum()
{
$this->assertFalse(EnumFixture::PROBLEMATIC_BOOLEAN_FALSE()->getValue());
$this->assertFalse((new EnumFixture(EnumFixture::PROBLEMATIC_BOOLEAN_FALSE))->jsonSerialize());
}
}

0 comments on commit a8284c7

Please sign in to comment.