1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Tests\Driver\PDO\PgSQL;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\PDO;
use Doctrine\DBAL\Driver\PDO\Exception\InvalidConfiguration;
use Doctrine\DBAL\Driver\PDO\PgSQL\Driver;
use Doctrine\DBAL\Tests\Driver\AbstractPostgreSQLDriverTestCase;
use Doctrine\DBAL\Tests\TestUtil;
use function array_merge;
class DriverTest extends AbstractPostgreSQLDriverTestCase
{
protected function setUp(): void
{
parent::setUp();
if (isset($GLOBALS['db_driver']) && $GLOBALS['db_driver'] === 'pdo_pgsql') {
return;
}
self::markTestSkipped('Test enabled only when using pdo_pgsql specific phpunit.xml');
}
public function testConnectionDisablesPrepares(): void
{
$connection = $this->connect([]);
self::assertInstanceOf(PDO\Connection::class, $connection);
self::assertTrue(
$connection->getNativeConnection()->getAttribute(\PDO::PGSQL_ATTR_DISABLE_PREPARES),
);
}
public function testConnectionDoesNotDisablePreparesWhenAttributeDefined(): void
{
$connection = $this->connect(
[\PDO::PGSQL_ATTR_DISABLE_PREPARES => false],
);
self::assertInstanceOf(PDO\Connection::class, $connection);
self::assertNotTrue(
$connection->getNativeConnection()->getAttribute(\PDO::PGSQL_ATTR_DISABLE_PREPARES),
);
}
public function testConnectionDisablePreparesWhenDisablePreparesIsExplicitlyDefined(): void
{
$connection = $this->connect(
[\PDO::PGSQL_ATTR_DISABLE_PREPARES => true],
);
self::assertInstanceOf(PDO\Connection::class, $connection);
self::assertTrue(
$connection->getNativeConnection()->getAttribute(\PDO::PGSQL_ATTR_DISABLE_PREPARES),
);
}
public function testUserIsFalse(): void
{
$this->expectException(InvalidConfiguration::class);
$this->expectExceptionMessage(
'The user configuration parameter is expected to be either a string or null, got bool.',
);
$this->driver->connect(['user' => false]);
}
public function testPasswordIsFalse(): void
{
$this->expectException(InvalidConfiguration::class);
$this->expectExceptionMessage(
'The password configuration parameter is expected to be either a string or null, got bool.',
);
$this->driver->connect(['password' => false]);
}
protected function createDriver(): Driver
{
return new Driver();
}
/** @param array<int,mixed> $driverOptions */
private function connect(array $driverOptions): Connection
{
return $this->createDriver()->connect(
array_merge(
TestUtil::getConnectionParams(),
['driverOptions' => $driverOptions],
),
);
}
}
|