Skip to content

Commit

Permalink
PHPLIB-743: Ignore extra metadata queries in CSFLE spec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmikola committed Oct 20, 2021
1 parent c4302b9 commit 3a0bef4
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions tests/SpecTests/CommandExpectations.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class CommandExpectations implements CommandSubscriber
/** @var boolean */
private $ignoreExtraEvents = false;

/** @var boolean */
private $ignoreKeyVaultListCollections = false;

/** @var string[] */
private $ignoredCommandNames = [];

Expand Down Expand Up @@ -87,6 +90,7 @@ public static function fromClientSideEncryption(array $expectedEvents)

$o->ignoreCommandFailed = true;
$o->ignoreCommandSucceeded = true;
$o->ignoreKeyVaultListCollections = true;

return $o;
}
Expand Down Expand Up @@ -254,7 +258,24 @@ public function assert(FunctionalTestCase $test, Context $context): void

private function isEventIgnored($event)
{
return ($this->ignoreExtraEvents && count($this->actualEvents) === count($this->expectedEvents))
|| in_array($event->getCommandName(), $this->ignoredCommandNames);
if ($this->ignoreExtraEvents && count($this->actualEvents) === count($this->expectedEvents)) {
return true;
}

if (in_array($event->getCommandName(), $this->ignoredCommandNames)) {
return true;
}

/* Note: libmongoc does not use a separate MongoClient to query for
* CSFLE metadata (DRIVERS-1459). Since the tests do not expect this
* command, we must ignore it. */
if (
$this->ignoreKeyVaultListCollections && $event instanceof CommandStartedEvent &&
$event->getCommandName() === 'listCollections' && $event->getDatabaseName() === 'keyvault'
) {
return true;
}

return false;
}
}

0 comments on commit 3a0bef4

Please sign in to comment.