Skip to content

Commit

Permalink
[11.x] Fix handling empty values passed to enum_value() function in…
Browse files Browse the repository at this point in the history
…stead 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 <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

---------

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone authored Oct 16, 2024
1 parent 3eb58f1 commit c31b2f5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Support/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function defer(?callable $callback = null, ?string $name = null, bool $always =
*/
function enum_value($value, $default = null)
{
if (is_string($value) && empty($value)) {
if (empty($value)) {
return $value;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Support/SupportEnumValueFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ public function test_it_can_handle_enum_value($given, $expected)

public static function scalarDataProvider()
{
yield [null, null];
yield [0, 0];
yield ['0', '0'];
yield [false, false];
yield [1, 1];
yield ['1', '1'];
yield [true, true];
yield [[], []];
yield ['', ''];
yield ['laravel', 'laravel'];
yield [true, true];
Expand Down
1 change: 1 addition & 0 deletions tests/Support/SupportJsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function testScalars()
$this->assertSame('true', (string) Js::from(true));
$this->assertSame('1', (string) Js::from(1));
$this->assertSame('1.1', (string) Js::from(1.1));
$this->assertSame('[]', (string) Js::from([]));
$this->assertSame("'Hello world'", (string) Js::from('Hello world'));
$this->assertEquals(
"'\\u003Cdiv class=\\u0022foo\\u0022\\u003E\\u0027quoted html\\u0027\\u003C\\/div\\u003E'",
Expand Down
11 changes: 6 additions & 5 deletions tests/Testing/TestResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,7 @@ public function testAssertJsonWithFluent()

$response->assertJson(function (AssertableJson $json) {
$json->where('0.foo', 'foo 0');
$json->where('0.meta', []);
});
}

Expand Down Expand Up @@ -1541,7 +1542,7 @@ public function testAssertExactJsonStructure()

$this->assertTrue($failed);

$response->assertExactJsonStructure(['*' => ['foo', 'bar', 'foobar']]);
$response->assertExactJsonStructure(['*' => ['foo', 'bar', 'foobar', 'meta']]);
}

public function testAssertJsonCount()
Expand Down Expand Up @@ -2734,10 +2735,10 @@ class JsonSerializableSingleResourceStub implements JsonSerializable
public function jsonSerialize(): array
{
return [
['foo' => 'foo 0', 'bar' => 'bar 0', 'foobar' => 'foobar 0'],
['foo' => 'foo 1', 'bar' => 'bar 1', 'foobar' => 'foobar 1'],
['foo' => 'foo 2', 'bar' => 'bar 2', 'foobar' => 'foobar 2'],
['foo' => 'foo 3', 'bar' => 'bar 3', 'foobar' => 'foobar 3'],
['foo' => 'foo 0', 'bar' => 'bar 0', 'foobar' => 'foobar 0', 'meta' => []],
['foo' => 'foo 1', 'bar' => 'bar 1', 'foobar' => 'foobar 1', 'meta' => null],
['foo' => 'foo 2', 'bar' => 'bar 2', 'foobar' => 'foobar 2', 'meta' => []],
['foo' => 'foo 3', 'bar' => 'bar 3', 'foobar' => 'foobar 3', 'meta' => null],
];
}
}
Expand Down

0 comments on commit c31b2f5

Please sign in to comment.