diff --git a/core/lib/Drupal/Core/Test/JUnitConverter.php b/core/lib/Drupal/Core/Test/JUnitConverter.php index 01b36ef2ee..5c60694385 100644 --- a/core/lib/Drupal/Core/Test/JUnitConverter.php +++ b/core/lib/Drupal/Core/Test/JUnitConverter.php @@ -46,8 +46,6 @@ public static function xmlToRows($test_id, $phpunit_xml_file) { * A list of all test cases. */ public static function findTestCases(\SimpleXMLElement $element, \SimpleXMLElement $parent = NULL) { - $test_cases = []; - if (!isset($parent)) { $parent = $element; } @@ -60,16 +58,15 @@ public static function findTestCases(\SimpleXMLElement $element, \SimpleXMLEleme $name = explode('::', $parent->attributes()->name, 2); $element->addAttribute('class', $name[0]); } - $test_cases[] = $element; + return [$element]; } - else { - foreach ($element as $child) { - $file = (string) $parent->attributes()->file; - if ($file && !$child->attributes()->file) { - $child->addAttribute('file', $file); - } - $test_cases = array_merge($test_cases, static::findTestCases($child, $element)); + $test_cases = []; + foreach ($element as $child) { + $file = (string) $parent->attributes()->file; + if ($file && !$child->attributes()->file) { + $child->addAttribute('file', $file); } + $test_cases = array_merge($test_cases, static::findTestCases($child, $element)); } return $test_cases; } @@ -105,7 +102,6 @@ public static function convertTestCaseToSimpletestRow($test_id, \SimpleXMLElemen 'test_class' => (string) $attributes->class, 'status' => $pass ? 'pass' : 'fail', 'message' => $message, - // @todo: Check on the proper values for this. 'message_group' => 'Other', 'function' => $attributes->class . '->' . $attributes->name . '()', 'line' => $attributes->line ?: 0, diff --git a/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php b/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php index 983d5780d9..e1e1087ef0 100644 --- a/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php +++ b/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php @@ -81,16 +81,6 @@ public function xmlLogFilePath($test_id) { return $this->workingDirectory . '/phpunit-' . $test_id . '.xml'; } - /** - * Returns the path to core's phpunit.xml.dist configuration file. - * - * @return string - * The path to core's phpunit.xml.dist configuration file. - */ - public function phpUnitConfigurationFilepath() { - return $this->appRoot . '/core/phpunit.xml.dist'; - } - /** * Returns the command to run PHPUnit. * @@ -216,23 +206,19 @@ public function runTests($test_id, array $unescaped_test_classnames, &$status = $output = []; $this->runCommand($unescaped_test_classnames, $phpunit_file, $status, $output); - $rows = []; if ($status == TestStatus::PASS) { - $rows = JUnitConverter::xmlToRows($test_id, $phpunit_file); - } - else { - $rows[] = [ - 'test_id' => $test_id, - 'test_class' => implode(",", $unescaped_test_classnames), - 'status' => TestStatus::label($status), - 'message' => 'PHPunit Test failed to complete; Error: ' . implode("\n", $output), - 'message_group' => 'Other', - 'function' => implode(",", $unescaped_test_classnames), - 'line' => '0', - 'file' => $phpunit_file, - ]; + return JUnitConverter::xmlToRows($test_id, $phpunit_file); } - return $rows; + return [[ + 'test_id' => $test_id, + 'test_class' => implode(",", $unescaped_test_classnames), + 'status' => TestStatus::label($status), + 'message' => 'PHPunit Test failed to complete; Error: ' . implode("\n", $output), + 'message_group' => 'Other', + 'function' => implode(",", $unescaped_test_classnames), + 'line' => '0', + 'file' => $phpunit_file, + ]]; } } diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index 1dc6529fc5..562e535cf1 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -789,7 +789,7 @@ function simpletest_mail_alter(&$message) { */ function simpletest_phpunit_xml_to_rows($test_id, $phpunit_xml_file) { @trigger_error(__FUNCTION__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\JUnitConverter::xmlToRows() instead. See https://www.drupal.org/node/2948547', E_USER_DEPRECATED); - return JUnitConverter::xmlToRows($test_id, $phpunit_xml_file); + return JUnitConverter::xmlToRows($test_id, $phpunit_xml_file) ?: NULL; } /** diff --git a/core/modules/simpletest/tests/src/Kernel/PhpUnitErrorTest.php b/core/modules/simpletest/tests/src/Kernel/PhpUnitErrorTest.php index 700df282ae..4f01936eeb 100644 --- a/core/modules/simpletest/tests/src/Kernel/PhpUnitErrorTest.php +++ b/core/modules/simpletest/tests/src/Kernel/PhpUnitErrorTest.php @@ -40,7 +40,7 @@ public function testPhpUnitXmlParsing() { // Make sure simpletest_phpunit_xml_to_rows() does not balk if the test // didn't run. - simpletest_phpunit_xml_to_rows(1, 'foobar'); + $this->assertNull(simpletest_phpunit_xml_to_rows(1, 'does_not_exist')); } } diff --git a/core/modules/simpletest/tests/src/Kernel/SimpletestDeprecationTest.php b/core/modules/simpletest/tests/src/Kernel/SimpletestDeprecationTest.php index 36c3d43dc7..389261fb6f 100644 --- a/core/modules/simpletest/tests/src/Kernel/SimpletestDeprecationTest.php +++ b/core/modules/simpletest/tests/src/Kernel/SimpletestDeprecationTest.php @@ -34,4 +34,31 @@ public function testDeprecatedServices() { $this->assertInstanceOf(TestDiscovery::class, $this->container->get('test_discovery')); } + /** + * @expectedDeprecation simpletest_phpunit_xml_filepath is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::xmlLogFilepath() instead. See https://www.drupal.org/node/2948547 + * @expectedDeprecation simpletest_phpunit_command is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\PhpUnitTestRunner::phpUnitCommand() instead. See https://www.drupal.org/node/2948547 + * @expectedDeprecation simpletest_phpunit_find_testcases is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\JUnitConverter::findTestCases() instead. See https://www.drupal.org/node/2948547 + * @expectedDeprecation simpletest_phpunit_testcase_to_row is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Test\JUnitConverter::convertTestCaseToSimpletestRow() instead. See https://www.drupal.org/node/2948547 + */ + public function testDeprecatedPhpUnitFunctions() { + // We can't test the deprecation errors for the following functions because + // they cannot be mocked, and calling them would change the test results: + // - simpletest_run_phpunit_tests(). + // - simpletest_phpunit_run_command(). + // - simpletest_phpunit_xml_to_rows(). + $this->assertStringEndsWith('/phpunit-23.xml', simpletest_phpunit_xml_filepath(23)); + $this->assertInternalType('string', simpletest_phpunit_command()); + $this->assertEquals([], simpletest_phpunit_find_testcases(new \SimpleXMLElement(''))); + $this->assertEquals([ + 'test_id' => 23, + 'test_class' => '', + 'status' => 'pass', + 'message' => '', + 'message_group' => 'Other', + 'function' => '->()', + 'line' => 0, + 'file' => NULL, + ], simpletest_phpunit_testcase_to_row(23, new \SimpleXMLElement(''))); + } + }