Skip to content

Commit e3b6462

Browse files
authored
Add test on UnifiedTestRunner::setEntityMapObserver() (#1129)
Use dedicated test file
1 parent 9e1971c commit e3b6462

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

tests/UnifiedSpecTests/UnifiedTestRunner.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ public function run(UnifiedTestCase $test): void
125125
*
126126
* This function is primarily used by the Atlas testing workload executor.
127127
*
128+
* @see https://github.com/mongodb-labs/drivers-atlas-testing/
129+
*
128130
* @param callable(EntityMap):void $entityMapObserver
129131
*/
130132
public function setEntityMapObserver(callable $entityMapObserver): void
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace MongoDB\Tests\UnifiedSpecTests;
4+
5+
use MongoDB\Tests\FunctionalTestCase;
6+
7+
class UnifiedTestRunnerTest extends FunctionalTestCase
8+
{
9+
public function testEntityMapObserver(): void
10+
{
11+
$test = UnifiedTestCase::fromFile(__DIR__ . '/runner/entity-map-observer.json');
12+
$calls = 0;
13+
14+
$runner = new UnifiedTestRunner(static::getUri());
15+
$runner->setEntityMapObserver(function (EntityMap $entityMap) use (&$calls): void {
16+
$this->assertArrayHasKey('client0', $entityMap);
17+
$this->assertArrayHasKey('database0', $entityMap);
18+
$this->assertArrayHasKey('collection0', $entityMap);
19+
$calls++;
20+
});
21+
22+
$runner->run($test->current());
23+
$this->assertSame(1, $calls);
24+
}
25+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"description": "find",
3+
"schemaVersion": "1.0",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0",
8+
"useMultipleMongoses": true,
9+
"observeEvents": [
10+
"commandStartedEvent"
11+
]
12+
}
13+
},
14+
{
15+
"database": {
16+
"id": "database0",
17+
"client": "client0",
18+
"databaseName": "runner-tests"
19+
}
20+
},
21+
{
22+
"collection": {
23+
"id": "collection0",
24+
"database": "database0",
25+
"collectionName": "coll0"
26+
}
27+
}
28+
],
29+
"initialData": [
30+
{
31+
"collectionName": "coll0",
32+
"databaseName": "runner-tests",
33+
"documents": []
34+
}
35+
],
36+
"tests": [
37+
{
38+
"description": "basic find",
39+
"operations": [
40+
{
41+
"name": "find",
42+
"arguments": {
43+
"filter": {}
44+
},
45+
"object": "collection0",
46+
"expectResult": []
47+
}
48+
],
49+
"expectEvents": [
50+
{
51+
"client": "client0",
52+
"events": [
53+
{
54+
"commandStartedEvent": {
55+
"command": {
56+
"find": "coll0",
57+
"filter": {}
58+
},
59+
"commandName": "find",
60+
"databaseName": "runner-tests"
61+
}
62+
}
63+
]
64+
}
65+
]
66+
}
67+
]
68+
}

0 commit comments

Comments
 (0)