Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Set opportunity to create enum statically with null value
  • Loading branch information
KartaviK committed Oct 25, 2018
commit 5e044e6635653ab2888551501426ba44385f18d1
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 (array_key_exists($name, $array)) {
return new static($array[$name]);
}

Expand Down
7 changes: 7 additions & 0 deletions tests/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,11 @@ 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());
}
}