summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-12-14 19:24:10 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-12-14 19:24:10 +0000
commit7e6fdd8540f0bddb68cc303ae769f043a6aea16d (patch)
tree6f78088a1348b8902234278170fc89012e7b3e69
parentc3def18f3a6e4a8640819fa13e3f46e862a0bbcb (diff)
downloadbrdo-7e6fdd8540f0bddb68cc303ae769f043a6aea16d.tar.gz
brdo-7e6fdd8540f0bddb68cc303ae769f043a6aea16d.tar.bz2
#560646 by carlos8f and chx: Make SimpleTest catch Fatal PHP errors.
-rw-r--r--modules/simpletest/drupal_web_test_case.php37
1 files changed, 34 insertions, 3 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 646eb64b4..3c4a2396c 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -148,7 +148,11 @@ abstract class DrupalTestCase {
* 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,12 +177,28 @@ abstract class DrupalTestCase {
'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.
*
* @return
@@ -402,11 +422,20 @@ abstract class DrupalTestCase {
}
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 @@ abstract class DrupalTestCase {
$this->exceptionHandler($e);
}
$this->tearDown();
+ // Remove the completion check record.
+ DrupalTestCase::deleteAssert($completion_check_id);
}
}
// Clear out the error messages and restore error handler.