Passed
Push — master ( d8d9c6...e02ef8 )
by Pedro
02:22
created

BotParserTest::testPositionQuest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 70
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 44
dl 0
loc 70
rs 9.216
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace ApplicationTest\Service;
4
5
use Zend\Stdlib\ArrayUtils;
6
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
7
use Application\Service\BotParser;
8
9
class BotParserTest extends AbstractHttpControllerTestCase
10
{
11
    public function setUp()
12
    {
13
        // The module configuration should still be applicable for tests.
14
        // You can override configuration here with test case specific values,
15
        // such as sample view templates, path stacks, module_listener_options,
16
        // etc.
17
        $configOverrides = [];
18
19
        $this->setApplicationConfig(ArrayUtils::merge(
20
            include __DIR__ . '/../../../../config/application.config.php',
21
            $configOverrides
22
        ));
23
24
          parent::setUp();
25
    }
26
27
    public function testPositionQuest()
28
    {
29
        $testcase = 'questinfo-position.txt';
30
        $config = [
31
            'bot_quest' => __DIR__ . '/../testcases/' . $testcase,
32
        ];
33
34
        $parser = new BotParser($config);
35
        $db = $parser->getQuestData();
36
37
        // Title
38
        $this->assertEquals('lay waste to the Towers of Ankh-Allor, wherein lies the terrible sorceror Croocq', $db['title']);
39
40
        // Type
41
        $this->assertEquals(2, $db['type']);
42
43
        // Current stage
44
        $this->assertEquals(1, $db['objective']);
45
46
        // Number of stages
47
        $this->assertEquals(2, count($db['stages']));
48
49
        // Stage 1
50
        $this->assertEquals([
51
            'x_pos' => 225,
52
            'y_pos' => 315,
53
            'color' => '#d30000',
54
        ], $db['stages'][0]);
55
56
        // Stage 2
57
        $this->assertEquals([
58
            'x_pos' => 280,
59
            'y_pos' => 360,
60
            'color' => '#d30000',
61
        ], $db['stages'][1]);
62
63
        // Number of players
64
        $this->assertEquals(4, count($db['players']));
65
66
        // Player 1
67
        $this->assertEquals([
68
            'nick'  => 'Orange',
69
            'x_pos' => 195,
70
            'y_pos' => 315,
71
            'color' => '#0080e1',
72
        ], $db['players'][0]);
73
74
        // Player 2
75
        $this->assertEquals([
76
            'nick'  => 'pi',
77
            'x_pos' => 225,
78
            'y_pos' => 270,
79
            'color' => '#0080e1',
80
        ], $db['players'][1]);
81
82
        // Player 3
83
        $this->assertEquals([
84
            'nick'  => 'BernardoRafael',
85
            'x_pos' => 225,
86
            'y_pos' => 315,
87
            'color' => '#0080e1',
88
        ], $db['players'][2]);
89
90
        // Player 4
91
        $this->assertEquals([
92
            'nick'  => 'pirilampo',
93
            'x_pos' => 225,
94
            'y_pos' => 315,
95
            'color' => '#0080e1',
96
        ], $db['players'][3]);
97
    }
98
99
    public function testTimeQuest()
100
    {
101
        $testcase = 'questinfo-time.txt';
102
        $config = [
103
            'bot_quest' => __DIR__ . '/../testcases/' . $testcase,
104
        ];
105
106
        $parser = new BotParser($config);
107
        $db = $parser->getQuestData();
108
109
        // Title
110
        $this->assertEquals('locate the herbs and brew the elixir to rid the realm of the Normonic Plague', $db['title']);
111
112
        // Type
113
        $this->assertEquals(1, $db['type']);
114
115
        // Current stage
116
        $this->assertEquals(1531325222, $db['objective_val']);
117
118
        // Number of players
119
        $this->assertEquals(4, count($db['players']));
120
121
        $this->assertEquals('RichardStallman', $db['players'][0]['nick']);
122
        $this->assertEquals('xhip', $db['players'][1]['nick']);
123
        $this->assertEquals('Infernvs', $db['players'][2]['nick']);
124
        $this->assertEquals('.hack', $db['players'][3]['nick']);
125
    }
126
127
    public function testScoreboard()
128
    {
129
        $testcase = 'irpg-scoreboard.db';
130
        $config = [
131
            'bot_db' => __DIR__ . '/../testcases/' . $testcase,
132
        ];
133
134
        $parser = new BotParser($config);
135
        $scoreboard = $parser->getScoreboard();
136
137
        // Test the sorting method
138
        // flcl and fALSO have the same level, but flcl should be first
139
        // because he has a lower ttl
140
        $this->assertEquals('flcl', $scoreboard[0]['nick']);
141
        $this->assertEquals('fALSO', $scoreboard[1]['nick']);
142
143
        // Number of players
144
        $this->assertEquals(12, count($scoreboard));
145
146
        // Full data of the first player
147
        $this->assertEquals([
148
            'nick'    => 'flcl',
149
            'level'   => 43,
150
            'class'   => 'gordo',
151
            'ttl'     => '3 days 1 hour',
152
            'ttl_num' => 264103,
153
            'status'  => true
154
        ], $scoreboard[0]);
155
156
        // Full data of the last player
157
        $this->assertEquals([
158
            'nick'    => 'MalMen',
159
            'level'   => 26,
160
            'class'   => 'amen',
161
            'ttl'     => '1 hour 40 minutes',
162
            'ttl_num' => 6031,
163
            'status'  => true
164
        ], $scoreboard[11]);
165
    }
166
}
167