-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResult.php
More file actions
117 lines (97 loc) · 2.79 KB
/
Copy pathResult.php
File metadata and controls
117 lines (97 loc) · 2.79 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
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
<?php
declare(strict_types=1);
namespace PHPCensor\Plugins\Testing\PhpUnit;
use PHPCensor\Common\Exception\Exception;
/**
* Class Result parses the results for the PhpUnitV2 plugin
*
* @package PHP Censor
* @subpackage Plugins
*
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
* @author Pablo Tejada <pablo@ptejada.com>
*/
abstract class Result
{
public const SEVERITY_PASS = 'success';
public const SEVERITY_FAIL = 'fail';
public const SEVERITY_ERROR = 'error';
public const SEVERITY_SKIPPED = 'skipped';
public const SEVERITY_WARN = self::SEVERITY_PASS;
public const SEVERITY_RISKY = self::SEVERITY_PASS;
protected array $results;
protected int $failures = 0;
protected array $errors = [];
public function __construct(
protected string $outputFile,
protected string $buildPath = ''
) {
}
/**
* Parse the results
*
* @return $this
*
* @throws Exception If fails to parse the output
*/
abstract public function parse(): Result;
abstract protected function getSeverity(mixed $testCase): string;
abstract protected function buildMessage(mixed $testCase): string;
abstract protected function buildTrace(mixed $testCase): array;
protected function getFileAndLine(mixed $testCase): array
{
return $testCase;
}
protected function getOutput(mixed $testCase): string
{
return $testCase['output'];
}
protected function parseTestcase(mixed $testCase): void
{
$severity = $this->getSeverity($testCase);
$pass = isset(\array_fill_keys([self::SEVERITY_PASS, self::SEVERITY_SKIPPED], true)[$severity]);
$data = [
'pass' => $pass,
'severity' => $severity,
'message' => $this->buildMessage($testCase),
'trace' => $pass ? [] : $this->buildTrace($testCase),
'output' => $this->getOutput($testCase),
];
if (!$pass) {
$this->failures++;
$info = $this->getFileAndLine($testCase);
$this->errors[] = [
'message' => $data['message'],
'severity' => $severity,
'file' => $info['file'],
'line' => $info['line'],
];
}
$this->results[] = $data;
}
/**
* Get the parse results
*
* @return string[]
*/
public function getResults(): array
{
return $this->results;
}
/**
* Get the total number of failing tests
*/
public function getFailures(): int
{
return $this->failures;
}
/**
* Get the tests with failing status
*
* @return array[]
*/
public function getErrors(): array
{
return $this->errors;
}
}