Permalink
Browse files

added unit tests

  • Loading branch information...
romankonz committed Mar 5, 2013
1 parent e0dc67f commit 3367ce811273fe100c18dd69af88c0119bb388d9
@@ -39,7 +39,7 @@ class DoctrinePaginator implements AdapterInterface
*
* @param Doctrine\ODM\MongoDB\Cursor $cursor
*/
- function __construct(Cursor $cursor)
+ public function __construct(Cursor $cursor)
{
$this->cursor = $cursor;
}
@@ -64,4 +64,16 @@ public function getItems($offset, $itemCountPerPage)
return $cursor;
}
+
+ public function getCursor()
+ {
+ return $this->cursor;
+ }
+
+ public function setCursor(Cursor $cursor)
+ {
+ $this->cursor = $cursor;
+ return $this;
+
+ }
}
@@ -0,0 +1,74 @@
+<?php
+
+namespace DoctrineMongoODMModuleTest\Doctrine;
+
+use DoctrineMongoODMModuleTest\Assets\Document\Simple;
+use DoctrineMongoODMModuleTest\AbstractTest;
+use DoctrineMongoODMModule\Paginator\Adapter\DoctrinePaginator;
+
+class PaginationAdapterTest extends AbstractTest
+{
+ protected $numberOfItems;
+
+
+ protected function getPaginationAdapter()
+ {
+ $documentManager = $this->getDocumentManager();
+ $cursor = $documentManager->getRepository(get_class(new Simple()))->findAll();
+ $cursor->sort(array('Name', 'asc'));
+
+ return new DoctrinePaginator($cursor);
+ }
+
+ public function setup()
+ {
+
+ parent::setup();
+
+ $this->numberOfItems = 20;
+
+ $documentManager = $this->getDocumentManager();
+
+ for ($i = 1; $i <= $this->numberOfItems; $i++) {
+ $document = new Simple();
+ $document->setName("Document $i");
+ $documentManager->persist($document);
+ }
+
+ $documentManager->flush();
+
+ }
+
+ public function testItemCount()
+ {
+ $paginationAdapter = $this->getPaginationAdapter();
+
+ $this->assertEquals($this->numberOfItems, $paginationAdapter->count());
+ }
+
+ public function testGetFiveItemsAtOffsetZero()
+ {
+ $paginationAdapter = $this->getPaginationAdapter();
+
+ $documents = $paginationAdapter->getItems(0, 5);
+
+ for ($i = 1; $i <= 5; $i++) {
+ $documents->next();
+ $this->assertEquals("Document $i", $documents->current()->getName());
+ }
+
+ $this->assertNull($documents->next());
+ }
+
+ public function testGetLastItemAtOffsetNineteen()
+ {
+ $paginationAdapter = $this->getPaginationAdapter();
+
+ $documents = $paginationAdapter->getItems($this->numberOfItems - 1, 5);
+
+ $documents->next();
+ $this->assertEquals('Document ' . $this->numberOfItems, $documents->current()->getName());
+
+ $this->assertNull($documents->next());
+ }
+}

0 comments on commit 3367ce8

Please sign in to comment.