|
21 | 21 | use MongoDB\Operation\UpdateOne;
|
22 | 22 | use MongoDB\Tests\CommandObserver;
|
23 | 23 |
|
| 24 | +use function array_key_exists; |
| 25 | +use function array_key_first; |
| 26 | + |
24 | 27 | class ExplainFunctionalTest extends FunctionalTestCase
|
25 | 28 | {
|
26 | 29 | /** @dataProvider provideVerbosityInformation */
|
@@ -368,21 +371,28 @@ public function provideVerbosityInformation()
|
368 | 371 |
|
369 | 372 | private function assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected, $stagesExpected = false): void
|
370 | 373 | {
|
| 374 | + $checkResult = $result; |
| 375 | + |
| 376 | + if (array_key_exists('shards', $result)) { |
| 377 | + $firstShard = array_key_first($result['shards']); |
| 378 | + $checkResult = $result['shards'][$firstShard]; |
| 379 | + } |
| 380 | + |
371 | 381 | if ($stagesExpected) {
|
372 |
| - $this->assertArrayHasKey('stages', $result); |
| 382 | + $this->assertArrayHasKey('stages', $checkResult); |
373 | 383 | } else {
|
374 |
| - $this->assertArrayHasKey('queryPlanner', $result); |
| 384 | + $this->assertArrayHasKey('queryPlanner', $checkResult); |
375 | 385 | }
|
376 | 386 |
|
377 | 387 | if ($executionStatsExpected) {
|
378 |
| - $this->assertArrayHasKey('executionStats', $result); |
| 388 | + $this->assertArrayHasKey('executionStats', $checkResult); |
379 | 389 | if ($allPlansExecutionExpected) {
|
380 |
| - $this->assertArrayHasKey('allPlansExecution', $result['executionStats']); |
| 390 | + $this->assertArrayHasKey('allPlansExecution', $checkResult['executionStats']); |
381 | 391 | } else {
|
382 |
| - $this->assertArrayNotHasKey('allPlansExecution', $result['executionStats']); |
| 392 | + $this->assertArrayNotHasKey('allPlansExecution', $checkResult['executionStats']); |
383 | 393 | }
|
384 | 394 | } else {
|
385 |
| - $this->assertArrayNotHasKey('executionStats', $result); |
| 395 | + $this->assertArrayNotHasKey('executionStats', $checkResult); |
386 | 396 | }
|
387 | 397 | }
|
388 | 398 |
|
|
0 commit comments