mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 08:22:07 +02:00
MDL-38041 behat: Capturing also PHP debug messages
This commit is contained in:
parent
5f4b4e918d
commit
90ed22ab70
@ -70,3 +70,60 @@ function behat_error($errorcode, $text = '') {
|
||||
testing_error($errorcode, $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP errors handler to use when running behat tests.
|
||||
*
|
||||
* Adds specific CSS classes to identify
|
||||
* the messages.
|
||||
*
|
||||
* @param int $errno
|
||||
* @param string $errstr
|
||||
* @param string $errfile
|
||||
* @param int $errline
|
||||
* @param array $errcontext
|
||||
* @return bool
|
||||
*/
|
||||
function behat_error_handler($errno, $errstr, $errfile, $errline, $errcontext) {
|
||||
global $OUTPUT;
|
||||
|
||||
// Only after something has been writen.
|
||||
if (!$OUTPUT->has_started()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If is preceded by an @ we don't show it.
|
||||
if (!error_reporting()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Using the default one in case there is a fatal catchable error.
|
||||
default_error_handler($errno, $errstr, $errfile, $errline, $errcontext);
|
||||
|
||||
switch ($errno) {
|
||||
case E_USER_ERROR:
|
||||
$errnostr = 'Fatal error';
|
||||
break;
|
||||
case E_WARNING:
|
||||
case E_USER_WARNING:
|
||||
$errnostr = 'Warning';
|
||||
break;
|
||||
case E_NOTICE:
|
||||
case E_USER_NOTICE:
|
||||
case E_STRICT:
|
||||
$errnostr = 'Notice';
|
||||
break;
|
||||
case E_RECOVERABLE_ERROR:
|
||||
$errnostr = 'Catchable';
|
||||
break;
|
||||
default:
|
||||
$errnostr = 'Unknown error type';
|
||||
}
|
||||
|
||||
// Wrapping the output.
|
||||
echo '<div class="phpdebugmessage">' . PHP_EOL;
|
||||
echo "$errnostr: $errstr in $errfile on line $errline" . PHP_EOL;
|
||||
echo '</div>';
|
||||
|
||||
// Also use the internal error handler so we keep the usual behaviour.
|
||||
return false;
|
||||
}
|
||||
|
@ -455,6 +455,12 @@ if (!PHPUNIT_TEST or PHPUNIT_UTIL) {
|
||||
set_error_handler('default_error_handler', E_ALL | E_STRICT);
|
||||
}
|
||||
|
||||
// Acceptance tests needs special output to capture the errors.
|
||||
if (!empty($CFG->originaldataroot) && !defined('BEHAT_RUNNING')) {
|
||||
require_once(__DIR__ . '/behat/lib.php');
|
||||
set_error_handler('behat_error_handler', E_ALL | E_STRICT);
|
||||
}
|
||||
|
||||
// If there are any errors in the standard libraries we want to know!
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
|
||||
|
@ -192,11 +192,6 @@ class behat_hooks extends behat_base {
|
||||
*/
|
||||
public function i_look_for_exceptions() {
|
||||
|
||||
// No need for checking if there is no UI.
|
||||
if (!$this->getSession()->getPage()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Exceptions.
|
||||
if ($errormsg = $this->getSession()->getPage()->find('css', '.errorbox p.errormessage')) {
|
||||
|
||||
@ -218,6 +213,17 @@ class behat_hooks extends behat_base {
|
||||
$msg = "debugging() message/s found:\n" . implode("\n", $msgs);
|
||||
throw new \Exception(html_entity_decode($msg));
|
||||
}
|
||||
|
||||
// PHP debug messages.
|
||||
if ($phpmessages = $this->getSession()->getPage()->findAll('css', '.phpdebugmessage')) {
|
||||
|
||||
$msgs = array();
|
||||
foreach ($phpmessages as $phpmessage) {
|
||||
$msgs[] = $this->get_debug_text($phpmessage->getHtml());
|
||||
}
|
||||
$msg = "PHP debug message/s found:\n" . implode("\n", $msgs);
|
||||
throw new \Exception(html_entity_decode($msg));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user