public function UncaughtExceptionTest::testMissingDependencyCustomErrorHandler 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::testMissingDependencyCustomErrorHandler()
Tests a missing dependency on a service with a custom error handler.
File
- core/
modules/ system/ src/ Tests/ System/ UncaughtExceptionTest.php, line 132 - Contains \Drupal\system\Tests\System\UncaughtExceptionTest.
Class
- UncaughtExceptionTest
- Tests kernel panic when things are really messed up.
Namespace
Drupal\system\Tests\SystemCode
public function testMissingDependencyCustomErrorHandler() {
$settings_filename = $this->siteDirectory . '/settings.php';
chmod($settings_filename, 0777);
$settings_php = file_get_contents($settings_filename);
$settings_php .= "\n";
$settings_php .= "set_error_handler(function() {\n";
$settings_php .= " header('HTTP/1.1 418 I\\'m a teapot');\n";
$settings_php .= " print('Oh oh, flying teapots');\n";
$settings_php .= " exit();\n";
$settings_php .= "});\n";
$settings_php .= "\$settings['teapots'] = TRUE;\n";
file_put_contents($settings_filename, $settings_php);
$this
->drupalGet('broken-service-class');
$this
->assertResponse(418);
$this
->assertRaw('Oh oh, flying teapots');
$message = 'Argument 1 passed to Drupal\\error_service_test\\LonelyMonkeyClass::__construct() must be an instance of Drupal\\Core\\Database\\Connection, non';
$this
->assertNoRaw('The website encountered an unexpected error.');
$this
->assertNoRaw($message);
$found_exception = FALSE;
foreach ($this->assertions as &$assertion) {
if (strpos($assertion['message'], $message) !== FALSE) {
$found_exception = TRUE;
$this
->deleteAssert($assertion['message_id']);
unset($assertion);
}
}
$this
->assertTrue($found_exception, 'Ensure that the exception of a missing constructor argument was triggered.');
}