@@ -69,12 +69,20 @@ public function tearDown(): void
69
69
70
70
public static function createTestClient (?string $ uri = null , array $ options = [], array $ driverOptions = []): Client
71
71
{
72
- return new Client ($ uri ?? static ::getUri (), $ options , static ::appendServerApiOption ($ driverOptions ));
72
+ return new Client (
73
+ $ uri ?? static ::getUri (),
74
+ static ::appendAuthenticationOptions ($ options ),
75
+ static ::appendServerApiOption ($ driverOptions )
76
+ );
73
77
}
74
78
75
79
public static function createTestManager (?string $ uri = null , array $ options = [], array $ driverOptions = []): Manager
76
80
{
77
- return new Manager ($ uri ?? static ::getUri (), $ options , static ::appendServerApiOption ($ driverOptions ));
81
+ return new Manager (
82
+ $ uri ?? static ::getUri (),
83
+ static ::appendAuthenticationOptions ($ options ),
84
+ static ::appendServerApiOption ($ driverOptions )
85
+ );
78
86
}
79
87
80
88
public static function getUri ($ allowMultipleMongoses = false ): string
@@ -513,6 +521,26 @@ protected function skipIfTransactionsAreNotSupported(): void
513
521
}
514
522
}
515
523
524
+ private static function appendAuthenticationOptions (array $ options ): array
525
+ {
526
+ if (isset ($ options ['username ' ]) || isset ($ options ['password ' ])) {
527
+ return $ options ;
528
+ }
529
+
530
+ $ username = getenv ('MONGODB_USERNAME ' ) ?: null ;
531
+ $ password = getenv ('MONGODB_PASSWORD ' ) ?: null ;
532
+
533
+ if ($ username !== null ) {
534
+ $ options ['username ' ] = $ username ;
535
+ }
536
+
537
+ if ($ password !== null ) {
538
+ $ options ['password ' ] = $ password ;
539
+ }
540
+
541
+ return $ options ;
542
+ }
543
+
516
544
private static function appendServerApiOption (array $ driverOptions ): array
517
545
{
518
546
if (getenv ('API_VERSION ' ) && ! isset ($ driverOptions ['serverApi ' ])) {
0 commit comments