public function UncaughtExceptionTest::testLostDatabaseConnection in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/System/UncaughtExceptionTest.php \Drupal\system\Tests\System\UncaughtExceptionTest::testLostDatabaseConnection()
Tests the case when the database connection is gone.
File
- core/
modules/ system/ src/ Tests/ System/ UncaughtExceptionTest.php, line 211 - Contains \Drupal\system\Tests\System\UncaughtExceptionTest.
Class
- UncaughtExceptionTest
- Tests kernel panic when things are really messed up.
Namespace
Drupal\system\Tests\SystemCode
public function testLostDatabaseConnection() {
$incorrect_username = $this
->randomMachineName(16);
switch ($this->container
->get('database')
->driver()) {
case 'pgsql':
case 'mysql':
$this->expectedExceptionMessage = $incorrect_username;
break;
default:
// We can not carry out this test.
$this
->pass('Unable to run \\Drupal\\system\\Tests\\System\\UncaughtExceptionTest::testLostDatabaseConnection for this database type.');
return;
}
// We simulate a broken database connection by rewrite settings.php to no
// longer have the proper data.
$settings['databases']['default']['default']['username'] = (object) array(
'value' => $incorrect_username,
'required' => TRUE,
);
$settings['databases']['default']['default']['passowrd'] = (object) array(
'value' => $this
->randomMachineName(16),
'required' => TRUE,
);
$this
->writeSettings($settings);
$this
->drupalGet('');
$this
->assertResponse(500);
$this
->assertRaw('PDOException');
$this
->assertErrorLogged($this->expectedExceptionMessage);
}