Skip to content

PHPLIB-118: Fix compatibility with extension's BSON typemaps #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Operation/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/CreateIndexes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down
4 changes: 2 additions & 2 deletions src/Operation/ListCollections.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/ListDatabases.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down
4 changes: 2 additions & 2 deletions src/Operation/ListIndexes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Collection/CollectionFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public function testFindOne()
'sort' => array('x' => -1),
);

$expected = array('_id' => 3, 'x' => 33);
$expected = (object) array('_id' => 3, 'x' => 33);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for now. I opened PHPLIB-113 to track creation of a typeMap option for findOne().


$this->assertSame($expected, $this->collection->findOne($filter, $options));
$this->assertEquals($expected, $this->collection->findOne($filter, $options));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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'];
Expand Down