-
Notifications
You must be signed in to change notification settings - Fork 3
/
ProgressCounterTest.php
121 lines (103 loc) · 3.32 KB
/
ProgressCounterTest.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
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
<?php
namespace Concise\Console\ResultPrinter\Utilities;
use Concise\TestCase;
class ProgressCounterTest extends TestCase
{
public function testCounterStartsAtZero()
{
$counter = new ProgressCounter(1);
$this->assert($counter->render(), equals, '0 / 1');
}
public function testCounterTotalIsSetThroughTheConstructor()
{
$counter = new ProgressCounter(5);
$this->assert($counter->render(), equals, '0 / 5');
}
public function testRenderCanTakeANumber()
{
$counter = new ProgressCounter(5);
$this->assert($counter->render(3), equals, '3 / 5');
}
public function testPercentageCanBeActivatedWithConstructor()
{
$counter = new ProgressCounter(5, true);
$this->assert($counter->render(5), equals, '5 / 5 (100%)');
}
public function testPercentageIsCalculatedBasedOnValue()
{
$counter = new ProgressCounter(10, true);
$this->assert($counter->render(5), equals, '5 / 10 ( 50%)');
}
public function testPercentageIsAlwaysShownAsAWholeNumber()
{
$counter = new ProgressCounter(9, true);
$this->assert($counter->render(5), equals, '5 / 9 ( 55%)');
}
public function testPercentageMayBeOneDigit()
{
$counter = new ProgressCounter(100, true);
$this->assert($counter->render(5), equals, '5 / 100 ( 5%)');
}
public function testDivideByZeroWillYieldZeroPercent()
{
$counter = new ProgressCounter(0, true);
$this->assert($counter->render(0), equals, '0 / 0 ( 0%)');
}
/**
* @expectedException \DomainException
* @expectedExceptionMessage Total must be at least zero.
*/
public function testTotalMustBeAtLeastZero()
{
new ProgressCounter(-1);
}
/**
* @expectedException \DomainException
* @expectedExceptionMessage Value must be at least zero.
*/
public function testValueMustBeAtLeastZero()
{
$counter = new ProgressCounter(0);
$counter->render(-1);
}
public function testValueGreaterThanTotalWillCreateNewTotal()
{
$counter = new ProgressCounter(10);
$this->assert($counter->render(15), equals, '15 / 15');
}
public function testPercentageMaximumValueIs100()
{
$counter = new ProgressCounter(10, true);
$this->assert($counter->render(15), equals, '15 / 15 (100%)');
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Expected integer, but got string for argument 1
*/
public function testValueMustBeAnInteger()
{
$counter = new ProgressCounter(10, true);
$counter->render('foo');
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Expected integer, but got string for argument 1
*/
public function testTotalMustBeAnInteger()
{
new ProgressCounter('foo');
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Expected boolean, but got string for argument 2
*/
public function testShowPercentageMustBeAnInteger()
{
new ProgressCounter(123, 'foo');
}
public function testCanGetPercentage()
{
$counter = new ProgressCounter(5);
$this->assert($counter->getPercentage(1), equals, 20);
}
}