Browse Source

Adding a test for chunking collections with nested elements.

chunk() should only return top level elements
Jose Lorenzo Rodriguez 10 years ago
parent
commit
b8d74a00c8
1 changed files with 13 additions and 0 deletions
  1. 13 0
      tests/TestCase/Collection/CollectionTest.php

+ 13 - 0
tests/TestCase/Collection/CollectionTest.php

@@ -1553,4 +1553,17 @@ class CollectionTest extends TestCase
         $expected = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11]];
         $this->assertEquals($expected, $chunked);
     }
+
+    /**
+     * Tests the chunk method with non-scalar items
+     *
+     * @return void
+     */
+    public function testChunkNested()
+    {
+        $collection = new Collection([1, 2, 3, [4, 5], 6, [7, [8, 9], 10], 11]);
+        $chunked = $collection->chunk(2)->toList();
+        $expected = [[1, 2], [3, [4, 5]], [6, [7, [8, 9,], 10]], [11]];
+        $this->assertEquals($expected, $chunked);
+    }
 }