Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix last item number #98

Closed
wants to merge 3 commits into from

3 participants

@superdweebie
Collaborator

Fix #79

levofski and others added some commits
@levofski levofski Returning array for count, with unit tests
Since the cursor returns the wrong count, we return an array. I have
updated the unit test to work with array return type. There is a new
unit test to test the counts.
086e056
@superdweebie superdweebie Merge branch 'lastItemNumber' into fix-lastItemNumber 6af21b2
@superdweebie superdweebie Tidy up #79 ready for merge 4d2217d
@superdweebie
Collaborator

@Ocramius if you could give this a quick glance before merge, then we can merge #96 and tag 0.8.0

@Ocramius Ocramius commented on the diff
...octrineMongoODMModuleTest/Doctrine/PaginationTest.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace DoctrineMongoODMModuleTest\Doctrine;
+
+use DoctrineMongoODMModule\Paginator\Adapter\DoctrinePaginator;
+use DoctrineMongoODMModuleTest\AbstractTest;
+use DoctrineMongoODMModuleTest\Assets\Document\Simple;
+use Zend\Paginator\Paginator;
+
+/**
+ * @license MIT
+ * @link http://www.doctrine-project.org/
+ * @author Chris Levy <chrisianlevy@yahoo.co.uk>
@Ocramius Owner

Can you add an @covers annotation here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Ocramius
Owner

@superdweebie looking good!

@Ocramius Ocramius added the bug label
@Ocramius Ocramius added this to the 0.8 milestone
@Ocramius Ocramius self-assigned this
@Ocramius Ocramius added refactoring and removed bug labels
@Ocramius
Owner

Actually, I'll merge manually and push

@Ocramius Ocramius closed this pull request from a commit
@Ocramius Ocramius Merge branch 'fix-lastItemNumber'
Fixes #98 and #79
7d0aa1d
@Ocramius Ocramius closed this in 7d0aa1d
@superdweebie
Collaborator

@Ocramius I was just about to add @covers, and you beat me to to it. Do you want me to merge #96 and tag?

@Ocramius
Owner

Yup, doing that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 10, 2013
  1. @levofski

    Returning array for count, with unit tests

    levofski authored
    Since the cursor returns the wrong count, we return an array. I have
    updated the unit test to work with array return type. There is a new
    unit test to test the counts.
Commits on Feb 21, 2014
  1. @superdweebie
  2. @superdweebie

    Tidy up #79 ready for merge

    superdweebie authored
This page is out of date. Refresh to see the latest.
View
4 src/DoctrineMongoODMModule/Paginator/Adapter/DoctrinePaginator.php
@@ -62,7 +62,7 @@ public function getItems($offset, $itemCountPerPage)
$cursor->recreate();
$cursor->skip($offset);
$cursor->limit($itemCountPerPage);
-
- return $cursor;
+ // Return array version so that counting is correct
+ return $cursor->toArray();
}
}
View
28 tests/DoctrineMongoODMModuleTest/Doctrine/PaginationAdapterTest.php
@@ -51,34 +51,24 @@ public function testItemCount()
$this->assertEquals($this->numberOfItems, $paginationAdapter->count());
}
- public function testGetItemsReturnsACursor()
- {
- $paginationAdapter = $this->getPaginationAdapter();
- $cursor = $paginationAdapter->getItems(0, 1);
-
- $this->assertInstanceOf('Doctrine\ODM\MongoDB\Cursor', $cursor);
- }
-
public function testGetItemsWithFirstFive()
{
$paginationAdapter = $this->getPaginationAdapter();
- $cursor = $paginationAdapter->getItems(0, 5);
- $documents = iterator_to_array($cursor, false);
-
- for ($i = 0; $i < 5; $i++) {
- $this->assertEquals(sprintf('Document %02d', $i + 1), $documents[$i]->getName());
- }
+ $documents = $paginationAdapter->getItems(0, 5);
$this->assertCount(5, $documents);
+ for ($i = 1; $i <= 5; $i++) {
+ $this->assertEquals(sprintf('Document %02d', $i), current($documents)->getName());
+ next($documents);
+ }
}
public function testGetItemsWithLastItem()
{
$paginationAdapter = $this->getPaginationAdapter();
- $cursor = $paginationAdapter->getItems($this->numberOfItems - 1, 5);
- $documents = iterator_to_array($cursor, false);
+ $documents = $paginationAdapter->getItems($this->numberOfItems - 1, 5);
- $this->assertEquals(sprintf('Document %02d', $this->numberOfItems), $documents[0]->getName());
+ $this->assertEquals(sprintf('Document %02d', $this->numberOfItems), current($documents)->getName());
$this->assertCount(1, $documents);
}
@@ -86,8 +76,8 @@ public function testGetItemsCalledTwoTimes()
{
$paginationAdapter = $this->getPaginationAdapter();
- $document1 = current(iterator_to_array($paginationAdapter->getItems(0, 1)));
- $document2 = current(iterator_to_array($paginationAdapter->getItems(1, 1)));
+ $document1 = current($paginationAdapter->getItems(0, 1));
+ $document2 = current($paginationAdapter->getItems(1, 1));
$this->assertEquals('Document 01', $document1->getName());
$this->assertEquals('Document 02', $document2->getName());
View
54 tests/DoctrineMongoODMModuleTest/Doctrine/PaginationTest.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace DoctrineMongoODMModuleTest\Doctrine;
+
+use DoctrineMongoODMModule\Paginator\Adapter\DoctrinePaginator;
+use DoctrineMongoODMModuleTest\AbstractTest;
+use DoctrineMongoODMModuleTest\Assets\Document\Simple;
+use Zend\Paginator\Paginator;
+
+/**
+ * @license MIT
+ * @link http://www.doctrine-project.org/
+ * @author Chris Levy <chrisianlevy@yahoo.co.uk>
@Ocramius Owner

Can you add an @covers annotation here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ */
+class PaginationTest extends AbstractTest
+{
+ protected function getPaginationAdapter()
+ {
+ $documentManager = $this->getDocumentManager();
+
+ $cursor = $documentManager->createQueryBuilder(get_class(new Simple()))->getQuery()->execute();
+ $cursor->sort(array('Name', 'asc'));
+
+ return new DoctrinePaginator($cursor);
+ }
+
+ protected function getPaginator(DoctrinePaginator $adapter)
+ {
+ return new Paginator($adapter);
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $documentManager = $this->getDocumentManager();
+
+ for ($i = 1; $i <= 20; $i++) {
+ $document = new Simple();
+ $document->setName("Document $i");
+ $documentManager->persist($document);
+ }
+ $documentManager->flush();
+ }
+
+ public function testGetFoundItemCount()
+ {
+ $paginationAdapter = $this->getPaginationAdapter();
+ $paginator = $this->getPaginator($paginationAdapter);
+ $pages = $paginator->getPages();
+
+ $this->assertEquals(10, $pages->lastItemNumber);
+ }
+}
Something went wrong with that request. Please try again.