55use Closure ;
66use MongoDB \BSON \Binary ;
77use MongoDB \BSON \Int64 ;
8- use MongoDB \Client ;
98use MongoDB \Collection ;
109use MongoDB \Driver \ClientEncryption ;
1110use MongoDB \Driver \Exception \AuthenticationException ;
@@ -206,7 +205,7 @@ public function testDataKeyAndDoubleEncryption(string $providerName, $masterKey)
206205 'keyVaultClient ' => $ client ,
207206 ];
208207
209- $ clientEncrypted = new Client ( static ::getUri () , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
208+ $ clientEncrypted = static ::createTestClient ( null , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
210209 $ clientEncryption = $ clientEncrypted ->createClientEncryption ($ encryptionOpts );
211210
212211 $ commands = [];
@@ -323,7 +322,7 @@ public function testExternalKeyVault($withExternalKeyVault)
323322 ];
324323
325324 if ($ withExternalKeyVault ) {
326- $ encryptionOpts ['keyVaultClient ' ] = new Client ( static ::getUri () , ['username ' => 'fake-user ' , 'password ' => 'fake-pwd ' ]);
325+ $ encryptionOpts ['keyVaultClient ' ] = static ::createTestClient ( null , ['username ' => 'fake-user ' , 'password ' => 'fake-pwd ' ]);
327326 }
328327
329328 $ autoEncryptionOpts = $ encryptionOpts + [
@@ -332,7 +331,7 @@ public function testExternalKeyVault($withExternalKeyVault)
332331 ],
333332 ];
334333
335- $ clientEncrypted = new Client ( static ::getUri () , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
334+ $ clientEncrypted = static ::createTestClient ( null , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
336335 $ clientEncryption = $ clientEncrypted ->createClientEncryption ($ encryptionOpts );
337336
338337 try {
@@ -469,7 +468,7 @@ public function testBSONSizeLimitsAndBatchSplitting(Closure $test)
469468 'keyVaultClient ' => $ client ,
470469 ];
471470
472- $ clientEncrypted = new Client ( static ::getUri () , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
471+ $ clientEncrypted = static ::createTestClient ( null , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
473472
474473 $ collection = $ clientEncrypted ->selectCollection ('db ' , 'coll ' );
475474
@@ -483,7 +482,7 @@ public function testBSONSizeLimitsAndBatchSplitting(Closure $test)
483482 */
484483 public function testViewsAreProhibited ()
485484 {
486- $ client = new Client ( static ::getUri () );
485+ $ client = static ::createTestClient ( );
487486
488487 $ client ->selectCollection ('db ' , 'view ' )->drop ();
489488 $ client ->selectDatabase ('db ' )->command (['create ' => 'view ' , 'viewOn ' => 'coll ' ]);
@@ -495,7 +494,7 @@ public function testViewsAreProhibited()
495494 ],
496495 ];
497496
498- $ clientEncrypted = new Client ( static ::getUri () , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
497+ $ clientEncrypted = static ::createTestClient ( null , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
499498
500499 try {
501500 $ clientEncrypted ->selectCollection ('db ' , 'view ' )->insertOne (['foo ' => 'bar ' ]);
@@ -557,7 +556,7 @@ public function testCorpus($schemaMap = true)
557556 $ corpus = (array ) $ this ->decodeJson (file_get_contents (__DIR__ . '/client-side-encryption/corpus/corpus.json ' ));
558557 $ corpusCopied = [];
559558
560- $ clientEncrypted = new Client ( static ::getUri () , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
559+ $ clientEncrypted = static ::createTestClient ( null , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
561560 $ clientEncryption = $ clientEncrypted ->createClientEncryption ($ encryptionOpts );
562561
563562 $ collection = $ clientEncrypted ->selectCollection ('db ' , 'coll ' );
@@ -621,7 +620,7 @@ public function testCorpus($schemaMap = true)
621620 */
622621 public function testCustomEndpoint (Closure $ test )
623622 {
624- $ client = new Client ( static ::getUri () );
623+ $ client = static ::createTestClient ( );
625624
626625 $ clientEncryption = $ client ->createClientEncryption ([
627626 'keyVaultNamespace ' => 'keyvault.datakeys ' ,
@@ -758,7 +757,7 @@ public function testBypassSpawningMongocryptdViaBypassSpawn()
758757 ],
759758 ];
760759
761- $ clientEncrypted = new Client ( static ::getUri () , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
760+ $ clientEncrypted = static ::createTestClient ( null , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
762761
763762 try {
764763 $ clientEncrypted ->selectCollection ('db ' , 'coll ' )->insertOne (['encrypted ' => 'test ' ]);
@@ -787,11 +786,11 @@ public function testBypassSpawningMongocryptdViaBypassAutoEncryption()
787786 ],
788787 ];
789788
790- $ clientEncrypted = new Client ( static ::getUri () , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
789+ $ clientEncrypted = static ::createTestClient ( null , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
791790
792791 $ clientEncrypted ->selectCollection ('db ' , 'coll ' )->insertOne (['encrypted ' => 'test ' ]);
793792
794- $ clientMongocryptd = new Client ('mongodb://localhost:27021 ' );
793+ $ clientMongocryptd = static :: createTestClient ('mongodb://localhost:27021 ' );
795794
796795 $ this ->expectException (ConnectionTimeoutException::class);
797796 $ clientMongocryptd ->selectDatabase ('db ' )->command (['isMaster ' => true ]);
0 commit comments