Просмотр исходного кода

Fix type conversion in MongoCursor

Andreas Braun 10 лет назад
Родитель
Сommit
68bb975599
3 измененных файлов с 17 добавлено и 3 удалено
  1. 12 0
      README.md
  2. 3 2
      lib/Mongo/MongoCursor.php
  3. 2 1
      tests/Alcaeus/MongoDbAdapter/MongoCursorTest.php

+ 12 - 0
README.md

@@ -68,6 +68,18 @@ root:
  method does not yet return the same result as the original method. Instead, it
  always returns the name of the index created.
 
+## MongoCursor
+ - The [MongoCursor::explain](https://php.net/manual/de/mongocursor.explain.php)
+ method is not yet implemented.
+ - The [MongoCursor::hasNext](https://php.net/manual/de/mongocursor.hasnext.php)
+ method is not yet implemented.
+ - The [MongoCursor::setFlag](https://php.net/manual/de/mongocursor.setflag.php)
+ method is not yet implemented.
+
+## MongoCommandCursor
+ - The [MongoCommandCursor::createFromDocument](https://php.net/manual/de/mongocommandcursor.createfromdocument.php)
+ method is not yet implemented.
+
 ## Types
 
  - Return values containing objects of the [MongoDB\BSON\Javascript](https://secure.php.net/manual/de/class.mongodb-bson-javascript.php)

+ 3 - 2
lib/Mongo/MongoCursor.php

@@ -14,6 +14,7 @@
  */
 
 use Alcaeus\MongoDbAdapter\AbstractCursor;
+use Alcaeus\MongoDbAdapter\TypeConverter;
 use MongoDB\Driver\Cursor;
 use MongoDB\Driver\ReadPreference;
 use MongoDB\Operation\Find;
@@ -140,7 +141,7 @@ class MongoCursor extends AbstractCursor implements Iterator
 
         $options = $this->getOptions($optionNames) + $this->options;
 
-        $count = $this->collection->count($this->query, $options);
+        $count = $this->collection->count(TypeConverter::fromLegacy($this->query), $options);
         return $count;
     }
 
@@ -154,7 +155,7 @@ class MongoCursor extends AbstractCursor implements Iterator
     {
         $options = $this->getOptions() + $this->options;
 
-        $this->cursor = $this->collection->find($this->query, $options);
+        $this->cursor = $this->collection->find(TypeConverter::fromLegacy($this->query), $options);
     }
 
     /**

+ 2 - 1
tests/Alcaeus/MongoDbAdapter/MongoCursorTest.php

@@ -1,6 +1,7 @@
 <?php
 
 namespace Alcaeus\MongoDbAdapter\Tests;
+use Alcaeus\MongoDbAdapter\TypeConverter;
 use MongoDB\Driver\ReadPreference;
 use MongoDB\Operation\Find;
 
@@ -50,7 +51,7 @@ class MongoCursorTest extends TestCase
         $collectionMock
             ->expects($this->once())
             ->method('find')
-            ->with($this->equalTo($query), $this->callback($checkOptionCallback))
+            ->with($this->equalTo(TypeConverter::fromLegacy($query)), $this->callback($checkOptionCallback))
             ->will($this->returnValue(new \ArrayIterator([])));
 
         $collection = $this->getCollection('test');