Skip to content

Commit 5e044e6

Browse files
committed
Set opportunity to create enum statically with null value
1 parent ca2f409 commit 5e044e6

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Enum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public static function search($value)
177177
public static function __callStatic($name, $arguments)
178178
{
179179
$array = static::toArray();
180-
if (isset($array[$name])) {
180+
if (array_key_exists($name, $array)) {
181181
return new static($array[$name]);
182182
}
183183

tests/EnumTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,11 @@ public function testJsonSerialize()
262262
$this->assertJsonStringEqualsJsonString('""', json_encode(new EnumFixture(EnumFixture::PROBLEMATIC_EMPTY_STRING)));
263263
$this->assertJsonStringEqualsJsonString('false', json_encode(new EnumFixture(EnumFixture::PROBLEMATIC_BOOLEAN_FALSE)));
264264
}
265+
266+
public function testNullableEnum()
267+
{
268+
$this->assertNull(EnumFixture::PROBLEMATIC_NULL()->getValue());
269+
$this->assertNull((new EnumFixture(EnumFixture::PROBLEMATIC_NULL))->getValue());
270+
$this->assertNull((new EnumFixture(EnumFixture::PROBLEMATIC_NULL))->jsonSerialize());
271+
}
265272
}

0 commit comments

Comments
 (0)