Issue #1949266 by chx: Fixed phpunit errors are silently eaten.

8.0.x
webchick 2013-03-26 20:40:17 -07:00
parent dba4763dfa
commit e2941705fb
3 changed files with 65 additions and 2 deletions

View File

@ -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 . '()',

View File

@ -0,0 +1,33 @@
<?php
namespace Drupal\simpletest\Tests;
use Drupal\Tests\UnitTestCase;
/**
* Test PHPUnit errors are getting converted to Simpletest errors.
*/
class PhpUnitErrorTest extends UnitTestCase {
public static function getInfo() {
return array(
'name' => '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');
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="Drupal Unit Test Suite" tests="1" assertions="0" failures="0" errors="1" time="0.002680">
<testsuite name="Drupal\Tests\Component\PhpStorage\FileStorageTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php" namespace="Drupal\Tests\Component\PhpStorage" fullPackage="Drupal.Tests.Component.PhpStorage" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
<testsuite name="Drupal\Tests\Component\PhpStorage\MTimeProtectedFastFileStorageTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Component/PhpStorage/MTimeProtectedFastFileStorageTest.php" namespace="Drupal\Tests\Component\PhpStorage" fullPackage="Drupal.Tests.Component.PhpStorage" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
<testsuite name="Drupal\Tests\Core\Cache\BackendChainImplementationUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php" namespace="Drupal\Tests\Core\Cache" fullPackage="Drupal.Tests.Core.Cache" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
<testsuite name="Drupal\Tests\Core\Cache\NullBackendTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Cache/NullBackendTest.php" namespace="Drupal\Tests\Core\Cache" fullPackage="Drupal.Tests.Core.Cache" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
<testsuite name="Drupal\Tests\Core\Extension\ModuleHandlerUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php" namespace="Drupal\Tests\Core\Extension" fullPackage="Drupal.Tests.Core.Extension" tests="1" assertions="0" failures="0" errors="1" time="0.002680">
<testcase name="testloadInclude" class="Drupal\Tests\Core\Extension\ModuleHandlerUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php" line="37" assertions="0" time="0.002680">
<error type="PHPUnit_Framework_Error_Notice">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
</error>
</testcase>
</testsuite>
<testsuite name="Drupal\Tests\Core\NestedArrayUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/NestedArrayUnitTest.php" namespace="Drupal\Tests\Core" fullPackage="Drupal.Tests.Core" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
<testsuite name="Drupal\breakpoint\Tests\BreakpointMediaQueryTest" file="/home/chx/www/system/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointMediaQueryTest.php" namespace="Drupal\breakpoint\Tests" fullPackage="Drupal.breakpoint.Tests" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
</testsuite>
</testsuites>