diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index d119f7f..4f5e692 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -122,22 +122,22 @@ function _simpletest_format_summary_line($summary) { * The test ID. */ function simpletest_run_tests($test_list) { - $test_id = db_insert('simpletest_test_id') - ->useDefaults(array('test_id')) - ->execute(); - - if (!empty($test_list['phpunit'])) { - $phpunit_results = simpletest_run_phpunit_tests($test_id, $test_list['phpunit']); - simpletest_process_phpunit_results($phpunit_results); + // We used to separate PHPUnit and Simpletest tests for a performance + // optimization. In order to support backwards compatibility check if these + // keys are set and create a single test list. + // @todo https://www.drupal.org/node/2748967 Remove BC support in Drupal 9. + if (isset($test_list['simpletest'])) { + $test_list = array_merge($test_list, $test_list['simpletest']); + unset($test_list['simpletest']); } - - // Early return if there are no further tests to run. - if (empty($test_list['simpletest'])) { - return $test_id; + if (isset($test_list['phpunit'])) { + $test_list = array_merge($test_list, $test_list['phpunit']); + unset($test_list['phpunit']); } - // Continue with SimpleTests only. - $test_list = $test_list['simpletest']; + $test_id = db_insert('simpletest_test_id') + ->useDefaults(array('test_id')) + ->execute(); // Clear out the previous verbose files. file_unmanaged_delete_recursive('public://simpletest/verbose'); @@ -190,7 +190,7 @@ function simpletest_run_phpunit_tests($test_id, array $unescaped_test_classnames // Something broke during the execution of phpunit. // Return an error record of all failed classes. $rows[] = [ - 'test_id' => '1', + 'test_id' => $test_id, 'test_class' => implode(",", $unescaped_test_classnames), 'status' => 'fail', 'message' => 'PHPunit Test failed to complete', @@ -224,6 +224,48 @@ function simpletest_process_phpunit_results($phpunit_results) { } /** + * Maps phpunit results to a data structure for batch messages and run-tests.sh. + * + * @param array $results + * The output from simpletest_run_phpunit_tests(). + * + * @return array + * The test result summary. A row per test class. + */ +function simpletest_summarise_phpunit_result($results) { + $summaries = []; + foreach ($results as $result) { + if (!isset($summaries[$result['test_class']])) { + $summaries[$result['test_class']] = array( + '#pass' => 0, + '#fail' => 0, + '#exception' => 0, + '#debug' => 0, + ); + } + + switch ($result['status']) { + case 'pass': + $summaries[$result['test_class']]['#pass']++; + break; + + case 'fail': + $summaries[$result['test_class']]['#fail']++; + break; + + case 'exception': + $summaries[$result['test_class']]['#exception']++; + break; + + case 'debug': + $summaries[$result['test_class']]['#debug']++; + break; + } + } + return $summaries; +} + +/** * Returns the path to use for PHPUnit's --log-junit option. * * @param $test_id @@ -352,15 +394,21 @@ function _simpletest_batch_operation($test_list_init, $test_id, &$context) { // Perform the next test. $test_class = array_shift($test_list); - $test = new $test_class($test_id); - $test->run(); + if (is_subclass_of($test_class, \PHPUnit_Framework_TestCase::class)) { + $phpunit_results = simpletest_run_phpunit_tests($test_id, [$test_class]); + simpletest_process_phpunit_results($phpunit_results); + $test_results[$test_class] = simpletest_summarise_phpunit_result($phpunit_results)[$test_class]; + } + else { + $test = new $test_class($test_id); + $test->run(); + \Drupal::moduleHandler()->invokeAll('test_finished', array($test->results)); + $test_results[$test_class] = $test->results; + } $size = count($test_list); $info = TestDiscovery::getTestInfo($test_class); - \Drupal::moduleHandler()->invokeAll('test_finished', array($test->results)); - // Gather results and compose the report. - $test_results[$test_class] = $test->results; foreach ($test_results[$test_class] as $key => $value) { $test_results[$key] += $value; } diff --git a/core/modules/simpletest/src/Form/SimpletestTestForm.php b/core/modules/simpletest/src/Form/SimpletestTestForm.php index 1c58efe..e645705 100644 --- a/core/modules/simpletest/src/Form/SimpletestTestForm.php +++ b/core/modules/simpletest/src/Form/SimpletestTestForm.php @@ -217,18 +217,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $form_state->setValue('tests', $user_input['tests']); } - $tests_list = array(); - foreach ($form_state->getValue('tests') as $class_name => $value) { - if ($value === $class_name) { - if (is_subclass_of($class_name, 'PHPUnit_Framework_TestCase')) { - $test_type = 'phpunit'; - } - else { - $test_type = 'simpletest'; - } - $tests_list[$test_type][] = $class_name; - } - } + $tests_list = array_filter($form_state->getValue('tests')); if (!empty($tests_list)) { putenv('SIMPLETEST_BASE_URL=' . $base_url); $test_id = simpletest_run_tests($tests_list, 'drupal'); diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index df61328..c0afeb9 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -690,36 +690,7 @@ function simpletest_script_run_phpunit($test_id, $class) { // Map phpunit results to a data structure we can pass to // _simpletest_format_summary_line. - $summaries = array(); - foreach ($results as $result) { - if (!isset($summaries[$result['test_class']])) { - $summaries[$result['test_class']] = array( - '#pass' => 0, - '#fail' => 0, - '#exception' => 0, - '#debug' => 0, - ); - } - - switch ($result['status']) { - case 'pass': - $summaries[$result['test_class']]['#pass']++; - break; - - case 'fail': - $summaries[$result['test_class']]['#fail']++; - break; - - case 'exception': - $summaries[$result['test_class']]['#exception']++; - break; - - case 'debug': - $summaries[$result['test_class']]['#debug']++; - break; - } - } - + $summaries = simpletest_summarise_phpunit_result($results); foreach ($summaries as $class => $summary) { simpletest_script_reporter_display_summary($class, $summary); }