// If the test is not a PHPUnit test, and either we don't have the
// Simpletest module or the \Drupal\simpletest\TestBase class available.
else {
simpletest_script_print_error(sprintf('Can not run %s. If this is a WebTestBase test the simpletest module must be installed. See https://www.drupal.org/node/3030340', $test_class));
$status = SIMPLETEST_SCRIPT_EXIT_FAILURE;
}
exit($status);
}
// DrupalTestCase::run() catches exceptions already, so this is only reached
@@ -905,112 +860,6 @@ function simpletest_script_command($test_id, $test_class) {
return$command;
}
/**
* Removes all remnants of a test runner.
*
* In case a fatal error occurs after the test site has been fully setup and
* the error happens in many tests, the environment that executes the tests can
* easily run out of memory or disk space. This function ensures that all
* created resources are properly cleaned up after every executed test.
*
* This clean-up only exists in this script, since SimpleTest module itself does
* not use isolated sub-processes for each test being run, so a fatal error
* halts not only the test, but also the test runner (i.e., the parent site).
*
* @param int $test_id
* The test ID of the test run.
* @param string $test_class
* The class name of the test run.
* @param int $exitcode
* The exit code of the test runner.
*
* @see simpletest_script_run_one_test()
*/
function simpletest_script_cleanup($test_id, $test_class, $exitcode) {
if (is_subclass_of($test_class, TestCase::class)) {
// PHPUnit test, move on.
return;
}
// Retrieve the last database prefix used for testing.
try {
$last_test = TestDatabase::lastTestGet($test_id);
$db_prefix = $last_test['last_prefix'];
}
catch (Exception $e) {
echo (string) $e;
exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION);
}
// If no database prefix was found, then the test was not set up correctly.
if (empty($db_prefix)) {
echo "\nFATAL $test_class: Found no database prefix for test ID $test_id. (Check whether setUp() is invoked correctly.)";
return;
}
// Do not output verbose cleanup messages in case of a positive exitcode.
$output = !empty($exitcode);
$messages = [];
$messages[] = "- Found database prefix '$db_prefix' for test ID $test_id.";
// Read the log file in case any fatal errors caused the test to crash.
try {
(new TestDatabase($db_prefix))->logRead($test_id, $last_test['test_class']);
}
catch (Exception $e) {
echo (string) $e;
exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION);
}
// Check whether a test site directory was setup already.