|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* ScoreSpec.php |
|
5
|
|
|
* |
|
6
|
|
|
* This file tests the behavior of the Score class. |
|
7
|
|
|
* |
|
8
|
|
|
* PHP version 7.4 |
|
9
|
|
|
* |
|
10
|
|
|
* @category Core |
|
11
|
|
|
* @package RedboxTestSuite |
|
12
|
|
|
* @author Johnny Mast <[email protected]> |
|
13
|
|
|
* @license https://opensource.org/licenses/MIT MIT |
|
14
|
|
|
* @link https://github.com/johnnymast/redbox-testsuite |
|
15
|
|
|
* @since 1.0 |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace spec\Redbox\Testsuite; |
|
19
|
|
|
|
|
20
|
|
|
use PhpSpec\ObjectBehavior; |
|
21
|
|
|
use Redbox\Testsuite\Score; |
|
22
|
|
|
use Redbox\Testsuite\Tests\Assets\MockableTestCase; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class ScoreSpec |
|
26
|
|
|
* |
|
27
|
|
|
* @package spec\Redbox\Testsuite |
|
28
|
|
|
*/ |
|
29
|
|
|
class ScoreSpec extends ObjectBehavior |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* This function is run before every test. |
|
33
|
|
|
* |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
|
|
function let() |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
$this->beConstructedWith(MockableTestCase::createWith(0, 0, 200)); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Test the Score class is initializable. |
|
43
|
|
|
* |
|
44
|
|
|
* @return void |
|
45
|
|
|
*/ |
|
46
|
|
|
function it_is_initializable() |
|
|
|
|
|
|
47
|
|
|
{ |
|
48
|
|
|
$this->shouldHaveType(Score::class); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Test the score and be set and later be returned via get. |
|
53
|
|
|
* |
|
54
|
|
|
* @return void |
|
55
|
|
|
*/ |
|
56
|
|
|
function it_should_be_able_to_set_and_get_the_score() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->setScore(5); |
|
|
|
|
|
|
59
|
|
|
$this->getScore()->shouldBe(5); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Test that default score in the class is set to 0. |
|
64
|
|
|
* |
|
65
|
|
|
* @return void |
|
66
|
|
|
*/ |
|
67
|
|
|
function it_the_default_value_for_scores_is_0() |
|
68
|
|
|
{ |
|
69
|
|
|
$this->getScore()->shouldBe(0); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Test incrementing scores works correctly. |
|
74
|
|
|
* |
|
75
|
|
|
* @return void |
|
76
|
|
|
*/ |
|
77
|
|
|
function it_can_increment_scores() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->increment(1); |
|
|
|
|
|
|
80
|
|
|
$this->getScore()->shouldBe(1); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Test that score motivations and answers work. |
|
85
|
|
|
* |
|
86
|
|
|
* @return void |
|
87
|
|
|
*/ |
|
88
|
|
|
function it_can_increment_scores_and_leave_a_motivation() |
|
89
|
|
|
{ |
|
90
|
|
|
$this->increment(1, 'Hello World', 'My answer'); |
|
91
|
|
|
$this->getScoreInfo()[0]->shouldContain('Hello World'); |
|
|
|
|
|
|
92
|
|
|
$this->getScoreInfo()[0]->shouldContain('My answer'); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Testing the average of 7 is calculated correctly. |
|
97
|
|
|
* |
|
98
|
|
|
* @return void |
|
99
|
|
|
*/ |
|
100
|
|
|
function it_can_calculate_the_average_of_total_7() |
|
101
|
|
|
{ |
|
102
|
|
|
$this->increment(2); |
|
103
|
|
|
$this->increment(2); |
|
104
|
|
|
$this->increment(3); |
|
105
|
|
|
$this->average()->shouldBeDouble(2.3333333333333); |
|
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Testing the average of 9 is calculated correctly. |
|
110
|
|
|
* |
|
111
|
|
|
* @return void |
|
112
|
|
|
*/ |
|
113
|
|
|
function it_can_calculate_the_average_of_total_9() |
|
114
|
|
|
{ |
|
115
|
|
|
$this->increment(3); |
|
116
|
|
|
$this->increment(3); |
|
117
|
|
|
$this->increment(3); |
|
118
|
|
|
$this->average()->shouldBe(3); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Testing the average of 12 is calculated correctly. |
|
123
|
|
|
* |
|
124
|
|
|
* @return void |
|
125
|
|
|
*/ |
|
126
|
|
|
function it_can_calculate_the_average_of_total_12() |
|
127
|
|
|
{ |
|
128
|
|
|
$this->increment(3); |
|
129
|
|
|
$this->increment(3); |
|
130
|
|
|
$this->increment(3); |
|
131
|
|
|
$this->increment(3); |
|
132
|
|
|
$this->average()->shouldBe(3); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Test that score is calculating the percentage correctly. |
|
137
|
|
|
* |
|
138
|
|
|
* @return void |
|
139
|
|
|
*/ |
|
140
|
|
|
function it_can_calculate_a_score_percentage() |
|
141
|
|
|
{ |
|
142
|
|
|
$this->increment(11); |
|
143
|
|
|
$this->increment(11); |
|
144
|
|
|
$this->percentage()->shouldBeDouble(0.11); |
|
|
|
|
|
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Test the reset function. |
|
149
|
|
|
* |
|
150
|
|
|
* @return void |
|
151
|
|
|
*/ |
|
152
|
|
|
function it_should_reset_values_to_default_using_reset() |
|
153
|
|
|
{ |
|
154
|
|
|
$this->increment(11); |
|
155
|
|
|
$this->increment(11); |
|
156
|
|
|
$this->reset(); |
|
|
|
|
|
|
157
|
|
|
|
|
158
|
|
|
$this->getScore()->shouldReturn(0); |
|
159
|
|
|
$this->getIncrements()->shouldReturn(0); |
|
|
|
|
|
|
160
|
|
|
$this->getScoreInfo()->shouldHaveCount(0); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Test if the setName and getName methods works correctly. |
|
165
|
|
|
* |
|
166
|
|
|
* @return void |
|
167
|
|
|
*/ |
|
168
|
|
|
function it_can_set_and_get_the_name_of_the_test() |
|
169
|
|
|
{ |
|
170
|
|
|
$this->getTest()->setName('__EEK__'); |
|
|
|
|
|
|
171
|
|
|
$this->getTest()->getName()->shouldReturn('__EEK__'); |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.