Skip to content

Commit

Permalink
Return a new collection instance instead of the current one.
Browse files Browse the repository at this point in the history
  • Loading branch information
jstoone committed Nov 1, 2016
1 parent 8ce29ca commit a9e381a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ public function split($numberOfGroups)
public function chunk($size)
{
if ($size == 0) {
return $this;
return new static;
}

$chunks = [];
Expand Down
8 changes: 5 additions & 3 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,10 +684,12 @@ public function testChunk()

public function testChunkWhenGivenZeroAsSize()
{
$data = new Collection([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
$chunkedData = $data->chunk(0);
$collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);

$this->assertEquals($data, $chunkedData);
$this->assertEquals(
[],
$collection->chunk(0)->toArray()
);
}

public function testEvery()
Expand Down

0 comments on commit a9e381a

Please sign in to comment.