5
5
use Closure ;
6
6
use MongoDB \BSON \Binary ;
7
7
use MongoDB \BSON \Int64 ;
8
- use MongoDB \Client ;
9
8
use MongoDB \Collection ;
10
9
use MongoDB \Driver \ClientEncryption ;
11
10
use MongoDB \Driver \Exception \AuthenticationException ;
@@ -206,7 +205,7 @@ public function testDataKeyAndDoubleEncryption(string $providerName, $masterKey)
206
205
'keyVaultClient ' => $ client ,
207
206
];
208
207
209
- $ clientEncrypted = new Client ( static ::getUri () , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
208
+ $ clientEncrypted = static ::createTestClient ( null , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
210
209
$ clientEncryption = $ clientEncrypted ->createClientEncryption ($ encryptionOpts );
211
210
212
211
$ commands = [];
@@ -323,7 +322,7 @@ public function testExternalKeyVault($withExternalKeyVault)
323
322
];
324
323
325
324
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 ' ]);
327
326
}
328
327
329
328
$ autoEncryptionOpts = $ encryptionOpts + [
@@ -332,7 +331,7 @@ public function testExternalKeyVault($withExternalKeyVault)
332
331
],
333
332
];
334
333
335
- $ clientEncrypted = new Client ( static ::getUri () , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
334
+ $ clientEncrypted = static ::createTestClient ( null , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
336
335
$ clientEncryption = $ clientEncrypted ->createClientEncryption ($ encryptionOpts );
337
336
338
337
try {
@@ -469,7 +468,7 @@ public function testBSONSizeLimitsAndBatchSplitting(Closure $test)
469
468
'keyVaultClient ' => $ client ,
470
469
];
471
470
472
- $ clientEncrypted = new Client ( static ::getUri () , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
471
+ $ clientEncrypted = static ::createTestClient ( null , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
473
472
474
473
$ collection = $ clientEncrypted ->selectCollection ('db ' , 'coll ' );
475
474
@@ -483,7 +482,7 @@ public function testBSONSizeLimitsAndBatchSplitting(Closure $test)
483
482
*/
484
483
public function testViewsAreProhibited ()
485
484
{
486
- $ client = new Client ( static ::getUri () );
485
+ $ client = static ::createTestClient ( );
487
486
488
487
$ client ->selectCollection ('db ' , 'view ' )->drop ();
489
488
$ client ->selectDatabase ('db ' )->command (['create ' => 'view ' , 'viewOn ' => 'coll ' ]);
@@ -495,7 +494,7 @@ public function testViewsAreProhibited()
495
494
],
496
495
];
497
496
498
- $ clientEncrypted = new Client ( static ::getUri () , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
497
+ $ clientEncrypted = static ::createTestClient ( null , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
499
498
500
499
try {
501
500
$ clientEncrypted ->selectCollection ('db ' , 'view ' )->insertOne (['foo ' => 'bar ' ]);
@@ -557,7 +556,7 @@ public function testCorpus($schemaMap = true)
557
556
$ corpus = (array ) $ this ->decodeJson (file_get_contents (__DIR__ . '/client-side-encryption/corpus/corpus.json ' ));
558
557
$ corpusCopied = [];
559
558
560
- $ clientEncrypted = new Client ( static ::getUri () , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
559
+ $ clientEncrypted = static ::createTestClient ( null , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
561
560
$ clientEncryption = $ clientEncrypted ->createClientEncryption ($ encryptionOpts );
562
561
563
562
$ collection = $ clientEncrypted ->selectCollection ('db ' , 'coll ' );
@@ -621,7 +620,7 @@ public function testCorpus($schemaMap = true)
621
620
*/
622
621
public function testCustomEndpoint (Closure $ test )
623
622
{
624
- $ client = new Client ( static ::getUri () );
623
+ $ client = static ::createTestClient ( );
625
624
626
625
$ clientEncryption = $ client ->createClientEncryption ([
627
626
'keyVaultNamespace ' => 'keyvault.datakeys ' ,
@@ -758,7 +757,7 @@ public function testBypassSpawningMongocryptdViaBypassSpawn()
758
757
],
759
758
];
760
759
761
- $ clientEncrypted = new Client ( static ::getUri () , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
760
+ $ clientEncrypted = static ::createTestClient ( null , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
762
761
763
762
try {
764
763
$ clientEncrypted ->selectCollection ('db ' , 'coll ' )->insertOne (['encrypted ' => 'test ' ]);
@@ -787,11 +786,11 @@ public function testBypassSpawningMongocryptdViaBypassAutoEncryption()
787
786
],
788
787
];
789
788
790
- $ clientEncrypted = new Client ( static ::getUri () , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
789
+ $ clientEncrypted = static ::createTestClient ( null , [], ['autoEncryption ' => $ autoEncryptionOpts ]);
791
790
792
791
$ clientEncrypted ->selectCollection ('db ' , 'coll ' )->insertOne (['encrypted ' => 'test ' ]);
793
792
794
- $ clientMongocryptd = new Client ('mongodb://localhost:27021 ' );
793
+ $ clientMongocryptd = static :: createTestClient ('mongodb://localhost:27021 ' );
795
794
796
795
$ this ->expectException (ConnectionTimeoutException::class);
797
796
$ clientMongocryptd ->selectDatabase ('db ' )->command (['isMaster ' => true ]);
0 commit comments