diff --git a/lib/Mongo/MongoCursor.php b/lib/Mongo/MongoCursor.php index 3aacd7f1..7f751d8c 100644 --- a/lib/Mongo/MongoCursor.php +++ b/lib/Mongo/MongoCursor.php @@ -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 diff --git a/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCursorTest.php b/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCursorTest.php index 71657fed..32e2d8a3 100644 --- a/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCursorTest.php +++ b/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCursorTest.php @@ -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; @@ -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