Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
added unit tests
- Loading branch information
Roman Konz
committed
Mar 5, 2013
1 parent
e0dc67f
commit 3367ce8
Showing
2 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
tests/DoctrineMongoODMModuleTest/Doctrine/PaginationAdapterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |