diff --git a/core/lib/Drupal/Core/Test/TestDatabase.php b/core/lib/Drupal/Core/Test/TestDatabase.php index 03ff3d2f626823862b159b5f505bd147c727a185..70c5c084fe10caefdbdc14e3ed11077b4724f561 100644 --- a/core/lib/Drupal/Core/Test/TestDatabase.php +++ b/core/lib/Drupal/Core/Test/TestDatabase.php @@ -406,4 +406,27 @@ public static function testingSchema() { return $schema; } + /** + * Inserts the parsed PHPUnit results into {simpletest}. + * + * @param array[] $phpunit_results + * An array of test results, as returned from + * \Drupal\Core\Test\JUnitConverter::xmlToRows(). These results are in a + * form suitable for inserting into the {simpletest} table of the test + * results database. + * + * @internal + */ + public static function processPhpUnitResults($phpunit_results) { + if ($phpunit_results) { + $query = static::getConnection() + ->insert('simpletest') + ->fields(array_keys($phpunit_results[0])); + foreach ($phpunit_results as $result) { + $query->values($result); + } + $query->execute(); + } + } + } diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index 8dc4ecea08c5ed5a24a24b6ffcf8dd2718c7a41e..07a2588602ccdff6d7a0b154f2ef3f9f22d72b25 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -204,19 +204,15 @@ function simpletest_run_phpunit_tests($test_id, array $unescaped_test_classnames * * @param array[] $phpunit_results * An array of test results returned from simpletest_phpunit_xml_to_rows(). + * + * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use + * \Drupal\Core\Test\TestDatabase::processPhpUnitResults() instead. + * + * @see https://www.drupal.org/node/3075252 */ function simpletest_process_phpunit_results($phpunit_results) { - // Insert the results of the PHPUnit test run into the database so the results - // are displayed along with Simpletest's results. - if (!empty($phpunit_results)) { - $query = TestDatabase::getConnection() - ->insert('simpletest') - ->fields(array_keys($phpunit_results[0])); - foreach ($phpunit_results as $result) { - $query->values($result); - } - $query->execute(); - } + @trigger_error(__FUNCTION__ . '() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\TestDatabase::processPhpUnitResults() instead. See https://www.drupal.org/node/3075252', E_USER_DEPRECATED); + TestDatabase::processPhpUnitResults($phpunit_results); } /** @@ -345,7 +341,7 @@ function _simpletest_batch_operation($test_list_init, $test_id, &$context) { if (is_subclass_of($test_class, TestCase::class)) { $runner = PhpUnitTestRunner::create(\Drupal::getContainer()); $phpunit_results = $runner->runTests($test_id, [$test_class]); - simpletest_process_phpunit_results($phpunit_results); + TestDatabase::processPhpUnitResults($phpunit_results); $test_results[$test_class] = simpletest_summarize_phpunit_result($phpunit_results)[$test_class]; } else { diff --git a/core/modules/simpletest/tests/src/Kernel/SimpletestDeprecationTest.php b/core/modules/simpletest/tests/src/Kernel/SimpletestDeprecationTest.php index b1c1a8f79c4439ad95fe99b7c913e61dadc48bee..4ef09a903357e5ec977ba0d37e13be6f050c59c1 100644 --- a/core/modules/simpletest/tests/src/Kernel/SimpletestDeprecationTest.php +++ b/core/modules/simpletest/tests/src/Kernel/SimpletestDeprecationTest.php @@ -92,4 +92,13 @@ public function testDeprecatedSimpletestGenerateFile() { $this->assertTrue(unlink($public_file)); } + /** + * @expectedDeprecation simpletest_process_phpunit_results() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\TestDatabase::processPhpUnitResults() instead. See https://www.drupal.org/node/3075252 + */ + public function testProcessPhpUnitResults() { + // The only safe way to test this deprecation is to call it with an empty + // result set. This should not touch the results database. + $this->assertNull(simpletest_process_phpunit_results([])); + } + } diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index f1cb4c0ce45526273d6ae71a8eaa03bb942be8d7..c4f910e2024dc876b51c185b5ea56683931ae3b8 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -782,7 +782,7 @@ function simpletest_script_run_phpunit($test_id, $class) { $runner = PhpUnitTestRunner::create(\Drupal::getContainer()); $results = $runner->runTests($test_id, [$class], $status); - simpletest_process_phpunit_results($results); + TestDatabase::processPhpUnitResults($results); $summaries = $runner->summarizeResults($results); foreach ($summaries as $class => $summary) {