MediaWiki master
PhpUnitTestListProcessor.php
Go to the documentation of this file.
1<?php
2
3declare( strict_types = 1 );
4
6
7use SimpleXMLElement;
8
13
14 private SimpleXMLElement $xml;
15 private array $resultsCache;
16
20 public function __construct(
21 string $testListFile,
22 ?string $resultsCacheFile = null,
23 ?string $testGroup = null
24 ) {
25 $this->xml = new SimpleXMLElement( file_get_contents( $testListFile ) );
26 // Load phpunit result cache information if available to create more balanced split groups
27 if ( $resultsCacheFile && $testGroup ) {
28 if ( !file_exists( $resultsCacheFile ) ) {
30 'Results cache file "' . $resultsCacheFile . '" specified but not found on filesystem'
31 );
32 }
33 $loadedResults = json_decode( file_get_contents( $resultsCacheFile ), true );
34 if ( array_key_exists( $testGroup, $loadedResults ) ) {
35 $this->resultsCache = $loadedResults[$testGroup];
36 } else {
37 $this->resultsCache = [];
38 }
39 } else {
40 $this->resultsCache = [];
41 }
42 }
43
49 public function getTestClasses(): array {
50 if ( !property_exists( $this->xml, "testCaseClass" ) ) {
51 return [];
52 }
53 return array_map(
54 fn ( $element ) => self::createTestDescriptor(
55 (string)$element->attributes()["name"],
56 $this->resultsCache
57 ),
58 iterator_to_array( $this->xml->testCaseClass, false )
59 );
60 }
61
62 private static function createTestDescriptor(
63 string $qualifiedClassName,
64 array $resultsCache
65 ): TestDescriptor {
66 $duration = 0;
67 if ( array_key_exists( $qualifiedClassName, $resultsCache ) ) {
68 $duration = $resultsCache[$qualifiedClassName];
69 }
70 $parts = explode( '\\', $qualifiedClassName );
71 $className = array_pop( $parts );
72 return new TestDescriptor( $className, $parts, null, $duration );
73 }
74}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:69
__construct(string $testListFile, ?string $resultsCacheFile=null, ?string $testGroup=null)