function JUnitConverter::convertTestCaseToSimpletestRow

Same name in other branches
  1. 9 core/lib/Drupal/Core/Test/JUnitConverter.php \Drupal\Core\Test\JUnitConverter::convertTestCaseToSimpletestRow()
  2. 10 core/lib/Drupal/Core/Test/JUnitConverter.php \Drupal\Core\Test\JUnitConverter::convertTestCaseToSimpletestRow()
  3. 11.x core/lib/Drupal/Core/Test/JUnitConverter.php \Drupal\Core\Test\JUnitConverter::convertTestCaseToSimpletestRow()

Converts a PHPUnit test case result to a {simpletest} result row.

@internal

Parameters

int $test_id: The current test ID.

\SimpleXMLElement $test_case: The PHPUnit test case represented as XML element.

Return value

array An array containing the {simpletest} result row.

3 calls to JUnitConverter::convertTestCaseToSimpletestRow()
JUnitConverter::xmlElementToRows in core/lib/Drupal/Core/Test/JUnitConverter.php
Parse test cases from XML to {simpletest} schema.
JUnitConverterTest::testConvertTestCaseToSimpletestRow in core/tests/Drupal/Tests/Core/Test/JUnitConverterTest.php
@covers ::convertTestCaseToSimpletestRow
simpletest_phpunit_testcase_to_row in core/modules/simpletest/simpletest.module
Converts a PHPUnit test case result to a {simpletest} result row.

File

core/lib/Drupal/Core/Test/JUnitConverter.php, line 111

Class

JUnitConverter
Converts JUnit XML to Drupal's {simpletest} schema.

Namespace

Drupal\Core\Test

Code

public static function convertTestCaseToSimpletestRow($test_id, \SimpleXMLElement $test_case) {
    $message = '';
    $pass = TRUE;
    if ($test_case->failure) {
        $lines = explode("\n", $test_case->failure);
        $message = $lines[2];
        $pass = FALSE;
    }
    if ($test_case->error) {
        $message = $test_case->error;
        $pass = FALSE;
    }
    $attributes = $test_case->attributes();
    $record = [
        'test_id' => $test_id,
        'test_class' => (string) $attributes->class,
        'status' => $pass ? 'pass' : 'fail',
        'message' => $message,
        'message_group' => 'Other',
        'function' => $attributes->class . '->' . $attributes->name . '()',
        'line' => (int) $attributes->line ?: 0,
        'file' => (string) $attributes->file,
    ];
    return $record;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.