Skip to content

Commit 6283fdc

Browse files
committed
Run versioned API spec tests
1 parent da0dd10 commit 6283fdc

9 files changed

+3049
-1
lines changed

tests/UnifiedSpecTests/Context.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use MongoDB\Driver\Manager;
88
use MongoDB\Driver\ReadPreference;
99
use MongoDB\Driver\Server;
10+
use MongoDB\Driver\ServerApi;
1011
use stdClass;
1112
use function array_key_exists;
1213
use function array_map;
@@ -208,11 +209,12 @@ static function (string $tag) : array {
208209

209210
private function createClient(string $id, stdClass $o)
210211
{
211-
Util::assertHasOnlyKeys($o, ['id', 'uriOptions', 'useMultipleMongoses', 'observeEvents', 'ignoreCommandMonitoringEvents']);
212+
Util::assertHasOnlyKeys($o, ['id', 'uriOptions', 'useMultipleMongoses', 'observeEvents', 'ignoreCommandMonitoringEvents', 'serverApi']);
212213

213214
$useMultipleMongoses = $o->useMultipleMongoses ?? null;
214215
$observeEvents = $o->observeEvents ?? null;
215216
$ignoreCommandMonitoringEvents = $o->ignoreCommandMonitoringEvents ?? [];
217+
$serverApi = $o->serverApi ?? null;
216218

217219
$uri = $this->uri;
218220

@@ -256,6 +258,14 @@ private function createClient(string $id, stdClass $o)
256258
static $i = 0;
257259
$driverOptions = isset($observeEvents) ? ['i' => $i++] : [];
258260

261+
if ($serverApi !== null) {
262+
$driverOptions['serverApi'] = new ServerApi(
263+
$serverApi->version,
264+
$serverApi->strict ?? null,
265+
$serverApi->deprecationErrors ?? null
266+
);
267+
}
268+
259269
$this->entityMap->set($id, new Client($uri, $uriOptions, $driverOptions));
260270
}
261271

tests/UnifiedSpecTests/UnifiedSpecTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,19 @@ public function provideCrudTests()
154154
return $this->provideTests(__DIR__ . '/crud');
155155
}
156156

157+
/**
158+
* @dataProvider provideVersionedApiTests
159+
*/
160+
public function testVersionedApi(...$args)
161+
{
162+
$this->doTestCase(...$args);
163+
}
164+
165+
public function provideVersionedApiTests()
166+
{
167+
return $this->provideTests(__DIR__ . '/versioned-api');
168+
}
169+
157170
/**
158171
* @dataProvider providePassingTests
159172
*/
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"description": "entity-client-apiVersion-unsupported",
3+
"schemaVersion": "1.1",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0",
8+
"serverApi": {
9+
"version": "server_will_never_support_this_api_version"
10+
}
11+
}
12+
}
13+
],
14+
"tests": [
15+
{
16+
"description": "foo",
17+
"operations": []
18+
}
19+
]
20+
}

0 commit comments

Comments
 (0)