Skip to content

Commit cf8b275

Browse files
authored
Allow to push and prepend config values on new keys (#40723)
1 parent 56d433a commit cf8b275

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Illuminate/Config/Repository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function set($key, $value = null)
9999
*/
100100
public function prepend($key, $value)
101101
{
102-
$array = $this->get($key);
102+
$array = $this->get($key, []);
103103

104104
array_unshift($array, $value);
105105

@@ -115,7 +115,7 @@ public function prepend($key, $value)
115115
*/
116116
public function push($key, $value)
117117
{
118-
$array = $this->get($key);
118+
$array = $this->get($key, []);
119119

120120
$array[] = $value;
121121

tests/Config/RepositoryTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@ public function testPush()
143143
$this->assertSame('xxx', $this->repository->get('array.2'));
144144
}
145145

146+
public function testPrependWithNewKey()
147+
{
148+
$this->repository->prepend('new_key', 'xxx');
149+
$this->assertSame(['xxx'], $this->repository->get('new_key'));
150+
}
151+
152+
public function testPushWithNewKey()
153+
{
154+
$this->repository->push('new_key', 'xxx');
155+
$this->assertSame(['xxx'], $this->repository->get('new_key'));
156+
}
157+
146158
public function testAll()
147159
{
148160
$this->assertSame($this->config, $this->repository->all());

0 commit comments

Comments
 (0)