Skip to content

Commit 46a0eda

Browse files
authored
Harden explain tests (#1192)
1 parent a5657d7 commit 46a0eda

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

tests/Operation/AggregateFunctionalTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,11 @@ public function testExplainOption(): void
185185
$this->assertCount(1, $results);
186186

187187
$checkResult = $results[0];
188+
188189
// Sharded clusters and load balanced servers list plans per shard
189-
if (array_key_exists('shards', $results[0])) {
190-
$firstShard = array_key_first((array) $results[0]['shards']);
191-
$checkResult = (array) $results[0]['shards']->$firstShard;
190+
if (array_key_exists('shards', $checkResult)) {
191+
$firstShard = array_key_first((array) $checkResult['shards']);
192+
$checkResult = (array) $checkResult['shards']->$firstShard;
192193
}
193194

194195
/* MongoDB 4.2 may optimize aggregate pipelines into queries, which can

tests/Operation/ExplainFunctionalTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ public function testAggregate(): void
341341
$explainOperation = new Explain($this->getDatabaseName(), $operation, ['verbosity' => Explain::VERBOSITY_QUERY, 'typeMap' => ['root' => 'array', 'document' => 'array']]);
342342
$result = $explainOperation->execute($this->getPrimaryServer());
343343

344-
$this->assertExplainResult($result, false, false, true);
344+
$this->assertExplainResult($result, false, false);
345345
}
346346

347347
/** @dataProvider provideVerbosityInformation */
@@ -369,7 +369,7 @@ public function provideVerbosityInformation()
369369
];
370370
}
371371

372-
private function assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected, $stagesExpected = false): void
372+
private function assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected): void
373373
{
374374
$checkResult = $result;
375375

@@ -378,11 +378,10 @@ private function assertExplainResult($result, $executionStatsExpected, $allPlans
378378
$checkResult = $result['shards'][$firstShard];
379379
}
380380

381-
if ($stagesExpected) {
382-
$this->assertArrayHasKey('stages', $checkResult);
383-
} else {
384-
$this->assertArrayHasKey('queryPlanner', $checkResult);
385-
}
381+
$this->assertThat($checkResult, $this->logicalOr(
382+
$this->arrayHasKey('stages'),
383+
$this->arrayHasKey('queryPlanner'),
384+
));
386385

387386
if ($executionStatsExpected) {
388387
$this->assertArrayHasKey('executionStats', $checkResult);

0 commit comments

Comments
 (0)