Alcaeus\MongoDbAdapter\Tests\Mongo\MongoCursorTest::testIteratorInterface PHP Method

testIteratorInterface() public method

    public function testIteratorInterface()
    {
        $this->prepareData();
        $collection = $this->getCollection();
        $cursor = $collection->find(['foo' => 'bar']);
        $this->assertFalse($cursor->valid(), 'Cursor should be invalid to start with');
        $this->assertNull($cursor->current(), 'Cursor should be invalid to start with');
        $this->assertNull($cursor->key(), 'Cursor should be invalid to start with');
        $cursor->next();
        $this->assertTrue($cursor->valid(), 'Cursor should be valid');
        $item = $cursor->current();
        $this->assertNotNull($item);
        $this->assertInstanceOf('MongoId', $item['_id']);
        $this->assertSame('bar', $item['foo']);
        $cursor->next();
        $item = $cursor->current();
        $this->assertNotNull($item);
        $this->assertInstanceOf('MongoId', $item['_id']);
        $this->assertSame('bar', $item['foo']);
        $cursor->next();
        $this->assertNull($cursor->current(), 'Cursor should return null at the end');
        $this->assertFalse($cursor->valid(), 'Cursor should be invalid');
        $cursor->rewind();
        $item = $cursor->current();
        $this->assertNotNull($item);
        $this->assertInstanceOf('MongoId', $item['_id']);
        $this->assertSame('bar', $item['foo']);
    }