diff --git a/tests/Operation/AggregateFunctionalTest.php b/tests/Operation/AggregateFunctionalTest.php index 7146ac973..bd5ccee80 100644 --- a/tests/Operation/AggregateFunctionalTest.php +++ b/tests/Operation/AggregateFunctionalTest.php @@ -185,10 +185,11 @@ public function testExplainOption(): void $this->assertCount(1, $results); $checkResult = $results[0]; + // Sharded clusters and load balanced servers list plans per shard - if (array_key_exists('shards', $results[0])) { - $firstShard = array_key_first((array) $results[0]['shards']); - $checkResult = (array) $results[0]['shards']->$firstShard; + if (array_key_exists('shards', $checkResult)) { + $firstShard = array_key_first((array) $checkResult['shards']); + $checkResult = (array) $checkResult['shards']->$firstShard; } /* MongoDB 4.2 may optimize aggregate pipelines into queries, which can diff --git a/tests/Operation/ExplainFunctionalTest.php b/tests/Operation/ExplainFunctionalTest.php index c620dbeaf..19b59dc5f 100644 --- a/tests/Operation/ExplainFunctionalTest.php +++ b/tests/Operation/ExplainFunctionalTest.php @@ -341,7 +341,7 @@ public function testAggregate(): void $explainOperation = new Explain($this->getDatabaseName(), $operation, ['verbosity' => Explain::VERBOSITY_QUERY, 'typeMap' => ['root' => 'array', 'document' => 'array']]); $result = $explainOperation->execute($this->getPrimaryServer()); - $this->assertExplainResult($result, false, false, true); + $this->assertExplainResult($result, false, false); } /** @dataProvider provideVerbosityInformation */ @@ -369,7 +369,7 @@ public function provideVerbosityInformation() ]; } - private function assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected, $stagesExpected = false): void + private function assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected): void { $checkResult = $result; @@ -378,11 +378,10 @@ private function assertExplainResult($result, $executionStatsExpected, $allPlans $checkResult = $result['shards'][$firstShard]; } - if ($stagesExpected) { - $this->assertArrayHasKey('stages', $checkResult); - } else { - $this->assertArrayHasKey('queryPlanner', $checkResult); - } + $this->assertThat($checkResult, $this->logicalOr( + $this->arrayHasKey('stages'), + $this->arrayHasKey('queryPlanner'), + )); if ($executionStatsExpected) { $this->assertArrayHasKey('executionStats', $checkResult);