Skip to content

Commit d5bfaa5

Browse files
committed
Correctly read database and collection options for operations
1 parent af3ad98 commit d5bfaa5

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

tests/SpecTests/Context.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,13 @@ public function getClient()
268268
return $this->useEncryptedClient && $this->encryptedClient ? $this->encryptedClient : $this->client;
269269
}
270270

271-
public function getCollection(array $collectionOptions = [])
271+
public function getCollection(array $collectionOptions = [], array $databaseOptions = [])
272272
{
273273
return $this->selectCollection(
274274
$this->databaseName,
275275
$this->collectionName,
276-
$this->prepareOptions($collectionOptions)
276+
$collectionOptions,
277+
$databaseOptions
277278
);
278279
}
279280

@@ -399,13 +400,11 @@ public function replaceCommandSessionPlaceholder(stdClass $command)
399400
}
400401
}
401402

402-
public function selectCollection($databaseName, $collectionName, array $collectionOptions = [])
403+
public function selectCollection($databaseName, $collectionName, array $collectionOptions = [], array $databaseOptions = [])
403404
{
404-
return $this->getClient()->selectCollection(
405-
$databaseName,
406-
$collectionName,
407-
$this->prepareOptions($collectionOptions)
408-
);
405+
return $this
406+
->selectDatabase($databaseName, $databaseOptions)
407+
->selectCollection($collectionName, $this->prepareOptions($collectionOptions));
409408
}
410409

411410
public function selectDatabase($databaseName, array $databaseOptions = [])

tests/SpecTests/Operation.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ final class Operation
6161
/** @var string|null */
6262
private $databaseName;
6363

64+
/** @var array */
65+
private $databaseOptions = [];
66+
6467
/** @var string */
6568
private $name;
6669

@@ -191,6 +194,14 @@ public static function fromReadWriteConcern(stdClass $operation)
191194
$o->errorExpectation = ErrorExpectation::fromReadWriteConcern($operation);
192195
$o->resultExpectation = ResultExpectation::fromReadWriteConcern($operation, $o->getResultAssertionType());
193196

197+
if (isset($operation->databaseOptions)) {
198+
$o->databaseOptions = (array) $operation->databaseOptions;
199+
}
200+
201+
if (isset($operation->collectionOptions)) {
202+
$o->collectionOptions = (array) $operation->collectionOptions;
203+
}
204+
194205
return $o;
195206
}
196207

@@ -287,7 +298,7 @@ private function execute(FunctionalTestCase $test, Context $context)
287298

288299
return $this->executeForClient($client, $context);
289300
case self::OBJECT_COLLECTION:
290-
$collection = $context->getCollection($this->collectionOptions);
301+
$collection = $context->getCollection($this->collectionOptions, $this->databaseOptions);
291302

292303
return $this->executeForCollection($collection, $context);
293304
case self::OBJECT_DATABASE:
@@ -299,7 +310,7 @@ private function execute(FunctionalTestCase $test, Context $context)
299310

300311
return $this->executeForGridFSBucket($bucket, $context);
301312
case self::OBJECT_SELECT_COLLECTION:
302-
$collection = $context->selectCollection($this->databaseName, $this->collectionName, $this->collectionOptions);
313+
$collection = $context->selectCollection($this->databaseName, $this->collectionName, $this->collectionOptions, $this->databaseOptions);
303314

304315
return $this->executeForCollection($collection, $context);
305316
case self::OBJECT_SELECT_DATABASE:

0 commit comments

Comments
 (0)