@@ -138,6 +138,14 @@ protected function assertSameObjectId($expectedObjectId, $actualObjectId)
138
138
*/
139
139
protected function configureFailPoint ($ command )
140
140
{
141
+ if (! $ this ->isFailCommandSupported ()) {
142
+ $ this ->markTestSkipped ('failCommand is only supported on mongod >= 4.0.0 and mongos >= 4.1.5. ' );
143
+ }
144
+
145
+ if (! $ this ->isFailCommandEnabled ()) {
146
+ $ this ->markTestSkipped ('The enableTestCommands parameter is not enabled. ' );
147
+ }
148
+
141
149
if (is_array ($ command )) {
142
150
$ command = (object ) $ command ;
143
151
}
@@ -394,4 +402,37 @@ private function disableFailPoints()
394
402
$ operation ->execute ($ server );
395
403
}
396
404
}
405
+
406
+ /**
407
+ * Checks if the failCommand command is supported on this server version
408
+ *
409
+ * @return bool
410
+ */
411
+ private function isFailCommandSupported ()
412
+ {
413
+ $ minVersion = $ this ->isShardedCluster () ? '4.1.5 ' : '4.0.0 ' ;
414
+
415
+ return version_compare ($ this ->getServerVersion (), $ minVersion , '>= ' );
416
+ }
417
+
418
+ /**
419
+ * Checks if the failCommand command is enabled by checking the enableTestCommands parameter
420
+ *
421
+ * @return bool
422
+ */
423
+ private function isFailCommandEnabled ()
424
+ {
425
+ try {
426
+ $ cursor = $ this ->manager ->executeCommand (
427
+ 'admin ' ,
428
+ new Command (['getParameter ' => 1 , 'enableTestCommands ' => 1 ])
429
+ );
430
+
431
+ $ document = current ($ cursor ->toArray ());
432
+ } catch (CommandException $ e ) {
433
+ return false ;
434
+ }
435
+
436
+ return isset ($ document ->enableTestCommands ) && $ document ->enableTestCommands === true ;
437
+ }
397
438
}
0 commit comments