Skip to content

Commit f50276a

Browse files
authored
PHPLIB-1116: Add tests for runCommand spec (#1066)
Additional test runner changes were required to support runCommand spec tests. Synced with mongodb/specifications@d697477
1 parent 81e8b79 commit f50276a

File tree

4 files changed

+595
-5
lines changed

4 files changed

+595
-5
lines changed

tests/UnifiedSpecTests/Operation.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -683,10 +683,16 @@ function (CollectionInfo $info) {
683683
assertArrayHasKey('command', $args);
684684
assertInstanceOf(stdClass::class, $args['command']);
685685

686-
return $database->command(
687-
$args['command'],
688-
array_diff_key($args, ['command' => 1])
689-
)->toArray()[0];
686+
// Note: commandName is not used by PHP
687+
$options = array_diff_key($args, ['command' => 1, 'commandName' => 1]);
688+
689+
/* runCommand spec tests may execute commands that return a
690+
* cursor (e.g. aggregate). PHPC creates a cursor automatically
691+
* so cannot return the original command result. Existing spec
692+
* tests do not evaluate the result, so we can return null here.
693+
* If that changes down the line, we can use command monitoring
694+
* to capture and return the command result. */
695+
return $database->command($args['command'], $options)->toArray()[0] ?? null;
690696

691697
default:
692698
Assert::fail('Unsupported database operation: ' . $this->name);

tests/UnifiedSpecTests/UnifiedSpecTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,17 @@ public function provideLoadBalancers()
168168
return $this->provideTests(__DIR__ . '/load-balancers/*.json');
169169
}
170170

171+
/** @dataProvider provideRunCommandTests */
172+
public function testRunCommand(UnifiedTestCase $test): void
173+
{
174+
self::$runner->run($test);
175+
}
176+
177+
public function provideRunCommandTests()
178+
{
179+
return $this->provideTests(__DIR__ . '/run-command/*.json');
180+
}
181+
171182
/** @dataProvider provideSessionsTests */
172183
public function testSessions(UnifiedTestCase $test): void
173184
{

tests/UnifiedSpecTests/Util.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ final class Util
8080
'listCollections' => ['authorizedCollections', 'filter', 'maxTimeMS', 'session'],
8181
'modifyCollection' => ['collection', 'changeStreamPreAndPostImages', 'index', 'validator'],
8282
// Note: commandName is not used by PHP
83-
'runCommand' => ['command', 'session', 'commandName'],
83+
'runCommand' => ['command', 'commandName', 'readPreference', 'session'],
8484
],
8585
Collection::class => [
8686
'aggregate' => ['pipeline', 'session', 'useCursor', 'allowDiskUse', 'batchSize', 'bypassDocumentValidation', 'collation', 'comment', 'explain', 'hint', 'let', 'maxAwaitTimeMS', 'maxTimeMS'],

0 commit comments

Comments
 (0)