|
1
|
|
|
<?php |
|
2
|
|
|
namespace Bedd\Timer; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* TimerTest |
|
6
|
|
|
*/ |
|
7
|
|
|
class TimerTest extends \PHPUnit_Framework_TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
/** @var Timer */ |
|
10
|
|
|
private $timer = null; |
|
11
|
|
|
|
|
12
|
|
|
public function setUp() |
|
13
|
|
|
{ |
|
14
|
|
|
$this->timer = Timer::getInstance('name'); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Test the instance types |
|
19
|
|
|
*/ |
|
20
|
|
|
public function testTypes() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->assertInstanceOf(Timer::class, $this->timer); |
|
23
|
|
|
$this->assertNotSame($this->timer, new Timer()); |
|
24
|
|
|
$this->assertSame($this->timer, Timer::getInstance('name')); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Test the init status |
|
29
|
|
|
*/ |
|
30
|
|
|
public function testInitialized() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->assertSame($this->timer->getStatus(), Timer::STATUS_INITIALIZED); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Test for Timer->getSummary() |
|
37
|
|
|
*/ |
|
38
|
|
|
public function testGetSummary() |
|
39
|
|
|
{ |
|
40
|
|
|
$summary = $this->timer->getSummary(); |
|
41
|
|
|
$this->assertArrayHasKey('status', $summary); |
|
42
|
|
|
$this->assertArrayHasKey('start', $summary); |
|
43
|
|
|
$this->assertArrayHasKey('end', $summary); |
|
44
|
|
|
$this->assertArrayHasKey('total', $summary); |
|
45
|
|
|
$this->assertArrayHasKey('paused', $summary); |
|
46
|
|
|
$this->assertArrayHasKey('laps', $summary); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testStart() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->timer->start(); |
|
52
|
|
|
$this->assertSame($this->timer->getStatus(), Timer::STATUS_RUNNING); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testPause() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->timer->pause(); |
|
58
|
|
|
$this->assertSame($this->timer->getStatus(), Timer::STATUS_PAUSED); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testUnpause() |
|
62
|
|
|
{ |
|
63
|
|
|
$this->timer->unpause(); |
|
64
|
|
|
$this->assertSame($this->timer->getStatus(), Timer::STATUS_RUNNING); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testEnd() |
|
68
|
|
|
{ |
|
69
|
|
|
$this->timer->end(); |
|
70
|
|
|
$this->assertSame($this->timer->getStatus(), Timer::STATUS_ENDED); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testReset() |
|
74
|
|
|
{ |
|
75
|
|
|
$summary = $this->timer->getSummary(); |
|
76
|
|
|
$this->timer->reset(); |
|
77
|
|
|
$this->assertSame($this->timer->getStatus(), Timer::STATUS_INITIALIZED); |
|
78
|
|
|
$this->assertNotSame($summary, $this->timer->getSummary()); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function testAddLap() |
|
82
|
|
|
{ |
|
83
|
|
|
$summary1 = $this->timer->getSummary(); |
|
84
|
|
|
$this->timer->addLap(); |
|
85
|
|
|
$this->timer->addLap(); |
|
86
|
|
|
$this->timer->addLap(); |
|
87
|
|
|
$this->timer->addLap(); |
|
88
|
|
|
$summary2 = $this->timer->getSummary(); |
|
89
|
|
|
$this->assertGreaterThan(count($summary1['laps']), count($summary2['laps'])); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|