function ErrorTestController::generateWarnings

Same name in other branches
  1. 9 core/modules/system/tests/modules/error_test/src/Controller/ErrorTestController.php \Drupal\error_test\Controller\ErrorTestController::generateWarnings()
  2. 8.9.x core/modules/system/tests/modules/error_test/src/Controller/ErrorTestController.php \Drupal\error_test\Controller\ErrorTestController::generateWarnings()
  3. 10 core/modules/system/tests/modules/error_test/src/Controller/ErrorTestController.php \Drupal\error_test\Controller\ErrorTestController::generateWarnings()

Generate warnings to test the error handler.

1 string reference to 'ErrorTestController::generateWarnings'
error_test.routing.yml in core/modules/system/tests/modules/error_test/error_test.routing.yml
core/modules/system/tests/modules/error_test/error_test.routing.yml

File

core/modules/system/tests/modules/error_test/src/Controller/ErrorTestController.php, line 45

Class

ErrorTestController
Controller routines for error_test routes.

Namespace

Drupal\error_test\Controller

Code

public function generateWarnings($collect_errors = FALSE) {
    // Tell Drupal error reporter to collect test errors or not.
    define('SIMPLETEST_COLLECT_ERRORS', $collect_errors);
    // This will generate a notice.
    $notice = new \stdClass();
    $notice == 1 ? 1 : 0;
    // This will generate a warning.
    $obj = new \stdClass();
    $obj->p =& $obj;
    var_export($obj, TRUE);
    // This will generate a user error. Use & to check for double escaping.
    trigger_error("Drupal & awesome", E_USER_WARNING);
    return [];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.