Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Laravel 5.3.23 changes (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
besologic authored Nov 18, 2016
1 parent cc142c6 commit 0258c13
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Illuminate/Support/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,19 @@ public static function set(&$array, $key, $value)
return $array;
}

/**
* Shuffle the given array and return the result.
*
* @param array $array
* @return array
*/
public static function shuffle($array)
{
shuffle($array);

return $array;
}

/**
* Sort the array using the given callback or "dot" notation.
*
Expand Down
4 changes: 4 additions & 0 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,10 @@ public function split($numberOfGroups)
*/
public function chunk($size)
{
if ($size <= 0) {
return new static;
}

$chunks = [];

foreach (array_chunk($this->items, $size, true) as $chunk) {
Expand Down
37 changes: 37 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,23 @@ public function testSortByString()
$this->assertEquals([['name' => 'dayle'], ['name' => 'taylor']], array_values($data->all()));
}

public function testSortByAlwaysReturnsAssoc()
{
$data = new Collection(['a' => 'taylor', 'b' => 'dayle']);
$data = $data->sortBy(function ($x) {
return $x;
});

$this->assertEquals(['b' => 'dayle', 'a' => 'taylor'], $data->all());

$data = new Collection(['taylor', 'dayle']);
$data = $data->sortBy(function ($x) {
return $x;
});

$this->assertEquals([1 => 'dayle', 0 => 'taylor'], $data->all());
}

public function testReverse()
{
$data = new Collection(['zaeed', 'alan']);
Expand Down Expand Up @@ -665,6 +682,26 @@ public function testChunk()
$this->assertEquals([9 => 10], $data[3]->toArray());
}

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

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

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

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

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

0 comments on commit 0258c13

Please sign in to comment.