ErrorTestController.php in Drupal 10
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);
$notice = new \stdClass();
$notice == 1 ? 1 : 0;
$obj = new \stdClass();
$obj->p =& $obj;
var_export($obj, TRUE);
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
->select('bananas_are_awesome', 'b')
->fields('b')
->execute();
}
public function triggerRendererException() {
return [
'#type' => 'page',
'#post_render' => [
function () {
throw new \Exception('This is an exception that occurs during rendering');
},
],
];
}
}