Issue #2599446 by alexpott: UncaughtExceptionTest fails on PHP7
parent
b6072feb46
commit
32a9e1cb2b
|
@ -137,6 +137,7 @@ class UncaughtExceptionTest extends WebTestBase {
|
|||
$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');
|
||||
|
@ -254,7 +255,7 @@ class UncaughtExceptionTest extends WebTestBase {
|
|||
$this->assertIdentical(count($errors), 1, 'Exactly one line logged to the PHP error log');
|
||||
|
||||
$expected_path = \Drupal::root() . '/core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php';
|
||||
$expected_line = 61;
|
||||
$expected_line = 63;
|
||||
$expected_entry = "Failed to log error: Exception: Deforestation in Drupal\\error_service_test\\MonkeysInTheControlRoom->handle() (line ${expected_line} of ${expected_path})";
|
||||
$this->assert(strpos($errors[0], $expected_entry) !== FALSE, 'Original error logged to the PHP error log when an exception is thrown by a logger');
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
services:
|
||||
http_middleware.monkeys:
|
||||
class: Drupal\error_service_test\MonkeysInTheControlRoom
|
||||
arguments: ['@settings']
|
||||
tags:
|
||||
- { name: http_middleware, priority: 400 }
|
||||
# Set up a service with a missing class dependency.
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
namespace Drupal\error_service_test;
|
||||
|
||||
use Drupal\Core\Site\Settings;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
|
@ -29,8 +30,9 @@ class MonkeysInTheControlRoom implements HttpKernelInterface {
|
|||
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $app
|
||||
* The wrapper HTTP kernel.
|
||||
*/
|
||||
public function __construct(HttpKernelInterface $app) {
|
||||
public function __construct(HttpKernelInterface $app, Settings $settings) {
|
||||
$this->app = $app;
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,7 +63,20 @@ class MonkeysInTheControlRoom implements HttpKernelInterface {
|
|||
throw new \Exception('Deforestation');
|
||||
}
|
||||
|
||||
return $this->app->handle($request, $type, $catch);
|
||||
if ($this->settings->get('teapots', FALSE) && class_exists('\TypeError')) {
|
||||
try {
|
||||
$return = $this->app->handle($request, $type, $catch);
|
||||
}
|
||||
catch (\TypeError $e) {
|
||||
header('HTTP/1.1 418 I\'m a teapot');
|
||||
print('Oh oh, flying teapots');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$return = $this->app->handle($request, $type, $catch);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue