ScoreSpec   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 143
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 143
rs 10
c 0
b 0
f 0
wmc 12

12 Methods

Rating   Name   Duplication   Size   Complexity  
A it_can_set_and_get_the_name_of_the_test() 0 4 1
A it_can_increment_scores() 0 4 1
A it_is_initializable() 0 3 1
A let() 0 3 1
A it_can_calculate_the_average_of_total_9() 0 6 1
A it_can_calculate_the_average_of_total_12() 0 7 1
A it_can_increment_scores_and_leave_a_motivation() 0 5 1
A it_the_default_value_for_scores_is_0() 0 3 1
A it_can_calculate_the_average_of_total_7() 0 6 1
A it_can_calculate_a_score_percentage() 0 5 1
A it_should_be_able_to_set_and_get_the_score() 0 4 1
A it_should_reset_values_to_default_using_reset() 0 9 1
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()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method setScore() does not exist on spec\Redbox\Testsuite\ScoreSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
        $this->/** @scrutinizer ignore-call */ 
59
               setScore(5);
Loading history...
59
        $this->getScore()->shouldBe(5);
0 ignored issues
show
Bug introduced by
The method getScore() does not exist on spec\Redbox\Testsuite\ScoreSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
        $this->/** @scrutinizer ignore-call */ 
60
               getScore()->shouldBe(5);
Loading history...
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);
0 ignored issues
show
Bug introduced by
The method increment() does not exist on spec\Redbox\Testsuite\ScoreSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

79
        $this->/** @scrutinizer ignore-call */ 
80
               increment(1);
Loading history...
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');
0 ignored issues
show
Bug introduced by
The method getScoreInfo() does not exist on spec\Redbox\Testsuite\ScoreSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

91
        $this->/** @scrutinizer ignore-call */ 
92
               getScoreInfo()[0]->shouldContain('Hello World');
Loading history...
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);
0 ignored issues
show
Bug introduced by
The method average() does not exist on spec\Redbox\Testsuite\ScoreSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
        $this->/** @scrutinizer ignore-call */ 
106
               average()->shouldBeDouble(2.3333333333333);
Loading history...
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);
0 ignored issues
show
Bug introduced by
The method percentage() does not exist on spec\Redbox\Testsuite\ScoreSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

144
        $this->/** @scrutinizer ignore-call */ 
145
               percentage()->shouldBeDouble(0.11);
Loading history...
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();
0 ignored issues
show
Bug introduced by
The method reset() does not exist on spec\Redbox\Testsuite\ScoreSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

156
        $this->/** @scrutinizer ignore-call */ 
157
               reset();
Loading history...
157
        
158
        $this->getScore()->shouldReturn(0);
159
        $this->getIncrements()->shouldReturn(0);
0 ignored issues
show
Bug introduced by
The method getIncrements() does not exist on spec\Redbox\Testsuite\ScoreSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

159
        $this->/** @scrutinizer ignore-call */ 
160
               getIncrements()->shouldReturn(0);
Loading history...
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__');
0 ignored issues
show
Bug introduced by
The method getTest() does not exist on spec\Redbox\Testsuite\ScoreSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

170
        $this->/** @scrutinizer ignore-call */ 
171
               getTest()->setName('__EEK__');
Loading history...
171
        $this->getTest()->getName()->shouldReturn('__EEK__');
172
    }
173
}
174