Debian Codegraph @

includes/composer/PhpUnitSplitter/PhpUnitTestListProcessor.php

raw symbols SCIP
1 <?php
2
3 declare( strict_types = 1 );
4
5 namespace MediaWiki\Composer\PhpUnitSplitter;
6
7 use SimpleXMLElement;
8
9 /**
10 * @license GPL-2.0-or-later
11 */
12 class PhpUnitTestListProcessor {
13
14 private SimpleXMLElement $xml;
15
16 public function __construct( string $testListFile ) {
17 $this->xml = new SimpleXMLElement( file_get_contents( $testListFile ) );
18 }
19
20 /**
21 * @return TestDescriptor[] A list of TestDescriptor objects representing the
22 * test classes found in the `--list-tests` XML
23 * output
24 */
25 public function getTestClasses(): array {
26 if ( !property_exists( $this->xml, "testCaseClass" ) ) {
27 return [];
28 }
29 return array_map(
30 fn ( $element ) => self::extractNamespace( (string)$element->attributes()["name"] ),
31 iterator_to_array( $this->xml->testCaseClass, false )
32 );
33 }
34
35 private static function extractNamespace( string $qualifiedClassName ): TestDescriptor {
36 $parts = explode( '\\', $qualifiedClassName );
37 $className = array_pop( $parts );
38 return new TestDescriptor( $className, $parts );
39 }
40 }