Skip to content

Commit c31b2f5

Browse files
authored
[11.x] Fix handling empty values passed to enum_value() function instead of only empty string (#53181)
* [11.x] Handle empty values passed to `enum_value()` function instead of only empty string fixes #53180 Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> --------- Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent 3eb58f1 commit c31b2f5

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

src/Illuminate/Support/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function defer(?callable $callback = null, ?string $name = null, bool $always =
4343
*/
4444
function enum_value($value, $default = null)
4545
{
46-
if (is_string($value) && empty($value)) {
46+
if (empty($value)) {
4747
return $value;
4848
}
4949

tests/Support/SupportEnumValueFunctionTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ public function test_it_can_handle_enum_value($given, $expected)
3030

3131
public static function scalarDataProvider()
3232
{
33+
yield [null, null];
34+
yield [0, 0];
35+
yield ['0', '0'];
36+
yield [false, false];
37+
yield [1, 1];
38+
yield ['1', '1'];
39+
yield [true, true];
40+
yield [[], []];
3341
yield ['', ''];
3442
yield ['laravel', 'laravel'];
3543
yield [true, true];

tests/Support/SupportJsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function testScalars()
1818
$this->assertSame('true', (string) Js::from(true));
1919
$this->assertSame('1', (string) Js::from(1));
2020
$this->assertSame('1.1', (string) Js::from(1.1));
21+
$this->assertSame('[]', (string) Js::from([]));
2122
$this->assertSame("'Hello world'", (string) Js::from('Hello world'));
2223
$this->assertEquals(
2324
"'\\u003Cdiv class=\\u0022foo\\u0022\\u003E\\u0027quoted html\\u0027\\u003C\\/div\\u003E'",

tests/Testing/TestResponseTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,7 @@ public function testAssertJsonWithFluent()
12121212

12131213
$response->assertJson(function (AssertableJson $json) {
12141214
$json->where('0.foo', 'foo 0');
1215+
$json->where('0.meta', []);
12151216
});
12161217
}
12171218

@@ -1541,7 +1542,7 @@ public function testAssertExactJsonStructure()
15411542

15421543
$this->assertTrue($failed);
15431544

1544-
$response->assertExactJsonStructure(['*' => ['foo', 'bar', 'foobar']]);
1545+
$response->assertExactJsonStructure(['*' => ['foo', 'bar', 'foobar', 'meta']]);
15451546
}
15461547

15471548
public function testAssertJsonCount()
@@ -2734,10 +2735,10 @@ class JsonSerializableSingleResourceStub implements JsonSerializable
27342735
public function jsonSerialize(): array
27352736
{
27362737
return [
2737-
['foo' => 'foo 0', 'bar' => 'bar 0', 'foobar' => 'foobar 0'],
2738-
['foo' => 'foo 1', 'bar' => 'bar 1', 'foobar' => 'foobar 1'],
2739-
['foo' => 'foo 2', 'bar' => 'bar 2', 'foobar' => 'foobar 2'],
2740-
['foo' => 'foo 3', 'bar' => 'bar 3', 'foobar' => 'foobar 3'],
2738+
['foo' => 'foo 0', 'bar' => 'bar 0', 'foobar' => 'foobar 0', 'meta' => []],
2739+
['foo' => 'foo 1', 'bar' => 'bar 1', 'foobar' => 'foobar 1', 'meta' => null],
2740+
['foo' => 'foo 2', 'bar' => 'bar 2', 'foobar' => 'foobar 2', 'meta' => []],
2741+
['foo' => 'foo 3', 'bar' => 'bar 3', 'foobar' => 'foobar 3', 'meta' => null],
27412742
];
27422743
}
27432744
}

0 commit comments

Comments
 (0)