This repository has been archived by the owner on Sep 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjunit_rewrite.php
82 lines (60 loc) · 2.12 KB
/
junit_rewrite.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
<?php
$xml = simplexml_load_file(__DIR__.'/upgrade_status.xml');
$xw = xmlwriter_open_memory();
xmlwriter_set_indent($xw, 1);
$res = xmlwriter_set_indent_string($xw, ' ');
xmlwriter_start_document($xw, '1.0', 'UTF-8');
xmlwriter_start_element($xw, 'testsuites');
xmlwriter_start_attribute($xw, 'name');
xmlwriter_text($xw, 'govcms-deprecations');
xmlwriter_end_attribute($xw);
xmlwriter_start_attribute($xw, 'tests');
xmlwriter_text($xw, count($xml));
xmlwriter_end_attribute($xw);
$totalFailures = 0;
foreach ($xml as $x) {
$totalFailures += count($x->error);
}
// Bail if no failures.
if ($totalFailures == 0) {
return;
}
xmlwriter_start_attribute($xw, 'failures');
xmlwriter_text($xw, $totalFailures);
xmlwriter_end_attribute($xw);
// Build the individual testsuites.
foreach ($xml as $x) {
$totalFailures += count($x->error);
xmlwriter_start_element($xw, 'testsuite');
xmlwriter_start_attribute($xw, 'name');
xmlwriter_text($xw, $x->attributes()->name);
xmlwriter_end_attribute($xw);
xmlwriter_start_attribute($xw, 'tests');
xmlwriter_text($xw, count($x));
xmlwriter_end_attribute($xw);
xmlwriter_start_attribute($xw, 'failures');
xmlwriter_text($xw, count($x));
xmlwriter_end_attribute($xw);
foreach ($x->error as $err) {
xmlwriter_start_element($xw, 'testcase');
xmlwriter_start_attribute($xw, 'name');
xmlwriter_text($xw, $err->attributes()->message . " - found on line: " . $err->attributes()->line);
xmlwriter_end_attribute($xw);
xmlwriter_start_attribute($xw, 'file');
xmlwriter_text($xw, $x->attributes()->name);
xmlwriter_end_attribute($xw);
xmlwriter_start_attribute($xw, 'classname');
xmlwriter_text($xw, "GovCMS deprecation alerts");
xmlwriter_end_attribute($xw);
xmlwriter_start_element($xw, 'failure');
xmlwriter_start_attribute($xw, 'message');
xmlwriter_text($xw, $err->attributes()->message);
xmlwriter_end_attribute($xw);
xmlwriter_end_element($xw); // end failure
xmlwriter_end_element($xw); // end testcase
}
xmlwriter_end_element($xw);
}
xmlwriter_end_element($xw);
xmlwriter_end_document($xw);
echo xmlwriter_output_memory($xw);