File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change 23
23
"illuminate/container" : " ^5.8|^6.0" ,
24
24
"illuminate/database" : " ^5.8|^6.0" ,
25
25
"illuminate/events" : " ^5.8|^6.0" ,
26
- "mongodb/mongodb" : " ^1.4" ,
27
- "cedx/coveralls" : " ^11.2"
26
+ "mongodb/mongodb" : " ^1.4"
28
27
},
29
28
"require-dev" : {
30
29
"phpunit/phpunit" : " ^6.0|^7.0|^8.0" ,
31
30
"orchestra/testbench" : " ^3.1|^4.0" ,
32
31
"mockery/mockery" : " ^1.0" ,
33
32
"doctrine/dbal" : " ^2.5" ,
34
- "phpunit/phpcov" : " ^6.0"
33
+ "phpunit/phpcov" : " ^6.0" ,
34
+ "cedx/coveralls" : " ^11.2"
35
35
},
36
36
"autoload" : {
37
37
"psr-0" : {
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ public function __construct(array $config)
38
38
$ this ->connection = $ this ->createConnection ($ dsn , $ config , $ options );
39
39
40
40
// Select database
41
- $ this ->db = $ this ->connection ->selectDatabase ($ config ['database ' ]);
41
+ $ this ->db = $ this ->connection ->selectDatabase ($ this -> getDatabaseDsn ( $ dsn , $ config ['database ' ]) );
42
42
43
43
$ this ->useDefaultPostProcessor ();
44
44
@@ -188,10 +188,21 @@ protected function getHostDsn(array $config)
188
188
189
189
// Check if we want to authenticate against a specific database.
190
190
$ auth_database = isset ($ config ['options ' ]) && !empty ($ config ['options ' ]['database ' ]) ? $ config ['options ' ]['database ' ] : null ;
191
-
192
191
return 'mongodb:// ' . implode (', ' , $ hosts ) . ($ auth_database ? '/ ' . $ auth_database : '' );
193
192
}
194
193
194
+ /**
195
+ * Get database name from DSN string, if there is no database in DSN path - returns back $database argument.
196
+ * @param string $dsn
197
+ * @param $database
198
+ * @return string
199
+ */
200
+ protected function getDatabaseDsn ($ dsn , $ database )
201
+ {
202
+ $ dsnDatabase = trim (parse_url ($ dsn , PHP_URL_PATH ), '/ ' );
203
+ return trim ($ dsnDatabase ) ? $ dsnDatabase : $ database ;
204
+ }
205
+
195
206
/**
196
207
* Create a DSN string from a configuration.
197
208
* @param array $config
You can’t perform that action at this time.
0 commit comments