Skip to content
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

[5.5] Pass test value to Collection::when callbacks #22224

Merged
merged 1 commit into from
Nov 27, 2017
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
4 changes: 2 additions & 2 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,9 @@ public function filter(callable $callback = null)
public function when($value, callable $callback, callable $default = null)
{
if ($value) {
return $callback($this);
return $callback($this, $value);
} elseif ($default) {
return $default($this);
return $default($this, $value);
}

return $this;
Expand Down
4 changes: 2 additions & 2 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2306,8 +2306,8 @@ public function testWhen()
{
$collection = new Collection(['michael', 'tom']);

$collection->when(true, function ($collection) {
return $collection->push('adam');
$collection->when('adam', function ($collection, $newName) {
return $collection->push($newName);
});

$this->assertSame(['michael', 'tom', 'adam'], $collection->toArray());
Expand Down