Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
90.00% |
9 / 10 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
PhpUnitTestListProcessor | |
90.00% |
9 / 10 |
|
66.67% |
2 / 3 |
4.02 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getTestClasses | |
83.33% |
5 / 6 |
|
0.00% |
0 / 1 |
2.02 | |||
extractNamespace | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 |
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 | } |