1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace whm\Smoke\Extensions\SmokeReporter\Reporter; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
6
|
|
|
use whm\Smoke\Config\Configuration; |
7
|
|
|
use whm\Smoke\Extensions\SmokeResponseRetriever\Retriever\Retriever; |
8
|
|
|
use whm\Smoke\Rules\CheckResult; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class HtmlReporter implements Reporter |
12
|
|
|
{ |
13
|
|
|
private $results = []; |
14
|
|
|
private $successes = []; |
15
|
|
|
private $failures = []; |
16
|
|
|
private $unknowns = []; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var Configuration |
21
|
|
|
*/ |
22
|
|
|
private $templateDir; |
23
|
|
|
private $templateFile; |
24
|
|
|
private $resultFile; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var OutputInterface |
28
|
|
|
*/ |
29
|
|
|
private $output; |
30
|
|
|
|
31
|
|
|
public function init(OutputInterface $_output, $resultFile, $templateDir = null, $templateFile = 'index.html.twig') |
32
|
|
|
{ |
33
|
|
|
$this->resultFile = $resultFile; |
34
|
|
|
|
35
|
|
|
if ($templateDir === null) { |
36
|
|
|
$this->templateDir = __DIR__ . '/templates'; |
|
|
|
|
37
|
|
|
} else { |
38
|
|
|
$this->templateDir = $templateDir; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$this->templateFile = $templateFile; |
42
|
|
|
$this->output = $_output; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param CheckResult[] $results |
47
|
|
|
*/ |
48
|
|
|
public function processResults($results) |
49
|
|
|
{ |
50
|
|
|
foreach ($results as $result) { |
51
|
|
|
$temp = [ |
52
|
|
|
'url' => $result->getResponse()->getUri(), |
53
|
|
|
'rule' => $result->getRuleName(), |
54
|
|
|
'message' => $result->getMessage(), |
55
|
|
|
'status' => $result->getStatus(), |
56
|
|
|
]; |
57
|
|
|
|
58
|
|
|
switch ($result->getStatus()) { |
59
|
|
|
case CheckResult::STATUS_SUCCESS: |
60
|
|
|
$this->successes[] = $temp; |
61
|
|
|
break; |
62
|
|
|
|
63
|
|
|
case CheckResult::STATUS_FAILURE: |
64
|
|
|
$this->failures[] = $temp; |
65
|
|
|
break; |
66
|
|
|
default: |
67
|
|
|
$this->unknowns[] = $temp; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$this->results[] = $temp; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function finish() |
75
|
|
|
{ |
76
|
|
|
$loader = new \Twig_Loader_Filesystem($this->templateDir); |
|
|
|
|
77
|
|
|
$twig = new \Twig_Environment($loader); |
78
|
|
|
|
79
|
|
|
$html = $twig->render($this->templateFile, [ |
80
|
|
|
'results' => $this->results, |
81
|
|
|
'successes' => $this->successes, |
82
|
|
|
'failures' => $this->failures, |
83
|
|
|
'unknowns' => $this->unknowns, |
84
|
|
|
'success' => count($this->successes), |
85
|
|
|
'failure' => count($this->failures), |
86
|
|
|
'unknown' => count($this->unknowns), |
87
|
|
|
'total' => count($this->results), |
88
|
|
|
]); |
89
|
|
|
|
90
|
|
|
if (!file_exists(dirname($this->resultFile))) { |
91
|
|
|
mkdir(dirname($this->resultFile)); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
if (!file_put_contents($this->resultFile, $html)) { |
95
|
|
|
$this->output->writeln("<error>HTML Reporter extension: Could not write result file to " . $this->resultFile ."</error>"); |
96
|
|
|
} else { |
97
|
|
|
$this->output->writeln("<info>HTML Reporter extension:</info> Result file written to " . $this->resultFile); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..