File tree 2 files changed +17
-3
lines changed
2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -261,9 +261,15 @@ protected function getHostDsn(array $config): string
261
261
*/
262
262
protected function getDsn (array $ config ): string
263
263
{
264
- return $ this ->hasDsnString ($ config )
265
- ? $ this ->getDsnString ($ config )
266
- : $ this ->getHostDsn ($ config );
264
+ if (! empty ($ config ['dsn ' ])) {
265
+ return $ this ->getDsnString ($ config );
266
+ }
267
+
268
+ if (! empty ($ config ['host ' ])) {
269
+ return $ this ->getHostDsn ($ config );
270
+ }
271
+
272
+ throw new InvalidArgumentException ('MongoDB connection configuration requires "dsn" or "host" key. ' );
267
273
}
268
274
269
275
/** @inheritdoc */
Original file line number Diff line number Diff line change @@ -204,6 +204,14 @@ public function testConnectionWithoutConfiguredDatabase(): void
204
204
new Connection (['dsn ' => 'mongodb://some-host ' ]);
205
205
}
206
206
207
+ public function testConnectionWithoutConfiguredDsnOrHost (): void
208
+ {
209
+ $ this ->expectException (InvalidArgumentException::class);
210
+ $ this ->expectExceptionMessage ('MongoDB connection configuration requires "dsn" or "host" key. ' );
211
+
212
+ new Connection (['database ' => 'hello ' ]);
213
+ }
214
+
207
215
public function testCollection ()
208
216
{
209
217
$ collection = DB ::connection ('mongodb ' )->getCollection ('unittest ' );
You can’t perform that action at this time.
0 commit comments