Sokil\Mongo\PaginatorTest::testPaginatorIteratorInterface PHP Method

testPaginatorIteratorInterface() public method

    public function testPaginatorIteratorInterface()
    {
        $d11 = $this->collection->createDocument(array('param1' => 1, 'param2' => 1))->save();
        $d12 = $this->collection->createDocument(array('param1' => 1, 'param2' => 2))->save();
        $d21 = $this->collection->createDocument(array('param1' => 2, 'param2' => 1))->save();
        $d22 = $this->collection->createDocument(array('param1' => 2, 'param2' => 2))->save();
        $pager = $this->collection->find()->paginate(20, 2);
        $this->assertEquals($d21->getId(), $pager->current()->getId());
        $this->assertEquals((string) $d21->getId(), $pager->key());
        $this->assertTrue($pager->valid());
        $pager->next();
        $this->assertEquals($d22->getId(), $pager->current()->getId());
        $this->assertEquals((string) $d22->getId(), $pager->key());
        $this->assertTrue($pager->valid());
        $pager->next();
        $this->assertFalse($pager->valid());
        $pager->rewind();
        $this->assertEquals($d21->getId(), $pager->current()->getId());
        $this->assertEquals((string) $d21->getId(), $pager->key());
    }