-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectorTest.php
More file actions
157 lines (137 loc) · 5.52 KB
/
CollectorTest.php
File metadata and controls
157 lines (137 loc) · 5.52 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php declare(strict_types=1);
namespace Tests\Timer;
use PHPUnit\Framework\TestCase;
/**
* 测试 php-timer\Timer\Collector
*
* @author fdipzone
*/
final class CollectorTest extends TestCase
{
/**
* @covers \Timer\Collector::__construct
*/
public function testConstruct()
{
$collector = new \Timer\Collector;
$this->assertEquals('Timer\Collector', get_class($collector));
}
/**
* @covers \Timer\Collector::start
*/
public function testStart()
{
$collector = new \Timer\Collector;
$this->assertEquals(\Timer\Collector::NOT_STARTED, \Tests\Utils\PHPUnitExtension::getVariable($collector, 'state'));
$collector->start();
$this->assertEquals(\Timer\Collector::STARTED, \Tests\Utils\PHPUnitExtension::getVariable($collector, 'state'));
}
/**
* @covers \Timer\Collector::start
*/
public function testStartStateException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('timer collector: the current state cannot be started');
$collector = new \Timer\Collector;
$this->assertEquals(\Timer\Collector::NOT_STARTED, \Tests\Utils\PHPUnitExtension::getVariable($collector, 'state'));
$collector->start();
$this->assertEquals(\Timer\Collector::STARTED, \Tests\Utils\PHPUnitExtension::getVariable($collector, 'state'));
$collector->start();
}
/**
* @covers \Timer\Collector::end
*/
public function testEnd()
{
$collector = new \Timer\Collector;
$this->assertEquals(\Timer\Collector::NOT_STARTED, \Tests\Utils\PHPUnitExtension::getVariable($collector, 'state'));
$collector->start();
$this->assertEquals(\Timer\Collector::STARTED, \Tests\Utils\PHPUnitExtension::getVariable($collector, 'state'));
$collector->end();
$this->assertEquals(\Timer\Collector::ENDED, \Tests\Utils\PHPUnitExtension::getVariable($collector, 'state'));
}
/**
* @covers \Timer\Collector::end
*/
public function testEndStateException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('timer collector: the current state cannot be ended');
$collector = new \Timer\Collector;
$this->assertEquals(\Timer\Collector::NOT_STARTED, \Tests\Utils\PHPUnitExtension::getVariable($collector, 'state'));
$collector->end();
}
/**
* @covers \Timer\Collector::savePoint
*/
public function testSavePoint()
{
$collector = new \Timer\Collector;
$this->assertEquals(\Timer\Collector::NOT_STARTED, \Tests\Utils\PHPUnitExtension::getVariable($collector, 'state'));
$collector->start();
$this->assertEquals(\Timer\Collector::STARTED, \Tests\Utils\PHPUnitExtension::getVariable($collector, 'state'));
$collector->savePoint('event 1');
$collector->savePoint('event2');
$this->assertEquals(\Timer\Collector::STARTED, \Tests\Utils\PHPUnitExtension::getVariable($collector, 'state'));
$collector->end();
$this->assertEquals(\Timer\Collector::ENDED, \Tests\Utils\PHPUnitExtension::getVariable($collector, 'state'));
$this->assertSame(4, count($collector->timeline()->events()));
}
/**
* @covers \Timer\Collector::savePoint
*/
public function testSavePointStateException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('timer collector: the current state cannot be save point');
$collector = new \Timer\Collector;
$this->assertEquals(\Timer\Collector::NOT_STARTED, \Tests\Utils\PHPUnitExtension::getVariable($collector, 'state'));
$collector->savePoint('event');
}
/**
* @covers \Timer\Collector::savePoint
*/
public function testSavePointContentException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('timer collector: save point content is empty');
$collector = new \Timer\Collector;
$this->assertEquals(\Timer\Collector::NOT_STARTED, \Tests\Utils\PHPUnitExtension::getVariable($collector, 'state'));
$collector->start();
$this->assertEquals(\Timer\Collector::STARTED, \Tests\Utils\PHPUnitExtension::getVariable($collector, 'state'));
$collector->savePoint('');
}
/**
* @covers \Timer\Collector::timeline
*/
public function testTimeline()
{
$collector = new \Timer\Collector;
$collector->start();
$collector->end();
$this->assertSame(2, count($collector->timeline()->events()));
}
/**
* @covers \Timer\Collector::timeline
*/
public function testTimelineStateException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('timer collector: the current state cannot be get timeline');
$collector = new \Timer\Collector;
$this->assertEquals(\Timer\Collector::NOT_STARTED, \Tests\Utils\PHPUnitExtension::getVariable($collector, 'state'));
$collector->start();
$this->assertEquals(\Timer\Collector::STARTED, \Tests\Utils\PHPUnitExtension::getVariable($collector, 'state'));
$collector->timeline();
}
/**
* @covers \Timer\Collector::getMilliSecondTimestamp
*/
public function testGetMilliSecondTimestamp()
{
$collector = new \Timer\Collector;
$millisecond_timestamp = \Tests\Utils\PHPUnitExtension::callMethod($collector, 'getMilliSecondTimestamp', []);
$this->assertTrue($millisecond_timestamp>0);
}
}