|
|
@@ -1771,54 +1771,54 @@ class CollectionTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Tests the chunks method with exact chunks
|
|
|
+ * Tests the chunkWithKeys method with exact chunks
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function testChunks()
|
|
|
+ public function testChunkWithKeys()
|
|
|
{
|
|
|
- $collection = new Collection(range(1, 10));
|
|
|
- $chunked = $collection->chunks(2)->toList();
|
|
|
- $expected = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]];
|
|
|
+ $collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6]);
|
|
|
+ $chunked = $collection->chunkWithKeys(2)->toList();
|
|
|
+ $expected = [['a' => 1, 'b' => 2], ['c' => 3, 'd' => 4], ['e' => 5, 'f' => 6]];
|
|
|
$this->assertEquals($expected, $chunked);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Tests the chunks method with overflowing chunk size
|
|
|
+ * Tests the chunkWithKeys method with overflowing chunk size
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function testChunksOverflow()
|
|
|
+ public function testChunkWithKeysOverflow()
|
|
|
{
|
|
|
- $collection = new Collection(range(1, 11));
|
|
|
- $chunked = $collection->chunks(2)->toList();
|
|
|
- $expected = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11]];
|
|
|
+ $collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7]);
|
|
|
+ $chunked = $collection->chunkWithKeys(2)->toList();
|
|
|
+ $expected = [['a' => 1, 'b' => 2], ['c' => 3, 'd' => 4], ['e' => 5, 'f' => 6], ['g' => 7]];
|
|
|
$this->assertEquals($expected, $chunked);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Tests the chunks method with non-scalar items
|
|
|
+ * Tests the chunkWithKeys method with non-scalar items
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function testChunksNested()
|
|
|
+ public function testChunkWithKeysNested()
|
|
|
{
|
|
|
- $collection = new Collection([1, 2, 3, [4, 5], 6, [7, [8, 9], 10], 11]);
|
|
|
- $chunked = $collection->chunks(2)->toList();
|
|
|
- $expected = [[1, 2], [3, [4, 5]], [6, [7, [8, 9], 10]], [11]];
|
|
|
+ $collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3, 'd' => [4, 5], 'e' => 6, 'f' => [7, [8, 9], 10], 'g' => 11]);
|
|
|
+ $chunked = $collection->chunkWithKeys(2)->toList();
|
|
|
+ $expected = [['a' => 1, 'b' => 2], ['c' => 3, 'd' => [4, 5]], ['e' => 6, 'f' => [7, [8, 9], 10]], ['g' => 11]];
|
|
|
$this->assertEquals($expected, $chunked);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Tests the chunks method with preserved keys
|
|
|
+ * Tests the chunkWithKeys method without preserving keys
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function testChunksPreserveKeys()
|
|
|
+ public function testChunkWithKeysNoPreserveKeys()
|
|
|
{
|
|
|
$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7]);
|
|
|
- $chunked = $collection->chunks(2, true)->toList();
|
|
|
- $expected = [['a' => 1, 'b' => 2], ['c' => 3, 'd' => 4], ['e' => 5, 'f' => 6], ['g' => 7]];
|
|
|
+ $chunked = $collection->chunkWithKeys(2, false)->toList();
|
|
|
+ $expected = [[0 => 1, 1 => 2], [0 => 3, 1 => 4], [0 => 5, 1 => 6], [0 => 7]];
|
|
|
$this->assertEquals($expected, $chunked);
|
|
|
}
|
|
|
|