From 7e42c8f1a459c660922ad116498ca8cca2b6c355 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Mon, 27 Jul 2015 15:21:34 +0100 Subject: [PATCH 1/2] Added 'root' to 'array' to the typemaps, as they are now separated in the extensions --- src/Operation/Count.php | 2 +- src/Operation/CreateIndexes.php | 2 +- src/Operation/ListCollections.php | 4 ++-- src/Operation/ListDatabases.php | 2 +- src/Operation/ListIndexes.php | 4 ++-- tests/FunctionalTestCase.php | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Operation/Count.php b/src/Operation/Count.php index c989761cb..fe43eb6de 100644 --- a/src/Operation/Count.php +++ b/src/Operation/Count.php @@ -85,7 +85,7 @@ public function __construct($databaseName, $collectionName, array $filter = arra public function execute(Server $server) { $cursor = $server->executeCommand($this->databaseName, $this->createCommand()); - $cursor->setTypeMap(array('document' => 'array')); + $cursor->setTypeMap(array('root' => 'array', 'document' => 'array')); $result = current($cursor->toArray()); if (empty($result['ok'])) { diff --git a/src/Operation/CreateIndexes.php b/src/Operation/CreateIndexes.php index 9d4b708a4..98237bbd0 100644 --- a/src/Operation/CreateIndexes.php +++ b/src/Operation/CreateIndexes.php @@ -91,7 +91,7 @@ private function executeCommand(Server $server) )); $cursor = $server->executeCommand($this->databaseName, $command); - $cursor->setTypeMap(array('document' => 'array')); + $cursor->setTypeMap(array('root' => 'array', 'document' => 'array')); $result = current($cursor->toArray()); if (empty($result['ok'])) { diff --git a/src/Operation/ListCollections.php b/src/Operation/ListCollections.php index 40a2b3cb6..1aa6fc665 100644 --- a/src/Operation/ListCollections.php +++ b/src/Operation/ListCollections.php @@ -85,7 +85,7 @@ private function executeCommand(Server $server) } $cursor = $server->executeCommand($this->databaseName, new Command($cmd)); - $cursor->setTypeMap(array('document' => 'array')); + $cursor->setTypeMap(array('root' => 'array', 'document' => 'array')); return new CollectionInfoCommandIterator($cursor); } @@ -115,7 +115,7 @@ private function executeLegacy(Server $server) : array(); $cursor = $server->executeQuery($this->databaseName . '.system.namespaces', new Query($filter, $options)); - $cursor->setTypeMap(array('document' => 'array')); + $cursor->setTypeMap(array('root' => 'array', 'document' => 'array')); return new CollectionInfoLegacyIterator($cursor); } diff --git a/src/Operation/ListDatabases.php b/src/Operation/ListDatabases.php index 1f9f200ed..e4189d4ff 100644 --- a/src/Operation/ListDatabases.php +++ b/src/Operation/ListDatabases.php @@ -55,7 +55,7 @@ public function execute(Server $server) } $cursor = $server->executeCommand('admin', new Command($cmd)); - $cursor->setTypeMap(array('document' => 'array')); + $cursor->setTypeMap(array('root' => 'array', 'document' => 'array')); $result = current($cursor->toArray()); if (empty($result['ok'])) { diff --git a/src/Operation/ListIndexes.php b/src/Operation/ListIndexes.php index 1e223a010..e682d2189 100644 --- a/src/Operation/ListIndexes.php +++ b/src/Operation/ListIndexes.php @@ -76,7 +76,7 @@ private function executeCommand(Server $server) } $cursor = $server->executeCommand($this->databaseName, new Command($cmd)); - $cursor->setTypeMap(array('document' => 'array')); + $cursor->setTypeMap(array('root' => 'array', 'document' => 'array')); return new IndexInfoIteratorIterator($cursor); } @@ -97,7 +97,7 @@ private function executeLegacy(Server $server) : array(); $cursor = $server->executeQuery($this->databaseName . '.system.indexes', new Query($filter, $options)); - $cursor->setTypeMap(array('document' => 'array')); + $cursor->setTypeMap(array('root' => 'array', 'document' => 'array')); return new IndexInfoIteratorIterator($cursor); } diff --git a/tests/FunctionalTestCase.php b/tests/FunctionalTestCase.php index 18a897885..3ab948bc2 100644 --- a/tests/FunctionalTestCase.php +++ b/tests/FunctionalTestCase.php @@ -23,7 +23,7 @@ protected function assertCollectionCount($namespace, $count) list($databaseName, $collectionName) = explode('.', $namespace, 2); $cursor = $this->manager->executeCommand($databaseName, new Command(array('count' => $collectionName))); - $cursor->setTypeMap(array('document' => 'array')); + $cursor->setTypeMap(array('root' => 'array', 'document' => 'array')); $document = current($cursor->toArray()); $this->assertArrayHasKey('n', $document); @@ -76,7 +76,7 @@ protected function getServerVersion(ReadPreference $readPreference = null) $readPreference ?: new ReadPreference(ReadPreference::RP_PRIMARY) ); - $cursor->setTypeMap(array('document' => 'array')); + $cursor->setTypeMap(array('root' => 'array', 'document' => 'array')); $document = current($cursor->toArray()); return $document['version']; From c7c86dd39279ab066b686dc28bfa27eabf522fe0 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Mon, 27 Jul 2015 15:22:39 +0100 Subject: [PATCH 2/2] We should be expecting an object, as that's the default type. And we need to use assertEquals as assertSame means it needs to be the same internal object --- tests/Collection/CollectionFunctionalTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Collection/CollectionFunctionalTest.php b/tests/Collection/CollectionFunctionalTest.php index 4e1b5141d..3fe5c20ce 100644 --- a/tests/Collection/CollectionFunctionalTest.php +++ b/tests/Collection/CollectionFunctionalTest.php @@ -29,9 +29,9 @@ public function testFindOne() 'sort' => array('x' => -1), ); - $expected = array('_id' => 3, 'x' => 33); + $expected = (object) array('_id' => 3, 'x' => 33); - $this->assertSame($expected, $this->collection->findOne($filter, $options)); + $this->assertEquals($expected, $this->collection->findOne($filter, $options)); } /**