forked from Berdir/d8modulestatus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_results.php
91 lines (81 loc) · 2.68 KB
/
parse_results.php
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
require_once 'vendor/autoload.php';
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader);
$projects = parse_results('results');
if (is_dir('results-old')) {
$projects_old = parse_results('results-old');
}
foreach ($projects as $name => &$project) {
if (!isset($projects_old[$name])) {
$project['new'] = TRUE;
continue;
}
foreach (['phpunit', 'simpletest'] as $framework) {
if (!isset($project[$framework])) {
continue;
}
foreach ($project[$framework] as $type => $count) {
if (isset($projects_old[$name][$framework][$type])) {
$project[$framework][$type . '_diff'] = $count - $projects_old[$name][$framework][$type];
}
}
}
}
ksort($projects);
$index = $twig->render('index.html.twig', ['projects' => $projects, 'timestamp' => date('Y-m-d H:i:s T')]);
file_put_contents('results/index.html', $index);
file_put_contents('results/projects.json', json_encode($projects, JSON_PRETTY_PRINT));
/**
* @param $path
*
* @return array
*/
function parse_results($path) {
$projects = array();
foreach (new DirectoryIterator($path) as $file_info) {
if ($file_info->isDir() && !$file_info->isDot()) {
$project = [
'name' => $file_info->getFilename(),
'phpunit' => [],
'simpletest' => [],
];
$phpunit_file = $file_info->getPathName() . '/phpunit.xml';
if (file_exists($phpunit_file) && filesize($phpunit_file) > 0) {
$phpunit = simplexml_load_file($phpunit_file);
$project['phpunit']['assertions'] = (int) $phpunit->testsuite['assertions'];
$project['phpunit']['failures'] = (int) $phpunit->testsuite['failures'];
$project['phpunit']['errors'] = (int) $phpunit->testsuite['errrors'];
}
$project['simpletest'] = get_simpletest_results($file_info->getPathname());
$projects[$project['name']] = $project;
}
}
return $projects;
}
/**
* Returns simpletest test results.
*
* @param $simpletest_dir
*
* @return array
*/
function get_simpletest_results($project_dir) {
$results = [
'assertions' => 0,
'failures' => 0,
'errors' => 0,
];
$simpletest_dir = $project_dir . '/simpletest';
if (is_dir($simpletest_dir)) {
foreach (new DirectoryIterator($simpletest_dir) as $simpletest_file_info) {
if ($simpletest_file_info->isFile()) {
$simpletest_xml = simplexml_load_file($simpletest_file_info->getRealPath());
$results['assertions'] += count($simpletest_xml->testcase);
$results['failures'] += count($simpletest_xml->xpath('/testsuite/testcase/failure'));
$results['errors'] += count($simpletest_xml->xpath('/testsuite/testcase/error'));
}
}
}
return $results;
}