-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHtmlReport.php
160 lines (149 loc) · 8.22 KB
/
HtmlReport.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
namespace Src;
use Src\ResultsContainer;
/**
* Class HtmlReport
*/
class HtmlReport
{
private const REPORT_FILE = __DIR__ . '/../results/report.html';
/**
* Generate HTML report
*/
public function generate(): void
{
if(HTML_REPORT === false) {
return;
}
$results = ResultsContainer::getResults();
ob_start();
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://code.jquery.com/jquery-3.7.1.slim.min.js" integrity="sha256-kmHvs0B+OpCW5GVHUNjv9rOmY0IvSIRcf7zGUDTDQM8=" crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
$('input[type="checkbox"]').click(function(){
var inputValue = $(this).attr("value");
$("." + inputValue).toggle();
});
});
</script>
</head>
<body class="bg-slate-200">
<?php
if(!in_array(RESULT_TYPE, ['json', 'xml'])) {
?>
<p class="px-4 py-2 bg-red-600 text-center text-sm text-white">
!! For better results use json or xml as RESULT_TYPE !!
</p>
<?php } ?>
<?php
if(in_array(RESULT_TYPE, ['json', 'xml'])) {
?>
<div class="flex bg-slate-600 w-full text-white py-2 px-4 gap-4 mb-4">
<!-- TOGGLE PASS TESTS -->
<label class="inline-flex items-center cursor-pointer">
<input type="checkbox" value="passed" checked class="sr-only peer">
<div class="relative w-11 h-6 bg-gray-700 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 rounded-full peer peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-green-600"></div>
<span class="ms-2 text-sm font-medium text-white">Pass</span>
</label>
<!-- TOGGLE FAIL TESTS -->
<label class="inline-flex items-center cursor-pointer">
<input type="checkbox" value="failed" checked class="sr-only peer">
<div class="relative w-11 h-6 bg-gray-700 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 rounded-full peer peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all
peer-checked:bg-red-600"></div>
<span class="ms-2 text-sm font-medium text-white">Fail</span>
</label>
</div>
<?php } ?>
<!-- PROGRESS BAR -->
<?php
if(in_array(RESULT_TYPE, ['json', 'xml'])) {
$passed = count(array_filter($results, function($result) {
return strtolower($result['status']) === 'passed';
}));
$total = count($results);
$percentagePass = round($total > 0 ? ($passed / $total) * 100 : 0);
$color = $percentagePass < 50 ? 'bg-red-500' : ($percentagePass < 100 ? 'bg-yellow-500' : 'bg-green-500');
?>
<div class="container mx-auto">
<div class="w-full max-w-lg bg-gray-300 rounded-full mb-4">
<div class="<?php echo $color; ?> text-xs font-medium text-blue-100 text-center p-0.5 leading-none rounded-full" style="width: <?php echo $percentagePass; ?>%"> <?php echo $percentagePass; ?>% Pass</div>
</div>
</div>
<?php } ?>
<div class="container mx-auto">
<div class="relative overflow-x-auto">
<table class="w-full text-sm text-left rtl:text-right text-gray-500">
<?php if(in_array(RESULT_TYPE, ['json', 'xml'])) { ?>
<thead>
<tr class="bg-slate-600 text-white">
<th class="px-6 py-3 text-xs font-medium uppercase">Status</th>
<th class="px-6 py-3 text-xs font-medium uppercase">Error Type</th>
<th class="px-6 py-3 text-xs font-medium uppercase">Error Message</th>
<th class="px-6 py-3 text-xs font-medium uppercase">Test Class</th>
<th class="px-6 py-3 text-xs font-medium uppercase">Test Method</th>
<th class="px-6 py-3 text-xs font-medium uppercase">Trace</th>
</tr>
</thead>
<?php } ?>
<tbody>
<?php
if(in_array(RESULT_TYPE, ['json', 'xml'])) {
foreach ($results as $result) {
?>
<tr class="bg-white border-b <?php echo $result['status']; ?>">
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap uppercase">
<?php echo $result['status']; ?>
</th>
<td class="px-6 py-4">
<?php echo $result['error_type'] ?? '-'; ?>
</td>
<td class="px-6 py-4">
<?php echo $result['error_message'] ?? '-'; ?>
</td>
<td class="px-6 py-4">
<?php echo $result['test_class']; ?>
</td>
<td class="px-6 py-4">
<?php echo $result['test_method']; ?>
</td>
<td class="px-6 py-4">
<?php echo isset($result['trace']) && trim($result['trace']) != '' ? $result['trace'] : '-'; ?>
</td>
</tr>
<?php }
} else {
foreach ($results as $result) {
?>
<tr class="bg-white border-b">
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
<?php echo $result; ?>
</th>
</tr>
<?php }
}
?>
</tbody>
</table>
</div>
</div>
</body>
</html>
<?php
$htmlContent = ob_get_clean();
file_put_contents(self::REPORT_FILE, $htmlContent);
}
/**
* Get HTML report as string
*/
public function getReport(): string
{
return file_get_contents(self::REPORT_FILE);
}
}