@@ -30,6 +30,10 @@ class FunctionalTestCase extends BaseFunctionalTestCase
30
30
public const TOPOLOGY_REPLICASET = 'replicaset ' ;
31
31
public const TOPOLOGY_SHARDED = 'sharded ' ;
32
32
33
+ public const SERVERLESS_ALLOW = 'allow ' ;
34
+ public const SERVERLESS_FORBID = 'forbid ' ;
35
+ public const SERVERLESS_REQUIRE = 'require ' ;
36
+
33
37
/** @var Context|null */
34
38
private $ context ;
35
39
@@ -137,8 +141,9 @@ protected function checkServerRequirements(array $runOn): void
137
141
$ minServerVersion = $ req ->minServerVersion ?? null ;
138
142
$ maxServerVersion = $ req ->maxServerVersion ?? null ;
139
143
$ topologies = $ req ->topology ?? null ;
144
+ $ serverlessMode = $ req ->serverless ?? null ;
140
145
141
- if ($ this ->isServerRequirementSatisifed ($ minServerVersion , $ maxServerVersion , $ topologies )) {
146
+ if ($ this ->isServerRequirementSatisifed ($ minServerVersion , $ maxServerVersion , $ topologies, $ serverlessMode )) {
142
147
return ;
143
148
}
144
149
}
@@ -268,7 +273,27 @@ private function getTopology(): string
268
273
return $ topologyTypeMap [$ primaryType ];
269
274
}
270
275
271
- throw new UnexpectedValueException ('Toplogy is neither single nor RS nor sharded ' );
276
+ throw new UnexpectedValueException (sprintf ('Cannot find topology for primary of type "%s". ' , $ primaryType ));
277
+ }
278
+
279
+ private function isServerlessRequirementSatisfied (?string $ serverlessMode ): bool
280
+ {
281
+ if ($ serverlessMode === null ) {
282
+ return true ;
283
+ }
284
+
285
+ switch ($ serverlessMode ) {
286
+ case self ::SERVERLESS_ALLOW :
287
+ return true ;
288
+
289
+ case self ::SERVERLESS_FORBID :
290
+ return ! static ::isServerless ();
291
+
292
+ case self ::SERVERLESS_REQUIRE :
293
+ return static ::isServerless ();
294
+ }
295
+
296
+ throw new UnexpectedValueException (sprintf ('Invalid serverless requirement "%s" found. ' , $ serverlessMode ));
272
297
}
273
298
274
299
/**
@@ -279,7 +304,7 @@ private function getTopology(): string
279
304
* @param array|null $topologies
280
305
* @return boolean
281
306
*/
282
- private function isServerRequirementSatisifed (?string $ minServerVersion , ?string $ maxServerVersion , ?array $ topologies = null ): bool
307
+ private function isServerRequirementSatisifed (?string $ minServerVersion , ?string $ maxServerVersion , ?array $ topologies = null , ? string $ serverlessMode = null ): bool
283
308
{
284
309
$ serverVersion = $ this ->getServerVersion ();
285
310
@@ -297,6 +322,10 @@ private function isServerRequirementSatisifed(?string $minServerVersion, ?string
297
322
return false ;
298
323
}
299
324
325
+ if (! $ this ->isServerlessRequirementSatisfied ($ serverlessMode )) {
326
+ return false ;
327
+ }
328
+
300
329
return true ;
301
330
}
302
331
}
0 commit comments