浏览代码

Add unit test to capture issue #190 which is fixed in previous commit

Rob Williams 8 年之前
父节点
当前提交
c976c05702
共有 1 个文件被更改,包括 16 次插入0 次删除
  1. 16 0
      tests/Alcaeus/MongoDbAdapter/Mongo/MongoCursorTest.php

+ 16 - 0
tests/Alcaeus/MongoDbAdapter/Mongo/MongoCursorTest.php

@@ -28,6 +28,22 @@ class MongoCursorTest extends TestCase
         $cursor = $collection->find(['foo' => 'bar']);
         $this->assertCount(2, $cursor);
 
+        $this->assertCursorIteration($cursor);
+    }
+
+    public function testCursorHandlesHasNextBeforeIteration()
+    {
+        $this->prepareData();
+
+        $collection = $this->getCollection();
+        $cursor = $collection->find(['foo' => 'bar']);
+        $this->assertTrue($cursor->hasNext());
+
+        $this->assertCursorIteration($cursor);
+    }
+
+    private function assertCursorIteration($cursor)
+    {
         $iterated = 0;
         foreach ($cursor as $key => $item) {
             $this->assertSame($iterated, $cursor->info()['at']);