File tree 3 files changed +20
-3
lines changed
3 files changed +20
-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 @@ -213,6 +213,8 @@ public function disconnect()
213
213
214
214
/**
215
215
* Determine if the given configuration array has a dsn string.
216
+ *
217
+ * @deprecated
216
218
*/
217
219
protected function hasDsnString (array $ config ): bool
218
220
{
@@ -261,9 +263,15 @@ protected function getHostDsn(array $config): string
261
263
*/
262
264
protected function getDsn (array $ config ): string
263
265
{
264
- return $ this ->hasDsnString ($ config )
265
- ? $ this ->getDsnString ($ config )
266
- : $ this ->getHostDsn ($ config );
266
+ if (! empty ($ config ['dsn ' ])) {
267
+ return $ this ->getDsnString ($ config );
268
+ }
269
+
270
+ if (! empty ($ config ['host ' ])) {
271
+ return $ this ->getHostDsn ($ config );
272
+ }
273
+
274
+ throw new InvalidArgumentException ('MongoDB connection configuration requires "dsn" or "host" key. ' );
267
275
}
268
276
269
277
/** @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