diff --git a/src/Enum.php b/src/Enum.php index 7a105d1..1ee2573 100644 --- a/src/Enum.php +++ b/src/Enum.php @@ -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]); } diff --git a/tests/EnumTest.php b/tests/EnumTest.php index ffb6583..4fd1000 100644 --- a/tests/EnumTest.php +++ b/tests/EnumTest.php @@ -262,4 +262,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()); + } }