function JUnitConverter::findTestCases

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

Finds all test cases recursively from a test suite list.

@internal

Parameters

\SimpleXMLElement $element: The PHPUnit xml to search for test cases.

\SimpleXMLElement $parent: (Optional) The parent of the current element. Defaults to NULL.

Return value

array A list of all test cases.

2 calls to JUnitConverter::findTestCases()
JUnitConverter::xmlElementToRows in core/lib/Drupal/Core/Test/JUnitConverter.php
Parse test cases from XML to {simpletest} schema.
simpletest_phpunit_find_testcases in core/modules/simpletest/simpletest.module
Finds all test cases recursively from a test suite list.

File

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

Class

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

Namespace

Drupal\Core\Test

Code

public static function findTestCases(\SimpleXMLElement $element, \SimpleXMLElement $parent = NULL) {
    if (!isset($parent)) {
        $parent = $element;
    }
    if ($element->getName() === 'testcase' && (int) $parent->attributes()->tests > 0) {
        // Add the class attribute if the test case does not have one. This is the
        // case for tests using a data provider. The name of the parent testsuite
        // will be in the format class::method.
        if (!$element->attributes()->class) {
            $name = explode('::', $parent->attributes()->name, 2);
            $element->addAttribute('class', $name[0]);
        }
        return [
            $element,
        ];
    }
    $test_cases = [];
    foreach ($element as $child) {
        $file = (string) $parent->attributes()->file;
        if ($file && !$child->attributes()->file) {
            $child->addAttribute('file', $file);
        }
        $test_cases = array_merge($test_cases, static::findTestCases($child, $element));
    }
    return $test_cases;
}

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