Skip to content

Commit

Permalink
Remove redundant dbname=postgres PostgreSQL DSN
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Sep 29, 2022
1 parent 13f6f4f commit 5e8928a
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 60 deletions.
2 changes: 0 additions & 2 deletions docs/en/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ pdo_pgsql
- ``dbname`` (string): Name of the database/schema to connect to.
- ``charset`` (string): The charset used when connecting to the
database.
- ``default_dbname`` (string): Override the default database (postgres)
to connect to.
- ``sslmode`` (string): Determines whether or with what priority
a SSL TCP/IP connection will be negotiated with the server.
See the list of available modes:
Expand Down
7 changes: 0 additions & 7 deletions src/Driver/PDO/PgSQL/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ private function constructPdoDsn(array $params): string

if (isset($params['dbname'])) {
$dsn .= 'dbname=' . $params['dbname'] . ';';
} elseif (isset($params['default_dbname'])) {
$dsn .= 'dbname=' . $params['default_dbname'] . ';';
} else {
// Used for temporary connections to allow operations like dropping the database currently connected to.
// Connecting without an explicit database does not work, therefore "postgres" database is used
// as it is mostly present in every server setup.
$dsn .= 'dbname=postgres;';
}

if (isset($params['sslmode'])) {
Expand Down
3 changes: 0 additions & 3 deletions src/DriverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
* @psalm-type OverrideParams = array{
* charset?: string,
* dbname?: string,
* default_dbname?: string,
* driver?: key-of<self::DRIVER_MAP>,
* driverClass?: class-string<Driver>,
* driverOptions?: array<mixed>,
Expand All @@ -51,7 +50,6 @@
* charset?: string,
* dbname?: string,
* defaultTableOptions?: array<string, mixed>,
* default_dbname?: string,
* driver?: key-of<self::DRIVER_MAP>,
* driverClass?: class-string<Driver>,
* driverOptions?: array<mixed>,
Expand Down Expand Up @@ -137,7 +135,6 @@ private function __construct()
* @psalm-param array{
* charset?: string,
* dbname?: string,
* default_dbname?: string,
* driver?: key-of<self::DRIVER_MAP>,
* driverClass?: class-string<Driver>,
* driverOptions?: array<mixed>,
Expand Down
48 changes: 0 additions & 48 deletions tests/Functional/Driver/PDO/PgSQL/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Doctrine\DBAL\Tests\Functional\Driver\PDO\PgSQL;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver as DriverInterface;
use Doctrine\DBAL\Driver\PDO\PgSQL\Driver;
use Doctrine\DBAL\Tests\Functional\Driver\AbstractDriverTest;
Expand All @@ -28,53 +27,6 @@ protected function setUp(): void
self::markTestSkipped('This test requires the pdo_pgsql driver.');
}

/** @dataProvider getDatabaseParameter */
public function testDatabaseParameters(
?string $databaseName,
?string $defaultDatabaseName,
?string $expectedDatabaseName,
): void {
$params = $this->connection->getParams();

if ($databaseName !== null) {
$params['dbname'] = $databaseName;
} else {
unset($params['dbname']);
}

if ($defaultDatabaseName !== null) {
$params['default_dbname'] = $defaultDatabaseName;
}

$connection = new Connection(
$params,
$this->connection->getDriver(),
$this->connection->getConfiguration(),
$this->connection->getEventManager(),
);

self::assertSame(
$expectedDatabaseName,
$connection->getDatabase(),
);
}

/** @return mixed[][] */
public static function getDatabaseParameter(): iterable
{
$params = TestUtil::getConnectionParams();
$realDatabaseName = $params['dbname'] ?? '';
$dummyDatabaseName = $realDatabaseName . 'a';

return [
// dbname, default_dbname, expected
[$realDatabaseName, null, $realDatabaseName],
[$realDatabaseName, $dummyDatabaseName, $realDatabaseName],
[null, $realDatabaseName, $realDatabaseName],
[null, null, static::getDatabaseNameForConnectionWithoutDatabaseNameParameter()],
];
}

public function testConnectsWithApplicationNameParameter(): void
{
$parameters = $this->connection->getParams();
Expand Down

0 comments on commit 5e8928a

Please sign in to comment.