File tree Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
5
5
6
6
* Fix memory leak when filling nested fields using dot notation by @GromNaN in [ #2962 ] ( https://github.com/mongodb/laravel-mongodb/pull/2962 )
7
7
* Fix PHP error when accessing the connection after disconnect by @SanderMuller in [ #2967 ] ( https://github.com/mongodb/laravel-mongodb/pull/2967 )
8
+ * Improve error message for invalid configuration by @GromNaN in [ #2975 ] ( https://github.com/mongodb/laravel-mongodb/pull/2975 )
8
9
9
10
## [ 4.3.0] - 2024-04-26
10
11
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