function JUnitConverter::convertTestCaseToSimpletestRow

Same name in other branches
  1. 9 core/lib/Drupal/Core/Test/JUnitConverter.php \Drupal\Core\Test\JUnitConverter::convertTestCaseToSimpletestRow()
  2. 8.9.x 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.

2 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

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.