diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index c0d8d425cb3..b78ff3ccd64 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -748,22 +748,31 @@ function simpletest_phpunit_get_available_tests() { * Path to the phpunit xml file. */ function simpletest_phpunit_xml_to_rows($test_id, $phpunit_xml_file) { - $contents = file_get_contents($phpunit_xml_file); + $contents = @file_get_contents($phpunit_xml_file); + if (!$contents) { + return; + } $xml = new SimpleXMLElement($contents); $records = array(); foreach ($xml->testsuite as $testsuite) { foreach ($testsuite as $suite) { foreach ($suite as $testcase) { $message = ''; + $pass = TRUE; if ($testcase->failure) { $lines = explode("\n", $testcase->failure); $message = $lines[2]; + $pass = FALSE; + } + if ($testcase->error) { + $message = $testcase->error; + $pass = FALSE; } $attributes = $testcase->attributes(); $records[] = array( 'test_id' => $test_id, 'test_class' => (string)$attributes->class, - 'status' => empty($testcase->failure) ? 'pass' : 'fail', + 'status' => $pass ? 'pass' : 'fail', 'message' => $message, 'message_group' => 'Other', // TODO: Check on the proper values for this. 'function' => $attributes->class . '->' . $attributes->name . '()', diff --git a/core/modules/simpletest/tests/Drupal/simpletest/Tests/PhpUnitErrorTest.php b/core/modules/simpletest/tests/Drupal/simpletest/Tests/PhpUnitErrorTest.php new file mode 100644 index 00000000000..b6c19d90b62 --- /dev/null +++ b/core/modules/simpletest/tests/Drupal/simpletest/Tests/PhpUnitErrorTest.php @@ -0,0 +1,33 @@ + 'PHPUnit errors', + 'description' => 'Test PHPUnit errors getting converted to Simpletest errors.', + 'group' => 'Simpletest', + ); + } + + /** + * Test errors reported. + */ + public function testPhpUnitXmlParsing() { + require_once __DIR__ . '/../../../../simpletest.module'; + $phpunit_error_xml = __DIR__ . '/phpunit_error.xml'; + $res = simpletest_phpunit_xml_to_rows(1, $phpunit_error_xml); + $this->assertNotEquals($res[0]['status'], 'pass'); + $this->assertEquals($res[0]['status'], 'fail'); + // Make sure simpletest_phpunit_xml_to_rows() does not balk if the test + // didn't run. + simpletest_phpunit_xml_to_rows(1, 'foobar'); + } +} diff --git a/core/modules/simpletest/tests/Drupal/simpletest/Tests/phpunit_error.xml b/core/modules/simpletest/tests/Drupal/simpletest/Tests/phpunit_error.xml new file mode 100644 index 00000000000..b1c08376ece --- /dev/null +++ b/core/modules/simpletest/tests/Drupal/simpletest/Tests/phpunit_error.xml @@ -0,0 +1,21 @@ + + + + + + + + + + Drupal\Tests\Core\Extension\ModuleHandlerUnitTest::testloadInclude +Undefined index: foo + +/home/chx/www/system/core/lib/Drupal/Core/Extension/ModuleHandler.php:219 +/home/chx/www/system/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php:40 + + + + + + +