Commit 8426bf5f authored by catch's avatar catch

Issue #3056877 by alexpott, Lendude: Remove usage of TestBase static functions...

Issue #3056877 by alexpott, Lendude: Remove usage of TestBase static functions because they are deprecated
parent f4bf1ae0
......@@ -11,7 +11,6 @@
use Drupal\Core\File\Exception\FileException;
use Drupal\Core\Render\Element;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\simpletest\TestBase;
use Drupal\Core\Test\TestDatabase;
use Drupal\simpletest\TestDiscovery;
use Drupal\Tests\Listeners\SimpletestUiPrinter;
......@@ -552,11 +551,11 @@ function simpletest_log_read($test_id, $database_prefix, $test_class) {
'line' => $match[4],
'file' => $match[3],
];
TestBase::insertAssert($test_id, $test_class, FALSE, $match[2], $match[1], $caller);
simpletest_insert_assert($test_id, $test_class, FALSE, $match[2], $match[1], $caller);
}
else {
// Unknown format, place the entire message in the log.
TestBase::insertAssert($test_id, $test_class, FALSE, $line, 'Fatal error');
simpletest_insert_assert($test_id, $test_class, FALSE, $line, 'Fatal error');
}
$found = TRUE;
}
......@@ -564,6 +563,62 @@ function simpletest_log_read($test_id, $database_prefix, $test_class) {
return $found;
}
/**
* Store an assertion from outside the testing context.
*
* This is useful for inserting assertions that can only be recorded after
* the test case has been destroyed, such as PHP fatal errors. The caller
* information is not automatically gathered since the caller is most likely
* inserting the assertion on behalf of other code. In all other respects
* the method behaves just like \Drupal\simpletest\TestBase::assert() in terms
* of storing the assertion.
*
* @param string $test_id
* The test ID to which the assertion relates.
* @param string $test_class
* The test class to store an assertion for.
* @param bool|string $status
* A boolean or a string of 'pass' or 'fail'. TRUE means 'pass'.
* @param string $message
* The assertion message.
* @param string $group
* The assertion message group.
* @param array $caller
* The an array containing the keys 'file' and 'line' that represent the file
* and line number of that file that is responsible for the assertion.
*
* @return
* Message ID of the stored assertion.
*/
function simpletest_insert_assert($test_id, $test_class, $status, $message = '', $group = 'Other', array $caller = []) {
// Convert boolean status to string status.
if (is_bool($status)) {
$status = $status ? 'pass' : 'fail';
}
$caller += [
'function' => 'Unknown',
'line' => 0,
'file' => 'Unknown',
];
$assertion = [
'test_id' => $test_id,
'test_class' => $test_class,
'status' => $status,
'message' => $message,
'message_group' => $group,
'function' => $caller['function'],
'line' => $caller['line'],
'file' => $caller['file'],
];
return TestDatabase::getConnection()
->insert('simpletest')
->fields($assertion)
->execute();
}
/**
* Gets a list of all of the tests provided by the system.
*
......
......@@ -384,6 +384,10 @@ protected function assert($status, $message = '', $group = 'Other', array $calle
* @return
* Message ID of the stored assertion.
*
* @deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use
* simpletest_insert_assert() instead.
*
* @see https://www.drupal.org/node/3030340
* @see \Drupal\simpletest\TestBase::assert()
* @see \Drupal\simpletest\TestBase::deleteAssert()
*/
......
......@@ -747,7 +747,7 @@ function simpletest_script_execute_batch($test_classes) {
// @see https://www.drupal.org/node/2780087
$total_status = max(SIMPLETEST_SCRIPT_EXIT_FAILURE, $total_status);
// Insert a fail for xml results.
TestBase::insertAssert($child['test_id'], $child['class'], FALSE, $message, 'run-tests.sh check');
simpletest_insert_assert($child['test_id'], $child['class'], FALSE, $message, 'run-tests.sh check');
// Ensure that an error line is displayed for the class.
simpletest_script_reporter_display_summary(
$child['class'],
......@@ -950,7 +950,7 @@ function simpletest_script_cleanup($test_id, $test_class, $exitcode) {
// would also delete file directories of other tests that are potentially
// running concurrently.
try {
\Drupal::service('file_system')->deleteRecursive($test_directory, ['Drupal\simpletest\TestBase', 'filePreDeleteCallback']);
\Drupal::service('file_system')->deleteRecursive($test_directory, ['\Drupal\Tests\BrowserTestBase', 'filePreDeleteCallback']);
$messages[] = "- Removed test site directory.";
}
catch (FileException $e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment