Browse Source

Add tests for skip() overflow.

I wasn't getting the outofbounds exception locally, and wanted to see
what happened in our CI environments.

Refs #11165
Mark Story 6 years ago
parent
commit
2e8b391598
1 changed files with 14 additions and 0 deletions
  1. 14 0
      tests/TestCase/Collection/CollectionTest.php

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

@@ -2104,10 +2104,24 @@ class CollectionTest extends TestCase
         $collection = new Collection([1, 2, 3, 4, 5]);
         $this->assertEquals([3, 4, 5], $collection->skip(2)->toList());
 
+        $this->assertEquals([1, 2, 3, 4, 5], $collection->skip(0)->toList());
+        $this->assertEquals([4, 5], $collection->skip(3)->toList());
         $this->assertEquals([5], $collection->skip(4)->toList());
     }
 
     /**
+     * Test skip() with an overflow
+     *
+     * @return void
+     */
+    public function testSkipOverflow()
+    {
+        $collection = new Collection([1, 2, 3]);
+        $this->assertEquals([], $collection->skip(3)->toArray());
+        $this->assertEquals([], $collection->skip(4)->toArray());
+    }
+
+    /**
      * Tests the skip() method with a traversable non-iterator
      *
      * @return void