Skip to content

Commit a8284c7

Browse files
authored
Merge pull request #78 from KartaviK/feature/nullable
Set opportunity to create enum statically with null value
2 parents c35dc89 + f8c4a11 commit a8284c7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Enum.php

+1-1
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 (isset($array[$name]) || \array_key_exists($name, $array)) {
181181
return new static($array[$name]);
182182
}
183183

tests/EnumTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,17 @@ public function testJsonSerialize()
266266
$this->assertJsonStringEqualsJsonString('""', json_encode(new EnumFixture(EnumFixture::PROBLEMATIC_EMPTY_STRING)));
267267
$this->assertJsonStringEqualsJsonString('false', json_encode(new EnumFixture(EnumFixture::PROBLEMATIC_BOOLEAN_FALSE)));
268268
}
269+
270+
public function testNullableEnum()
271+
{
272+
$this->assertNull(EnumFixture::PROBLEMATIC_NULL()->getValue());
273+
$this->assertNull((new EnumFixture(EnumFixture::PROBLEMATIC_NULL))->getValue());
274+
$this->assertNull((new EnumFixture(EnumFixture::PROBLEMATIC_NULL))->jsonSerialize());
275+
}
276+
277+
public function testBooleanEnum()
278+
{
279+
$this->assertFalse(EnumFixture::PROBLEMATIC_BOOLEAN_FALSE()->getValue());
280+
$this->assertFalse((new EnumFixture(EnumFixture::PROBLEMATIC_BOOLEAN_FALSE))->jsonSerialize());
281+
}
269282
}

0 commit comments

Comments
 (0)