Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions src/Jenssegers/Mongodb/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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'];
}

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/DsnTest.php
Original file line number Diff line number Diff line change
@@ -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';
}
1 change: 1 addition & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 6 additions & 0 deletions tests/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
'database' => 'unittest',
],

'dsn_mongodb' => [
'driver' => 'mongodb',
'dsn' => 'mongodb://mongodb:27017',
'database' => 'unittest',
],

'mysql' => [
'driver' => 'mysql',
'host' => 'mysql',
Expand Down