-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathSimpleReporter.php
More file actions
68 lines (57 loc) · 1.71 KB
/
SimpleReporter.php
File metadata and controls
68 lines (57 loc) · 1.71 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
<?php
declare(strict_types=1);
namespace Codeception\Extension;
use Codeception\Event\TestEvent;
use Codeception\Events;
use Codeception\Extension;
use Codeception\Test\Descriptor;
/**
* This extension demonstrates how you can implement console output of your own.
* Recommended to be used for development purposes only.
*/
class SimpleReporter extends Extension
{
public function _initialize(): void
{
$this->_reconfigure(['settings' => ['silent' => true]]); // turn off printing for everything else
}
/**
* We are listening for events
*
* @var array<string, string>
*/
public static array $events = [
Events::SUITE_BEFORE => 'beforeSuite',
Events::TEST_END => 'after',
Events::TEST_SUCCESS => 'success',
Events::TEST_FAIL => 'fail',
Events::TEST_ERROR => 'error',
];
public function beforeSuite(): void
{
$this->output->writeln('');
}
public function success(): void
{
$this->output->write('[+] ');
}
public function fail(): void
{
$this->output->write('[-] ');
}
public function error(): void
{
$this->output->write('[E] ');
}
// we are printing test status and time taken
public function after(TestEvent $event): void
{
$secondsInput = $event->getTime();
// See https://stackoverflow.com/q/16825240
$milliseconds = (int)($secondsInput * 1000);
$seconds = (int)($milliseconds / 1000);
$time = ($seconds % 60) . (($milliseconds === 0) ? '' : '.' . $milliseconds);
$this->output->write(Descriptor::getTestSignature($event->getTest()));
$this->output->writeln(' (' . $time . 's)');
}
}