function DriverSpecificConnectionUnitTestBase::testConnectionOpen

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/DriverSpecificConnectionUnitTestBase.php \Drupal\KernelTests\Core\Database\DriverSpecificConnectionUnitTestBase::testConnectionOpen()
  2. 11.x core/tests/Drupal/KernelTests/Core/Database/DriverSpecificConnectionUnitTestBase.php \Drupal\KernelTests\Core\Database\DriverSpecificConnectionUnitTestBase::testConnectionOpen()

Tests pdo options override.

File

core/tests/Drupal/KernelTests/Core/Database/DriverSpecificConnectionUnitTestBase.php, line 181

Class

DriverSpecificConnectionUnitTestBase
Tests management of database connections.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testConnectionOpen() : void {
    $reflection = new \ReflectionObject($this->connection);
    $connection_property = $reflection->getProperty('connection');
    $error_mode = $connection_property->getValue($this->connection)
        ->getAttribute(\PDO::ATTR_ERRMODE);
    // Ensure the default error mode is set to exception.
    $this->assertSame(\PDO::ERRMODE_EXCEPTION, $error_mode);
    $connection_info = Database::getConnectionInfo();
    $connection_info['default']['pdo'][\PDO::ATTR_ERRMODE] = \PDO::ERRMODE_SILENT;
    Database::addConnectionInfo('test', 'default', $connection_info['default']);
    $test_connection = Database::getConnection('default', 'test');
    $reflection = new \ReflectionObject($test_connection);
    $connection_property = $reflection->getProperty('connection');
    $error_mode = $connection_property->getValue($test_connection)
        ->getAttribute(\PDO::ATTR_ERRMODE);
    // Ensure PDO connection options can be overridden.
    $this->assertSame(\PDO::ERRMODE_SILENT, $error_mode);
    Database::removeConnection('test');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.