Skip to content

Commit

Permalink
adjust literal, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 16, 2024
1 parent 637b814 commit 6e9f185
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Illuminate/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,16 @@ function filled($value)

if (! function_exists('literal')) {
/**
* Create a new anonymous object using named arguments.
* Return a new literal or anonymous object using named arguments.
*
* @return \stdClass
*/
function literal(...$arguments)
{
if (count($arguments) === 1 && array_is_list($arguments)) {
return $arguments[0];
}

return (object) $arguments;
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/Support/SupportHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,14 @@ public function testRequiredEnvReturnsValue(): void
$this->assertSame('some-value', Env::getOrFail('required-exists'));
}

public function testLiteral(): void
{
$this->assertEquals(1, literal(1));
$this->assertEquals('taylor', literal('taylor'));
$this->assertEquals((object) ['name' => 'Taylor', 'role' => 'Developer'], literal(name: 'Taylor', role: 'Developer'));

}

public static function providesPregReplaceArrayData()
{
$pointerArray = ['Taylor', 'Otwell'];
Expand Down

0 comments on commit 6e9f185

Please sign in to comment.