Skip to content

Rely on Collection to apply read/write opts for old servers #712

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

Merged
merged 1 commit into from
Jan 27, 2020
Merged
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
6 changes: 3 additions & 3 deletions tests/SpecTests/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class Context
public $defaultWriteOptions = [];

/** @var array */
public $outcomeFindOptions = [];
public $outcomeReadOptions = [];

/** @var string */
public $outcomeCollectionName;
Expand Down Expand Up @@ -98,7 +98,7 @@ public static function fromCrud(stdClass $test, $databaseName, $collectionName)
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY),
];

$o->outcomeFindOptions = [
$o->outcomeReadOptions = [
'readConcern' => new ReadConcern('local'),
'readPreference' => new ReadPreference('primary'),
];
Expand Down Expand Up @@ -147,7 +147,7 @@ public static function fromTransactions(stdClass $test, $databaseName, $collecti
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY),
];

$o->outcomeFindOptions = [
$o->outcomeReadOptions = [
'readConcern' => new ReadConcern('local'),
'readPreference' => new ReadPreference('primary'),
];
Expand Down
17 changes: 8 additions & 9 deletions tests/SpecTests/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,11 @@ protected static function assertDocumentsMatch($expectedDocument, $actualDocumen
*/
protected function assertOutcomeCollectionData(array $expectedDocuments)
{
$outcomeCollection = $this->getOutcomeCollection();
$findOptions = $this->getContext()->outcomeFindOptions;
$outcomeCollection = $this->getOutcomeCollection($this->getContext()->outcomeReadOptions);

$mi = new MultipleIterator(MultipleIterator::MIT_NEED_ANY);
$mi->attachIterator(new ArrayIterator($expectedDocuments));
$mi->attachIterator(new IteratorIterator($outcomeCollection->find([], $findOptions)));
$mi->attachIterator(new IteratorIterator($outcomeCollection->find()));

foreach ($mi as $documents) {
list($expectedDocument, $actualDocument) = $documents;
Expand Down Expand Up @@ -193,16 +192,16 @@ protected function dropTestAndOutcomeCollections()

$collection = null;
if ($context->collectionName !== null) {
$collection = $context->getCollection();
$collection->drop($context->defaultWriteOptions);
$collection = $context->getCollection($context->defaultWriteOptions);
$collection->drop();
}

if ($context->outcomeCollectionName !== null) {
$outcomeCollection = $this->getOutcomeCollection();
$outcomeCollection = $this->getOutcomeCollection($context->defaultWriteOptions);

// Avoid redundant drop if the test and outcome collections are the same
if ($collection === null || $outcomeCollection->getNamespace() !== $collection->getNamespace()) {
$outcomeCollection->drop($context->defaultWriteOptions);
$outcomeCollection->drop();
}
}
}
Expand All @@ -226,12 +225,12 @@ protected function insertDataFixtures(array $documents, $collectionName = null)
return;
}

private function getOutcomeCollection()
private function getOutcomeCollection(array $collectionOptions = [])
{
$context = $this->getContext();

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

/**
Expand Down