-
Notifications
You must be signed in to change notification settings - Fork 6
/
ProfilerTest.php
69 lines (51 loc) · 1.6 KB
/
ProfilerTest.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
<?php
namespace TestTools\Tests\Profiler;
use TestTools\Profiler\Profiler;
use PHPUnit\Framework\TestCase;
/**
* @author Michael Mayer <michael@lastzero.net>
* @package TestTools
* @license MIT
*/
class ProfilerTest extends TestCase
{
public function setUp()
{
Profiler::clear();
}
public function testAddStep () {
Profiler::start();
usleep(20000);
Profiler::addStep('Foo');
usleep(50000);
Profiler::addSilentStep('Bar');
usleep(12000);
Profiler::stop();
$result = Profiler::getResultAsTable();
$this->assertContains('Foo', $result);
$this->assertContains('Start', $result);
$this->assertContains('Done', $result);
$this->assertNotContains('Bar', $result);
}
public function testAggregate () {
Profiler::start('Start Aggregate');
for($i = 0; $i < 23; $i++) {
Profiler::startAggregate('Foo', 'Bar');
usleep(5000);
Profiler::stopAggregate('Foo', 'Bar');
}
for($i = 0; $i < 19; $i++) {
Profiler::startAggregate('Foo', 'Baz');
usleep(2000);
Profiler::stopAggregate('Foo', 'Baz');
}
Profiler::stop();
$result = Profiler::getResultAsTable();
$this->assertContains('Foo', $result); // Aggregation label
$this->assertContains('Bar', $result);
$this->assertContains('Baz', $result);
$this->assertContains('42', $result); // Aggregated count
$this->assertContains('23', $result);
$this->assertContains('19', $result);
}
}