-
Notifications
You must be signed in to change notification settings - Fork 6
/
Channel.php
80 lines (63 loc) 路 1.57 KB
/
Channel.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
<?php
namespace Lloople\PHPUnitExtensions\Runners\SlowestTests;
use PHPUnit\Runner\AfterLastTestHook;
use PHPUnit\Runner\AfterTestHook;
abstract class Channel implements AfterTestHook, AfterLastTestHook
{
/**
* Tests marked as slow.
*
* @var array
*/
protected $tests = [];
/**
* The max number of rows to be reported.
*
* @var int|null
*/
protected $rows;
/**
* The minimum amount of miliseconds to consider a test slow.
*
* @var int|null
*/
protected $min;
public function __construct(?int $rows = null, ?int $min = 200)
{
$this->rows = $rows;
$this->min = $min;
}
public function executeAfterTest(string $test, float $time): void
{
$time = $this->timeToMiliseconds($time);
if ($time <= $this->min) {
return;
}
$this->tests[$test] = $time;
}
protected function timeToMiliseconds(float $time): int
{
return (int)($time * 1000);
}
public function executeAfterLastTest(): void
{
$this->sortTestsBySpeed();
$this->printResults();
}
protected function sortTestsBySpeed(): void
{
arsort($this->tests);
}
abstract protected function printResults(): void;
protected function testsToPrint(): array
{
if ($this->rows === null) {
return $this->tests;
}
return array_slice($this->tests, 0, $this->rows, true);
}
protected function getClassName(): string
{
return get_class($this);
}
}