Skip to content

Commit

Permalink
Implement MongoCursorInterface in MongoCursor
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Nov 6, 2019
1 parent cd2393e commit 00ee947
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Mongo/MongoCursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* Result object for database query.
* @link http://www.php.net/manual/en/class.mongocursor.php
*/
class MongoCursor extends AbstractCursor implements Iterator, Countable
class MongoCursor extends AbstractCursor implements Iterator, Countable, MongoCursorInterface
{
/**
* @var bool
Expand Down
15 changes: 15 additions & 0 deletions tests/Alcaeus/MongoDbAdapter/Mongo/MongoCursorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Alcaeus\MongoDbAdapter\Tests\TestCase;
use Alcaeus\MongoDbAdapter\TypeConverter;
use Countable;
use MongoCursorInterface;
use MongoDB\Driver\ReadPreference;
use MongoDB\Model\BSONDocument;
use MongoDB\Operation\Find;
Expand Down Expand Up @@ -516,6 +518,19 @@ public function testExplainConvertsQuery()
$this->assertArraySubset($expected, $cursor->explain());
}

public function testInterfaces()
{
$collection = $this->getCollection();
$cursor = $collection->find();

$this->assertInstanceOf(MongoCursorInterface::class, $cursor);

// The countable interface is necessary for compatibility with PHP 7.3+, but not implemented by MongoCursor
if (! extension_loaded('mongo')) {
$this->assertInstanceOf(Countable::class, $cursor);
}
}


/**
* @return \PHPUnit_Framework_MockObject_MockObject
Expand Down

0 comments on commit 00ee947

Please sign in to comment.