You are here

public function ConnectionUnitTest::testConnectionOpen in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Database/ConnectionUnitTest.php \Drupal\system\Tests\Database\ConnectionUnitTest::testConnectionOpen()

Tests pdo options override.

File

core/modules/system/src/Tests/Database/ConnectionUnitTest.php, line 224
Contains \Drupal\system\Tests\Database\ConnectionUnitTest.

Class

ConnectionUnitTest
Tests management of database connections.

Namespace

Drupal\system\Tests\Database

Code

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