Skip to content

Commit adbb3dc

Browse files
committed
Rely on Collection to apply read/write opts for old servers
Server versions < 3.4 do not support write concerns for drop commands. Rather than pass the context's write options directly to drop(), filter them through the Collection class so it can decide to inherit them based on the server's wire version. Likewise for executing find() on the output collection.
1 parent 8f741bf commit adbb3dc

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

tests/SpecTests/Context.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ final class Context
3838
public $defaultWriteOptions = [];
3939

4040
/** @var array */
41-
public $outcomeFindOptions = [];
41+
public $outcomeReadOptions = [];
4242

4343
/** @var string */
4444
public $outcomeCollectionName;

tests/SpecTests/FunctionalTestCase.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,11 @@ protected static function assertDocumentsMatch($expectedDocument, $actualDocumen
101101
*/
102102
protected function assertOutcomeCollectionData(array $expectedDocuments)
103103
{
104-
$outcomeCollection = $this->getOutcomeCollection();
105-
$findOptions = $this->getContext()->outcomeFindOptions;
104+
$outcomeCollection = $this->getOutcomeCollection($this->getContext()->outcomeReadOptions);
106105

107106
$mi = new MultipleIterator(MultipleIterator::MIT_NEED_ANY);
108107
$mi->attachIterator(new ArrayIterator($expectedDocuments));
109-
$mi->attachIterator(new IteratorIterator($outcomeCollection->find([], $findOptions)));
108+
$mi->attachIterator(new IteratorIterator($outcomeCollection->find()));
110109

111110
foreach ($mi as $documents) {
112111
list($expectedDocument, $actualDocument) = $documents;
@@ -193,16 +192,16 @@ protected function dropTestAndOutcomeCollections()
193192

194193
$collection = null;
195194
if ($context->collectionName !== null) {
196-
$collection = $context->getCollection();
197-
$collection->drop($context->defaultWriteOptions);
195+
$collection = $context->getCollection($context->defaultWriteOptions);
196+
$collection->drop();
198197
}
199198

200199
if ($context->outcomeCollectionName !== null) {
201-
$outcomeCollection = $this->getOutcomeCollection();
200+
$outcomeCollection = $this->getOutcomeCollection($context->defaultWriteOptions);
202201

203202
// Avoid redundant drop if the test and outcome collections are the same
204203
if ($collection === null || $outcomeCollection->getNamespace() !== $collection->getNamespace()) {
205-
$outcomeCollection->drop($context->defaultWriteOptions);
204+
$outcomeCollection->drop();
206205
}
207206
}
208207
}
@@ -226,12 +225,12 @@ protected function insertDataFixtures(array $documents, $collectionName = null)
226225
return;
227226
}
228227

229-
private function getOutcomeCollection()
228+
private function getOutcomeCollection(array $collectionOptions = [])
230229
{
231230
$context = $this->getContext();
232231

233232
// Outcome collection need not use the client under test
234-
return new Collection($this->manager, $context->databaseName, $context->outcomeCollectionName);
233+
return new Collection($this->manager, $context->databaseName, $context->outcomeCollectionName, $collectionOptions);
235234
}
236235

237236
/**

0 commit comments

Comments
 (0)