Skip to content

Commit aca8ac0

Browse files
committed
fix dsn config when not unix socket
1 parent 7445ea6 commit aca8ac0

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

src/Jenssegers/Mongodb/Connection.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function disconnect()
151151
}
152152

153153
/**
154-
* Determine if the given configuration array has a UNIX socket value.
154+
* Determine if the given configuration array has a dsn string.
155155
*
156156
* @param array $config
157157
* @return bool
@@ -162,22 +162,14 @@ protected function hasDsnString(array $config)
162162
}
163163

164164
/**
165-
* Get the DSN string for a socket configuration.
165+
* Get the DSN string form configuration.
166166
*
167167
* @param array $config
168168
* @return string
169169
*/
170170
protected function getDsnString(array $config)
171171
{
172-
$dsn_string = $config['dsn'];
173-
174-
if (Str::contains($dsn_string, 'mongodb://')) {
175-
$dsn_string = Str::replaceFirst('mongodb://', '', $dsn_string);
176-
}
177-
178-
$dsn_string = rawurlencode($dsn_string);
179-
180-
return "mongodb://{$dsn_string}";
172+
return $config['dsn'];
181173
}
182174

183175
/**

tests/DsnTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
class DsnTest extends TestCase
4+
{
5+
public function test_dsn_works()
6+
{
7+
$this->assertInstanceOf(\Illuminate\Database\Eloquent\Collection::class, DsnAddress::all());
8+
}
9+
}
10+
11+
class DsnAddress extends Address
12+
{
13+
protected $connection = 'dsn_mongodb';
14+
}

tests/TestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ protected function getEnvironmentSetUp($app)
5151
$app['config']->set('database.default', 'mongodb');
5252
$app['config']->set('database.connections.mysql', $config['connections']['mysql']);
5353
$app['config']->set('database.connections.mongodb', $config['connections']['mongodb']);
54+
$app['config']->set('database.connections.dsn_mongodb', $config['connections']['dsn_mongodb']);
5455

5556
$app['config']->set('auth.model', 'User');
5657
$app['config']->set('auth.providers.users.model', 'User');

tests/config/database.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
'database' => 'unittest',
1212
],
1313

14+
'dsn_mongodb' => [
15+
'driver' => 'mongodb',
16+
'dsn' => 'mongodb://mongodb:27017',
17+
'database' => 'unittest',
18+
],
19+
1420
'mysql' => [
1521
'driver' => 'mysql',
1622
'host' => 'mysql',

0 commit comments

Comments
 (0)