Repository navigation
Expand file tree
/
Copy pathReportPrinter.php
More file actions
132 lines (112 loc) · 3.75 KB
/
Copy pathReportPrinter.php
File metadata and controls
132 lines (112 loc) · 3.75 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
namespace Codeception\Reporter;
use Codeception\Event\FailEvent;
use Codeception\Event\PrintResultEvent;
use Codeception\Event\TestEvent;
use Codeception\Events;
use Codeception\Lib\Console\Message;
use Codeception\Lib\Console\Output;
use Codeception\Lib\Interfaces\ConsolePrinter;
use Codeception\Subscriber\Shared\StaticEventsTrait;
use Codeception\Test\Descriptor;
use Codeception\Test\Test;
class ReportPrinter implements ConsolePrinter
{
use StaticEventsTrait;
/**
* @var array<string, string>
*/
protected static array $events = [
Events::TEST_SUCCESS => 'testSuccess',
Events::TEST_FAIL => 'testFailure',
Events::TEST_ERROR => 'testError',
Events::TEST_INCOMPLETE => 'testIncomplete',
Events::TEST_SKIPPED => 'testSkipped',
Events::TEST_WARNING => 'testWarning',
Events::TEST_USELESS => 'testUseless',
Events::RESULT_PRINT_AFTER => 'afterResult',
];
private Output $output;
private int $successfulCount = 0;
private int $errorCount = 0;
private int $failureCount = 0;
private int $warningCount = 0;
private int $skippedCount = 0;
private int $incompleteCount = 0;
private int $uselessCount = 0;
public function __construct(array $options)
{
$this->output = new Output($options);
}
private function message(string $string = ''): Message
{
return $this->output->message($string);
}
public function testSuccess(TestEvent $event): void
{
$this->printTestResult($event->getTest(), 'Ok');
$this->successfulCount++;
}
public function testError(FailEvent $event): void
{
$this->printTestResult($event->getTest(), 'ERROR');
$this->errorCount++;
}
public function testFailure(FailEvent $event): void
{
$this->printTestResult($event->getTest(), "\033[41;37mFAIL\033[0m");
$this->failureCount++;
}
public function testWarning(FailEvent $event): void
{
$this->printTestResult($event->getTest(), 'WARNING');
$this->warningCount++;
}
public function testSkipped(FailEvent $event): void
{
$this->printTestResult($event->getTest(), 'Skipped');
$this->skippedCount++;
}
public function testIncomplete(FailEvent $event): void
{
$this->printTestResult($event->getTest(), 'Incomplete');
$this->incompleteCount++;
}
public function testUseless(FailEvent $event): void
{
$this->printTestResult($event->getTest(), 'Useless');
$this->uselessCount++;
}
private function printTestResult(Test $test, string $status): void
{
$name = Descriptor::getTestAsString($test);
if (strlen($name) > 75) {
$name = substr($name, 0, 70);
}
$this->message($name)
->width(75, '.')
->append($status)
->writeln();
}
public function afterResult(PrintResultEvent $event): void
{
$counts = [
sprintf("Successful: %s", $this->successfulCount)
];
$failedCount = $this->errorCount + $this->errorCount + $this->warningCount;
if ($failedCount > 0) {
$counts [] = sprintf("Failed: %s", $failedCount);
}
if ($this->incompleteCount > 0) {
$counts [] = sprintf("Incomplete: %s", $this->incompleteCount);
}
if ($this->skippedCount > 0) {
$counts [] = sprintf("Skipped: %s", $this->skippedCount);
}
if ($this->uselessCount > 0) {
$counts [] = sprintf("Useless: %s", $this->uselessCount);
}
$this->output->writeln("\nCodeception Results");
$this->output->writeln(implode('. ', $counts) . '.');
}
}