From 0e693886f2f59c0eae154ad175de08be928e656a Mon Sep 17 00:00:00 2001 From: Hamid Alaei V Date: Thu, 8 Mar 2018 13:48:54 +0330 Subject: [PATCH] fix dsn config when not unix socket --- src/Jenssegers/Mongodb/Connection.php | 15 +++------------ tests/DsnTest.php | 14 ++++++++++++++ tests/TestCase.php | 1 + tests/config/database.php | 6 ++++++ 4 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 tests/DsnTest.php diff --git a/src/Jenssegers/Mongodb/Connection.php b/src/Jenssegers/Mongodb/Connection.php index bbc5c437c..7276155a6 100644 --- a/src/Jenssegers/Mongodb/Connection.php +++ b/src/Jenssegers/Mongodb/Connection.php @@ -4,7 +4,6 @@ use Illuminate\Database\Connection as BaseConnection; use Illuminate\Support\Arr; -use Illuminate\Support\Str; use MongoDB\Client; class Connection extends BaseConnection @@ -151,7 +150,7 @@ public function disconnect() } /** - * Determine if the given configuration array has a UNIX socket value. + * Determine if the given configuration array has a dsn string. * * @param array $config * @return bool @@ -162,22 +161,14 @@ protected function hasDsnString(array $config) } /** - * Get the DSN string for a socket configuration. + * Get the DSN string form configuration. * * @param array $config * @return string */ protected function getDsnString(array $config) { - $dsn_string = $config['dsn']; - - if (Str::contains($dsn_string, 'mongodb://')) { - $dsn_string = Str::replaceFirst('mongodb://', '', $dsn_string); - } - - $dsn_string = rawurlencode($dsn_string); - - return "mongodb://{$dsn_string}"; + return $config['dsn']; } /** diff --git a/tests/DsnTest.php b/tests/DsnTest.php new file mode 100644 index 000000000..08fa0a8aa --- /dev/null +++ b/tests/DsnTest.php @@ -0,0 +1,14 @@ +assertInstanceOf(\Illuminate\Database\Eloquent\Collection::class, DsnAddress::all()); + } +} + +class DsnAddress extends Address +{ + protected $connection = 'dsn_mongodb'; +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 13988623b..f4b26be2d 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -51,6 +51,7 @@ protected function getEnvironmentSetUp($app) $app['config']->set('database.default', 'mongodb'); $app['config']->set('database.connections.mysql', $config['connections']['mysql']); $app['config']->set('database.connections.mongodb', $config['connections']['mongodb']); + $app['config']->set('database.connections.dsn_mongodb', $config['connections']['dsn_mongodb']); $app['config']->set('auth.model', 'User'); $app['config']->set('auth.providers.users.model', 'User'); diff --git a/tests/config/database.php b/tests/config/database.php index 1986807a3..f24d20d2f 100644 --- a/tests/config/database.php +++ b/tests/config/database.php @@ -11,6 +11,12 @@ 'database' => 'unittest', ], + 'dsn_mongodb' => [ + 'driver' => 'mongodb', + 'dsn' => 'mongodb://mongodb:27017', + 'database' => 'unittest', + ], + 'mysql' => [ 'driver' => 'mysql', 'host' => 'mysql',