Skip to content

[8.x] Test and annotate that Arr::pull() works with int keys #42927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ public static function prepend($array, $value, $key = null)
* Get a value from the array, and remove it.
*
* @param array $array
* @param string $key
* @param string|int $key
* @param mixed $default
* @return mixed
*/
Expand Down
12 changes: 9 additions & 3 deletions tests/Support/SupportArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,19 +620,25 @@ public function testPull()
$array = ['name' => 'Desk', 'price' => 100];
$name = Arr::pull($array, 'name');
$this->assertSame('Desk', $name);
$this->assertEquals(['price' => 100], $array);
$this->assertSame(['price' => 100], $array);

// Only works on first level keys
$array = ['joe@example.com' => 'Joe', 'jane@localhost' => 'Jane'];
$name = Arr::pull($array, 'joe@example.com');
$this->assertSame('Joe', $name);
$this->assertEquals(['jane@localhost' => 'Jane'], $array);
$this->assertSame(['jane@localhost' => 'Jane'], $array);

// Does not work for nested keys
$array = ['emails' => ['joe@example.com' => 'Joe', 'jane@localhost' => 'Jane']];
$name = Arr::pull($array, 'emails.joe@example.com');
$this->assertNull($name);
$this->assertEquals(['emails' => ['joe@example.com' => 'Joe', 'jane@localhost' => 'Jane']], $array);
$this->assertSame(['emails' => ['joe@example.com' => 'Joe', 'jane@localhost' => 'Jane']], $array);

// Works with int keys
$array = ['First', 'Second'];
$first = Arr::pull($array, 0);
$this->assertSame('First', $first);
$this->assertSame([1 => 'Second'], $array);
}

public function testQuery()
Expand Down