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
4 changes: 4 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ protected function createConnection(string $dsn, array $config, array $options):
$options['password'] = $config['password'];
}

if (isset($config['name'])) {
$driverOptions += ['connectionName' => $config['name']];
}

return new Client($dsn, $options, $driverOptions);
}

Expand Down
28 changes: 28 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,34 @@ public function testQueryLog()
}
}

public function testQueryLogWithMultipleClients()
{
$connection = DB::connection('mongodb');
$this->assertInstanceOf(Connection::class, $connection);

// Create a second connection with the same config as the first
// Make sure to change the name as it's used as a connection identifier
$config = $connection->getConfig();
$config['name'] = 'mongodb2';
$secondConnection = new Connection($config);

$connection->enableQueryLog();
$secondConnection->enableQueryLog();

$this->assertCount(0, $connection->getQueryLog());
$this->assertCount(0, $secondConnection->getQueryLog());

$connection->table('items')->get();

$this->assertCount(1, $connection->getQueryLog());
$this->assertCount(0, $secondConnection->getQueryLog());

$secondConnection->table('items')->get();

$this->assertCount(1, $connection->getQueryLog());
$this->assertCount(1, $secondConnection->getQueryLog());
}

public function testDisableQueryLog()
{
// Disabled by default
Expand Down