Skip to content

Commit 7e72c2c

Browse files
Merge 4.3 into 4.4 (#2978)
2 parents 8979ed9 + 7b8f0a1 commit 7e72c2c

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

.github/labeler.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# https://github.com/actions/labeler
2+
docs:
3+
- changed-files:
4+
- any-glob-to-any-file: 'docs/**'
5+
github:
6+
- changed-files:
7+
- any-glob-to-any-file: '.github/**'

.github/workflows/labeler.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: "Pull Request Labeler"
2+
on:
3+
- pull_request_target
4+
5+
jobs:
6+
labeler:
7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/labeler@v5

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
1212

1313
* Fix memory leak when filling nested fields using dot notation by @GromNaN in [#2962](https://github.com/mongodb/laravel-mongodb/pull/2962)
1414
* Fix PHP error when accessing the connection after disconnect by @SanderMuller in [#2967](https://github.com/mongodb/laravel-mongodb/pull/2967)
15+
* Improve error message for invalid configuration by @GromNaN in [#2975](https://github.com/mongodb/laravel-mongodb/pull/2975)
1516

1617
## [4.3.0] - 2024-04-26
1718

src/Connection.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ public function disconnect()
215215

216216
/**
217217
* Determine if the given configuration array has a dsn string.
218+
*
219+
* @deprecated
218220
*/
219221
protected function hasDsnString(array $config): bool
220222
{
@@ -263,9 +265,15 @@ protected function getHostDsn(array $config): string
263265
*/
264266
protected function getDsn(array $config): string
265267
{
266-
return $this->hasDsnString($config)
267-
? $this->getDsnString($config)
268-
: $this->getHostDsn($config);
268+
if (! empty($config['dsn'])) {
269+
return $this->getDsnString($config);
270+
}
271+
272+
if (! empty($config['host'])) {
273+
return $this->getHostDsn($config);
274+
}
275+
276+
throw new InvalidArgumentException('MongoDB connection configuration requires "dsn" or "host" key.');
269277
}
270278

271279
/** @inheritdoc */

tests/ConnectionTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ public function testConnectionWithoutConfiguredDatabase(): void
206206
new Connection(['dsn' => 'mongodb://some-host']);
207207
}
208208

209+
public function testConnectionWithoutConfiguredDsnOrHost(): void
210+
{
211+
$this->expectException(InvalidArgumentException::class);
212+
$this->expectExceptionMessage('MongoDB connection configuration requires "dsn" or "host" key.');
213+
214+
new Connection(['database' => 'hello']);
215+
}
216+
209217
public function testCollection()
210218
{
211219
$collection = DB::connection('mongodb')->getCollection('unittest');

0 commit comments

Comments
 (0)