From e35dd05ad9c3bf953ea3a16575c942188cf5a0f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Mon, 17 Jul 2023 10:19:45 +0200 Subject: [PATCH 1/2] Add test on UnifiedTestRunner EntityMapObserver --- tests/UnifiedSpecTests/UnifiedTestRunner.php | 2 ++ .../UnifiedTestRunnerTest.php | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/UnifiedSpecTests/UnifiedTestRunnerTest.php diff --git a/tests/UnifiedSpecTests/UnifiedTestRunner.php b/tests/UnifiedSpecTests/UnifiedTestRunner.php index 27f953a89..35a0ec456 100644 --- a/tests/UnifiedSpecTests/UnifiedTestRunner.php +++ b/tests/UnifiedSpecTests/UnifiedTestRunner.php @@ -125,6 +125,8 @@ public function run(UnifiedTestCase $test): void * * This function is primarily used by the Atlas testing workload executor. * + * @see https://github.com/mongodb-labs/drivers-atlas-testing/ + * * @param callable(EntityMap):void $entityMapObserver */ public function setEntityMapObserver(callable $entityMapObserver): void diff --git a/tests/UnifiedSpecTests/UnifiedTestRunnerTest.php b/tests/UnifiedSpecTests/UnifiedTestRunnerTest.php new file mode 100644 index 000000000..04c77bfd9 --- /dev/null +++ b/tests/UnifiedSpecTests/UnifiedTestRunnerTest.php @@ -0,0 +1,25 @@ +setEntityMapObserver(function (EntityMap $entityMap) use (&$calls): void { + $this->assertArrayHasKey('client0', $entityMap); + $this->assertArrayHasKey('database0', $entityMap); + $this->assertArrayHasKey('collection0', $entityMap); + $calls++; + }); + + $runner->run($test->current()); + $this->assertSame(1, $calls); + } +} From 0b29bcfd5ae66aa939dcb7a8e5d4795f334299be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 21 Jul 2023 13:16:17 +0200 Subject: [PATCH 2/2] Use dedicated test file --- .../UnifiedTestRunnerTest.php | 2 +- .../runner/entity-map-observer.json | 68 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/UnifiedSpecTests/runner/entity-map-observer.json diff --git a/tests/UnifiedSpecTests/UnifiedTestRunnerTest.php b/tests/UnifiedSpecTests/UnifiedTestRunnerTest.php index 04c77bfd9..d9e9c37ca 100644 --- a/tests/UnifiedSpecTests/UnifiedTestRunnerTest.php +++ b/tests/UnifiedSpecTests/UnifiedTestRunnerTest.php @@ -8,7 +8,7 @@ class UnifiedTestRunnerTest extends FunctionalTestCase { public function testEntityMapObserver(): void { - $test = UnifiedTestCase::fromFile(__DIR__ . '/crud/find.json'); + $test = UnifiedTestCase::fromFile(__DIR__ . '/runner/entity-map-observer.json'); $calls = 0; $runner = new UnifiedTestRunner(static::getUri()); diff --git a/tests/UnifiedSpecTests/runner/entity-map-observer.json b/tests/UnifiedSpecTests/runner/entity-map-observer.json new file mode 100644 index 000000000..833600950 --- /dev/null +++ b/tests/UnifiedSpecTests/runner/entity-map-observer.json @@ -0,0 +1,68 @@ +{ + "description": "find", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "useMultipleMongoses": true, + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "runner-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "runner-tests", + "documents": [] + } + ], + "tests": [ + { + "description": "basic find", + "operations": [ + { + "name": "find", + "arguments": { + "filter": {} + }, + "object": "collection0", + "expectResult": [] + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "find": "coll0", + "filter": {} + }, + "commandName": "find", + "databaseName": "runner-tests" + } + } + ] + } + ] + } + ] +}