Skip to content
Snippets Groups Projects
Commit 7e6fdd85 authored by Angie Byron's avatar Angie Byron
Browse files

#560646 by carlos8f and chx: Make SimpleTest catch Fatal PHP errors.

parent c3def18f
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -148,7 +148,11 @@ protected function assert($status, $message = '', $group = 'Other', array $calle
* the method behaves just like DrupalTestCase::assert() in terms of storing
* the assertion.
*
* @return
* Message ID of the stored assertion.
*
* @see DrupalTestCase::assert()
* @see DrupalTestCase::deleteAssert()
*/
public static function insertAssert($test_id, $test_class, $status, $message = '', $group = 'Other', array $caller = array()) {
// Convert boolean status to string status.
......@@ -173,11 +177,27 @@ public static function insertAssert($test_id, $test_class, $status, $message = '
'file' => $caller['file'],
);
db_insert('simpletest')
return db_insert('simpletest')
->fields($assertion)
->execute();
}
/**
* Delete an assertion record by message ID.
*
* @param $message_id
* Message ID of the assertion to delete.
* @return
* TRUE if the assertion was deleted, FALSE otherwise.
*
* @see DrupalTestCase::insertAssert()
*/
public static function deleteAssert($message_id) {
return (bool) db_delete('simpletest')
->condition('message_id', $message_id)
->execute();
}
/**
* Cycles through backtrace until the first non-assertion method is found.
*
......@@ -402,11 +422,20 @@ public function run() {
}
set_error_handler(array($this, 'errorHandler'));
$methods = array();
$class = get_class($this);
// Iterate through all the methods in this class.
foreach (get_class_methods(get_class($this)) as $method) {
foreach (get_class_methods($class) as $method) {
// If the current method starts with "test", run it - it's a test.
if (strtolower(substr($method, 0, 4)) == 'test') {
// Insert a fail record. This will be deleted on completion to ensure
// that testing completed.
$method_info = new ReflectionMethod($class, $method);
$caller = array(
'file' => $method_info->getFileName(),
'line' => $method_info->getStartLine(),
'function' => $class . '->' . $method . '()',
);
$completion_check_id = DrupalTestCase::insertAssert($this->testId, $class, FALSE, t('The test did not complete due to a fatal error.'), 'Completion check', $caller);
$this->setUp();
try {
$this->$method();
......@@ -416,6 +445,8 @@ public function run() {
$this->exceptionHandler($e);
}
$this->tearDown();
// Remove the completion check record.
DrupalTestCase::deleteAssert($completion_check_id);
}
}
// Clear out the error messages and restore error handler.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment