Skip to content

Commit

Permalink
Throw invalid argument exception if value below zero is given
Browse files Browse the repository at this point in the history
  • Loading branch information
jstoone committed Nov 1, 2016
1 parent a9e381a commit 5e6de19
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,12 @@ public function split($numberOfGroups)
*/
public function chunk($size)
{
if ($size < 0) {
throw new InvalidArgumentException(
'Size parameter expected to be greater than 0'
);
}

if ($size == 0) {
return new static;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,17 @@ public function testChunkWhenGivenZeroAsSize()
);
}

public function testChunkWhenGivenLessThanZero()
{
$collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);

$this->expectException(InvalidArgumentException::class);
$this->assertEquals(
[],
$collection->chunk(-1)->toArray()
);
}

public function testEvery()
{
$data = new Collection([
Expand Down

0 comments on commit 5e6de19

Please sign in to comment.