forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests-levels-matrix.php
More file actions
47 lines (36 loc) · 1.38 KB
/
tests-levels-matrix.php
File metadata and controls
47 lines (36 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php declare(strict_types = 1);
exec('php vendor/bin/phpunit --group levels --list-tests-xml test-list.xml', $output, $return);
if ($return !== 0) {
throw new RuntimeException(implode("\n", $output));
}
libxml_use_internal_errors(true);
$simpleXml = simplexml_load_file('test-list.xml');
if ($simpleXml === false) {
$errors = [];
foreach (libxml_get_errors() as $error) {
$errors[] = $error->message;
}
throw new RuntimeException('Error loading test-list.xml: ' . implode(', ', $errors));
}
$testFilters = [];
foreach($simpleXml->tests as $testClasses) {
foreach($testClasses->testClass as $testClass) {
foreach($testClass->testMethod as $testMethod) {
$testCaseName = (string)$testMethod['id'];
[$className, $testName] = explode('::', $testCaseName, 2);
$fileName = 'tests/' . str_replace('\\', DIRECTORY_SEPARATOR, $className) . '.php';
$filter = str_replace('\\', '\\\\', $testCaseName);
$testFilters[] = sprintf("%s --filter %s", escapeshellarg($fileName), escapeshellarg($filter));
}
}
}
if ($testFilters === []) {
throw new RuntimeException('No tests found');
}
$chunkSize = (int) ceil(count($testFilters) / 10);
$chunks = array_chunk($testFilters, $chunkSize);
$commands = [];
foreach ($chunks as $chunk) {
$commands[] = implode("\n", array_map(fn (string $ch) => sprintf('php vendor/bin/phpunit %s --group levels', $ch), $chunk));
}
echo json_encode($commands);