|
|
@@ -1771,6 +1771,19 @@ class CollectionTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Tests the chunk method with preserved keys
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testChunkPreserveKeys()
|
|
|
+ {
|
|
|
+ $collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7]);
|
|
|
+ $chunked = $collection->chunk(2, true)->toList();
|
|
|
+ $expected = [['a' => 1, 'b' => 2], ['c' => 3, 'd' => 4], ['e' => 5, 'f' => 6], ['g' => 7]];
|
|
|
+ $this->assertEquals($expected, $chunked);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Tests cartesianProduct
|
|
|
*
|
|
|
* @return void
|
|
|
@@ -1961,4 +1974,17 @@ class CollectionTest extends TestCase
|
|
|
|
|
|
$collection->transpose();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Tests the chunk method with preserved keys
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testChunkPreserveKeys()
|
|
|
+ {
|
|
|
+ $collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7]);
|
|
|
+ $chunked = $collection->chunk(2, true)->toList();
|
|
|
+ $expected = [['a' => 1, 'b' => 2], ['c' => 3, 'd' => 4], ['e' => 5, 'f' => 6], ['g' => 7]];
|
|
|
+ $this->assertEquals($expected, $chunked);
|
|
|
+ }
|
|
|
}
|