Browse Source

Merge branch 'fix-cursor-types'

* fix-cursor-types:
  Throw appropriate exception in authenticate()
  Fix type conversion in MongoCursor
Andreas Braun 10 years ago
parent
commit
2019f3220d

+ 15 - 2
README.md

@@ -52,6 +52,9 @@ root:
  method is not yet implemented.
  method is not yet implemented.
 
 
 ## MongoDB
 ## MongoDB
+ - The [MongoDB::authenticate](https://secure.php.net/manual/de/mongodb.authenticate.php)
+ method is not supported. To connect to a database with authentication, please
+ supply the credentials using the connection string.
  - The `includeSystemCollections` parameter used in the [MongoDB::getCollectionInfo](https://php.net/manual/de/mongodb.getcollectioninfo.php]),
  - The `includeSystemCollections` parameter used in the [MongoDB::getCollectionInfo](https://php.net/manual/de/mongodb.getcollectioninfo.php]),
  [MongoDB::getCollectionNames](https://php.net/manual/de/mongodb.getcollectionnames.php]),
  [MongoDB::getCollectionNames](https://php.net/manual/de/mongodb.getcollectionnames.php]),
  and [MongoDB::listCollections](https://php.net/manual/de/mongodb.listcollections.php)
  and [MongoDB::listCollections](https://php.net/manual/de/mongodb.listcollections.php)
@@ -59,8 +62,6 @@ root:
  collections.
  collections.
  - The [MongoDB::repair](https://secure.php.net/manual/de/mongodb.repair.php)
  - The [MongoDB::repair](https://secure.php.net/manual/de/mongodb.repair.php)
  method is not yet implemented.
  method is not yet implemented.
- - The [MongoDB::authenticate](https://secure.php.net/manual/de/mongodb.authenticate.php)
- method is not yet implemented.
 
 
 ## MongoCollection
 ## MongoCollection
 
 
@@ -68,6 +69,18 @@ root:
  method does not yet return the same result as the original method. Instead, it
  method does not yet return the same result as the original method. Instead, it
  always returns the name of the index created.
  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
 ## Types
 
 
  - Return values containing objects of the [MongoDB\BSON\Javascript](https://secure.php.net/manual/de/class.mongodb-bson-javascript.php)
  - 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\AbstractCursor;
+use Alcaeus\MongoDbAdapter\TypeConverter;
 use MongoDB\Driver\Cursor;
 use MongoDB\Driver\Cursor;
 use MongoDB\Driver\ReadPreference;
 use MongoDB\Driver\ReadPreference;
 use MongoDB\Operation\Find;
 use MongoDB\Operation\Find;
@@ -140,7 +141,7 @@ class MongoCursor extends AbstractCursor implements Iterator
 
 
         $options = $this->getOptions($optionNames) + $this->options;
         $options = $this->getOptions($optionNames) + $this->options;
 
 
-        $count = $this->collection->count($this->query, $options);
+        $count = $this->collection->count(TypeConverter::fromLegacy($this->query), $options);
         return $count;
         return $count;
     }
     }
 
 
@@ -154,7 +155,7 @@ class MongoCursor extends AbstractCursor implements Iterator
     {
     {
         $options = $this->getOptions() + $this->options;
         $options = $this->getOptions() + $this->options;
 
 
-        $this->cursor = $this->collection->find($this->query, $options);
+        $this->cursor = $this->collection->find(TypeConverter::fromLegacy($this->query), $options);
     }
     }
 
 
     /**
     /**

+ 3 - 1
lib/Mongo/MongoDB.php

@@ -426,10 +426,12 @@ class MongoDB
      * @param string $username The username.
      * @param string $username The username.
      * @param string $password The password (in plaintext).
      * @param string $password The password (in plaintext).
      * @return array Returns database response. If the login was successful, it will return 1.
      * @return array Returns database response. If the login was successful, it will return 1.
+     *
+     * @deprecated This method is not implemented, supply authentication credentials through the connection string instead.
      */
      */
     public function authenticate($username, $password)
     public function authenticate($username, $password)
     {
     {
-        $this->notImplemented();
+        throw new \Exception('The MongoDB::authenticate method is not supported. Please supply authentication credentials through the connection string');
     }
     }
 
 
     /**
     /**

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

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