Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPLIB-1408: Convert ADL spec test to unified test format #1250

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,16 @@ protected function skipIfTransactionsAreNotSupported(): void
}
}

protected function isAtlasDataLake(): bool
{
$buildInfo = $this->getPrimaryServer()->executeCommand(
$this->getDatabaseName(),
new Command(['buildInfo' => 1]),
)->toArray()[0];

return ! empty($buildInfo->dataLake);
}

protected function isEnterprise(): bool
{
$buildInfo = $this->getPrimaryServer()->executeCommand(
Expand Down
113 changes: 1 addition & 112 deletions tests/SpecTests/AtlasDataLakeSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@

namespace MongoDB\Tests\SpecTests;

use MongoDB\Driver\Command;
use MongoDB\Driver\Cursor;
use MongoDB\Tests\CommandObserver;
use stdClass;

use function basename;
use function current;
use function explode;
use function file_get_contents;
use function glob;
use function parse_url;

/**
Expand All @@ -32,101 +27,7 @@ public function setUp(): void
}

/**
* Assert that the expected and actual command documents match.
*
* @param stdClass $expected Expected command document
* @param stdClass $actual Actual command document
*/
public static function assertCommandMatches(stdClass $expected, stdClass $actual): void
{
foreach ($expected as $key => $value) {
if ($value === null) {
static::assertObjectNotHasAttribute($key, $actual);
unset($expected->{$key});
}
}

static::assertDocumentsMatch($expected, $actual);
}

/**
* Execute an individual test case from the specification.
*
* @dataProvider provideTests
* @param stdClass $test Individual "tests[]" document
* @param array $runOn Top-level "runOn" array with server requirements
* @param array $data Top-level "data" array to initialize collection
* @param string $databaseName Name of database under test
* @param string $collectionName Name of collection under test
*/
public function testAtlasDataLake(stdClass $test, ?array $runOn, array $data, ?string $databaseName = null, ?string $collectionName = null): void
{
if (isset($runOn)) {
$this->checkServerRequirements($runOn);
}

if (isset($test->skipReason)) {
$this->markTestSkipped($test->skipReason);
}

$databaseName ??= $this->getDatabaseName();
$collectionName ??= $this->getCollectionName();

$context = Context::fromCrud($test, $databaseName, $collectionName);
$this->setContext($context);

/* Note: Atlas Data Lake is read-only, so do not attempt to drop the
* collection under test or insert data fixtures. Necesarry data
* fixtures are already specified in the mongohoused configuration. */

if (isset($test->failPoint)) {
throw new LogicException('ADL tests are not expected to configure fail points');
}

if (isset($test->expectations)) {
$commandExpectations = CommandExpectations::fromCrud($context->getClient(), (array) $test->expectations);
$commandExpectations->startMonitoring();
}

foreach ($test->operations as $operation) {
Operation::fromCrud($operation)->assert($this, $context);
}

if (isset($commandExpectations)) {
$commandExpectations->stopMonitoring();
$commandExpectations->assert($this, $context);
}

if (isset($test->outcome->collection->data)) {
throw new LogicException('ADL tests are not expected to assert collection data');
}
}

public function provideTests()
{
$testArgs = [];

foreach (glob(__DIR__ . '/atlas_data_lake/*.json') as $filename) {
$json = $this->decodeJson(file_get_contents($filename));
$group = basename($filename, '.json');
$runOn = $json->runOn ?? null;
$data = $json->data ?? [];
// phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
$databaseName = $json->database_name ?? null;
$collectionName = $json->collection_name ?? null;
// phpcs:enable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps

foreach ($json->tests as $test) {
$name = $group . ': ' . $test->description;
$testArgs[$name] = [$test, $runOn, $data, $databaseName, $collectionName];
}
}

return $testArgs;
}

/**
* Prose test 1: Connect without authentication
* Prose test 1: killCursors command
*/
public function testKillCursors(): void
{
Expand Down Expand Up @@ -235,16 +136,4 @@ public function testConnectwithSCRAMSHA256(): void
$this->assertInstanceOf(Cursor::class, $cursor);
$this->assertCommandSucceeded(current($cursor->toArray()));
}

private function isAtlasDataLake(): bool
{
$cursor = $this->manager->executeCommand(
$this->getDatabaseName(),
new Command(['buildInfo' => 1]),
);

$document = current($cursor->toArray());

return ! empty($document->dataLake);
}
}
53 changes: 0 additions & 53 deletions tests/SpecTests/atlas_data_lake/aggregate.json

This file was deleted.

27 changes: 0 additions & 27 deletions tests/SpecTests/atlas_data_lake/estimatedDocumentCount.json

This file was deleted.

57 changes: 0 additions & 57 deletions tests/SpecTests/atlas_data_lake/getMore.json

This file was deleted.

25 changes: 0 additions & 25 deletions tests/SpecTests/atlas_data_lake/listCollections.json

This file was deleted.

24 changes: 0 additions & 24 deletions tests/SpecTests/atlas_data_lake/listDatabases.json

This file was deleted.

31 changes: 0 additions & 31 deletions tests/SpecTests/atlas_data_lake/runCommand.json

This file was deleted.

Loading