Skip to content

Commit d405fa4

Browse files
committed
PHPLIB-1408: Convert ADL spec test to unified test format
Synced with mongodb/specifications#1545 Moves isAtlasDataLake() function to FunctionalTestCase, since it is now shared across test files. Fixes typo in ADL prose test comment.
1 parent 6f18405 commit d405fa4

16 files changed

+447
-338
lines changed

tests/FunctionalTestCase.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,16 @@ protected function skipIfTransactionsAreNotSupported(): void
522522
}
523523
}
524524

525+
protected function isAtlasDataLake(): bool
526+
{
527+
$buildInfo = $this->getPrimaryServer()->executeCommand(
528+
$this->getDatabaseName(),
529+
new Command(['buildInfo' => 1]),
530+
)->toArray()[0];
531+
532+
return ! empty($buildInfo->dataLake);
533+
}
534+
525535
protected function isEnterprise(): bool
526536
{
527537
$buildInfo = $this->getPrimaryServer()->executeCommand(

tests/SpecTests/AtlasDataLakeSpecTest.php

Lines changed: 1 addition & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@
22

33
namespace MongoDB\Tests\SpecTests;
44

5-
use MongoDB\Driver\Command;
65
use MongoDB\Driver\Cursor;
76
use MongoDB\Tests\CommandObserver;
8-
use stdClass;
97

10-
use function basename;
118
use function current;
129
use function explode;
13-
use function file_get_contents;
14-
use function glob;
1510
use function parse_url;
1611

1712
/**
@@ -32,101 +27,7 @@ public function setUp(): void
3227
}
3328

3429
/**
35-
* Assert that the expected and actual command documents match.
36-
*
37-
* @param stdClass $expected Expected command document
38-
* @param stdClass $actual Actual command document
39-
*/
40-
public static function assertCommandMatches(stdClass $expected, stdClass $actual): void
41-
{
42-
foreach ($expected as $key => $value) {
43-
if ($value === null) {
44-
static::assertObjectNotHasAttribute($key, $actual);
45-
unset($expected->{$key});
46-
}
47-
}
48-
49-
static::assertDocumentsMatch($expected, $actual);
50-
}
51-
52-
/**
53-
* Execute an individual test case from the specification.
54-
*
55-
* @dataProvider provideTests
56-
* @param stdClass $test Individual "tests[]" document
57-
* @param array $runOn Top-level "runOn" array with server requirements
58-
* @param array $data Top-level "data" array to initialize collection
59-
* @param string $databaseName Name of database under test
60-
* @param string $collectionName Name of collection under test
61-
*/
62-
public function testAtlasDataLake(stdClass $test, ?array $runOn, array $data, ?string $databaseName = null, ?string $collectionName = null): void
63-
{
64-
if (isset($runOn)) {
65-
$this->checkServerRequirements($runOn);
66-
}
67-
68-
if (isset($test->skipReason)) {
69-
$this->markTestSkipped($test->skipReason);
70-
}
71-
72-
$databaseName ??= $this->getDatabaseName();
73-
$collectionName ??= $this->getCollectionName();
74-
75-
$context = Context::fromCrud($test, $databaseName, $collectionName);
76-
$this->setContext($context);
77-
78-
/* Note: Atlas Data Lake is read-only, so do not attempt to drop the
79-
* collection under test or insert data fixtures. Necesarry data
80-
* fixtures are already specified in the mongohoused configuration. */
81-
82-
if (isset($test->failPoint)) {
83-
throw new LogicException('ADL tests are not expected to configure fail points');
84-
}
85-
86-
if (isset($test->expectations)) {
87-
$commandExpectations = CommandExpectations::fromCrud($context->getClient(), (array) $test->expectations);
88-
$commandExpectations->startMonitoring();
89-
}
90-
91-
foreach ($test->operations as $operation) {
92-
Operation::fromCrud($operation)->assert($this, $context);
93-
}
94-
95-
if (isset($commandExpectations)) {
96-
$commandExpectations->stopMonitoring();
97-
$commandExpectations->assert($this, $context);
98-
}
99-
100-
if (isset($test->outcome->collection->data)) {
101-
throw new LogicException('ADL tests are not expected to assert collection data');
102-
}
103-
}
104-
105-
public function provideTests()
106-
{
107-
$testArgs = [];
108-
109-
foreach (glob(__DIR__ . '/atlas_data_lake/*.json') as $filename) {
110-
$json = $this->decodeJson(file_get_contents($filename));
111-
$group = basename($filename, '.json');
112-
$runOn = $json->runOn ?? null;
113-
$data = $json->data ?? [];
114-
// phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
115-
$databaseName = $json->database_name ?? null;
116-
$collectionName = $json->collection_name ?? null;
117-
// phpcs:enable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
118-
119-
foreach ($json->tests as $test) {
120-
$name = $group . ': ' . $test->description;
121-
$testArgs[$name] = [$test, $runOn, $data, $databaseName, $collectionName];
122-
}
123-
}
124-
125-
return $testArgs;
126-
}
127-
128-
/**
129-
* Prose test 1: Connect without authentication
30+
* Prose test 1: killCursors command
13031
*/
13132
public function testKillCursors(): void
13233
{
@@ -235,16 +136,4 @@ public function testConnectwithSCRAMSHA256(): void
235136
$this->assertInstanceOf(Cursor::class, $cursor);
236137
$this->assertCommandSucceeded(current($cursor->toArray()));
237138
}
238-
239-
private function isAtlasDataLake(): bool
240-
{
241-
$cursor = $this->manager->executeCommand(
242-
$this->getDatabaseName(),
243-
new Command(['buildInfo' => 1]),
244-
);
245-
246-
$document = current($cursor->toArray());
247-
248-
return ! empty($document->dataLake);
249-
}
250139
}

tests/SpecTests/atlas_data_lake/aggregate.json

Lines changed: 0 additions & 53 deletions
This file was deleted.

tests/SpecTests/atlas_data_lake/estimatedDocumentCount.json

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/SpecTests/atlas_data_lake/getMore.json

Lines changed: 0 additions & 57 deletions
This file was deleted.

tests/SpecTests/atlas_data_lake/listCollections.json

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/SpecTests/atlas_data_lake/listDatabases.json

Lines changed: 0 additions & 24 deletions
This file was deleted.

tests/SpecTests/atlas_data_lake/runCommand.json

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)