Permalink
Browse files

getItems returns independent mongodb cursors

  • Loading branch information...
1 parent 3367ce8 commit 4b880cbbed12ffbc70627af648bee356d903ec5b @romankonz romankonz committed Mar 6, 2013
@@ -49,8 +49,7 @@ public function __construct(Cursor $cursor)
*/
public function count()
{
- $cursor = clone $this->cursor;
- return $cursor->count();
+ return $this->cursor->count();
}
/**
@@ -59,6 +58,7 @@ public function count()
public function getItems($offset, $itemCountPerPage)
{
$cursor = clone $this->cursor;
+ $cursor->recreate();
$cursor->skip($offset);
$cursor->limit($itemCountPerPage);
return $cursor;
@@ -71,4 +71,22 @@ public function testGetLastItemAtOffsetNineteen()
$this->assertNull($documents->next());
}
+
+ public function testGetItemsCalledTwoTimes()
+ {
+ $paginationAdapter = $this->getPaginationAdapter();
+
+ $items = $paginationAdapter->getItems(0, 5);
+
+ $items2 = $paginationAdapter->getItems(2, 5);
+ $items->next();
+ $items2->next();
+
+ $this->assertNotEquals($items->current()->getName(), $items2->current()->getName());
+ $this->assertEquals('Document 1', $items->current()->getName());
+ $this->assertEquals('Document 3', $items2->current()->getName());
+
+
+ }
+
}

0 comments on commit 4b880cb

Please sign in to comment.