getName() === 'testcase') { return [$element]; } $test_cases = []; foreach ($element as $child) { $test_cases[] = static::findTestCases($child, $element); } return array_merge(...$test_cases); } /** * Converts a PHPUnit test case result to a {simpletest} result row. * * @param int $test_id * The current test ID. * @param \SimpleXMLElement $test_case * The PHPUnit test case represented as XML element. * * @return array * An array containing the {simpletest} result row. * * @internal */ public static function convertTestCaseToSimpletestRow($test_id, \SimpleXMLElement $test_case): array { $status = static::getTestCaseResult($test_case); $attributes = $test_case->attributes(); $message = match ($status) { PhpUnitTestCaseJUnitResult::Fail => (string) $test_case->failure[0], PhpUnitTestCaseJUnitResult::Error => (string) $test_case->error[0], default => '', }; return [ 'test_id' => $test_id, 'test_class' => (string) $attributes->class, 'status' => $status->value, 'message' => $message, 'message_group' => 'Other', 'function' => $attributes->name, 'line' => (int) $attributes->line ?: 0, 'file' => (string) $attributes->file, 'time' => (float) $attributes->time, ]; } /** * Determine a status string for the given testcase. * * @param \SimpleXMLElement $test_case * The test case XML element. * * @return \Drupal\TestTools\PhpUnitTestCaseJUnitResult * The status value to insert into the {simpletest} record. */ protected static function getTestCaseResult(\SimpleXMLElement $test_case): PhpUnitTestCaseJUnitResult { if ($test_case->error) { return PhpUnitTestCaseJUnitResult::Error; } if ($test_case->failure) { return PhpUnitTestCaseJUnitResult::Fail; } if ($test_case->skipped) { return PhpUnitTestCaseJUnitResult::Skip; } return PhpUnitTestCaseJUnitResult::Pass; } }