diff --git a/src/Jenssegers/Mongodb/Connection.php b/src/Jenssegers/Mongodb/Connection.php index bbc5c437c6effcd326448c05478fca97f6a00ea0..7276155a622a288906e4b7304d0e9a2100981676 100644 --- a/src/Jenssegers/Mongodb/Connection.php +++ b/src/Jenssegers/Mongodb/Connection.php @@ -4,7 +4,6 @@ namespace Jenssegers\Mongodb; 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 @@ class Connection extends BaseConnection } /** - * 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 @@ class Connection extends BaseConnection } /** - * 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 0000000000000000000000000000000000000000..08fa0a8aab66de6c27e8479329dcec261c16cd2b --- /dev/null +++ b/tests/DsnTest.php @@ -0,0 +1,14 @@ +<?php + +class DsnTest extends TestCase +{ + public function test_dsn_works() + { + $this->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 13988623b53ce64abb6a8025f2bc843ab3fb6e6c..f4b26be2d01d5ca365a9c4e61404e7f5fc19d554 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -51,6 +51,7 @@ class TestCase extends Orchestra\Testbench\TestCase $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 1986807a3a39fd8a457b067fd4ffa3a9b0eddc37..f24d20d2fca04cec69574c07d2472f512baa3377 100644 --- a/tests/config/database.php +++ b/tests/config/database.php @@ -11,6 +11,12 @@ return [ 'database' => 'unittest', ], + 'dsn_mongodb' => [ + 'driver' => 'mongodb', + 'dsn' => 'mongodb://mongodb:27017', + 'database' => 'unittest', + ], + 'mysql' => [ 'driver' => 'mysql', 'host' => 'mysql',