ErrorTestController.php in Zircon Profile 8.0
File
core/modules/system/tests/modules/error_test/src/Controller/ErrorTestController.php
View source
<?php
namespace Drupal\error_test\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Database\Connection;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ErrorTestController extends ControllerBase {
protected $database;
public function __construct(Connection $database) {
$this->database = $database;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('database'));
}
public function generateWarnings($collect_errors = FALSE) {
define('SIMPLETEST_COLLECT_ERRORS', $collect_errors);
$monkey_love = $bananas;
$awesomely_big = 1 / 0;
trigger_error("Drupal & awesome", E_USER_WARNING);
return [];
}
public function generateFatals() {
$function = function (array $test) {
};
$function("test-string");
return [];
}
public function triggerException() {
define('SIMPLETEST_COLLECT_ERRORS', FALSE);
throw new \Exception("Drupal & awesome");
}
public function triggerPDOException() {
define('SIMPLETEST_COLLECT_ERRORS', FALSE);
$this->database
->query('SELECT * FROM bananas_are_awesome');
}
public function triggerRendererException() {
return [
'#type' => 'page',
'#post_render' => [
function () {
throw new \Exception('This is an exception that occurs during rendering');
},
],
];
}
}