Passed
Push — master ( 022b37...3bb133 )
by Maurício
07:36
created

ServerBinlogControllerTest::testIndex()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 146
Code Lines 102

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 102
dl 0
loc 146
rs 8
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
/* vim: set expandtab sw=4 ts=4 sts=4: */
3
/**
4
 * Holds ServerBinlogControllerTest
5
 *
6
 * @package PhpMyAdmin-test
7
 */
8
declare(strict_types=1);
9
10
namespace PhpMyAdmin\Tests\Controllers\Server;
11
12
use PhpMyAdmin\Config;
13
use PhpMyAdmin\Controllers\Server\ServerBinlogController;
14
use PhpMyAdmin\DatabaseInterface;
15
use PhpMyAdmin\Response;
16
use PhpMyAdmin\Util;
17
use PHPUnit\Framework\TestCase;
18
19
/**
20
 * Tests for ServerCollationsController class
21
 *
22
 * @package PhpMyAdmin-test
23
 */
24
class ServerBinlogControllerTest extends TestCase
25
{
26
    /**
27
     * Prepares environment for the test.
28
     *
29
     * @return void
30
     */
31
    protected function setUp(): void
32
    {
33
        $GLOBALS['PMA_Config'] = new Config();
34
        $GLOBALS['PMA_Config']->enableBc();
35
36
        $GLOBALS['cfg']['MaxRows'] = 10;
37
        $GLOBALS['cfg']['ServerDefault'] = 'server';
38
        $GLOBALS['cfg']['Server']['DisableIS'] = false;
39
40
        $GLOBALS['server'] = 1;
41
        $GLOBALS['db'] = 'db';
42
        $GLOBALS['table'] = 'table';
43
        $GLOBALS['pmaThemeImage'] = 'image';
44
        $GLOBALS['PMA_PHP_SELF'] = 'index.php';
45
46
        Util::cacheSet('profiling_supported', true);
47
    }
48
49
    /**
50
     * @return void
51
     */
52
    public function testIndex(): void
53
    {
54
        $binaryLogs = [
55
            [
56
                'Log_name' => 'index1',
57
                'File_size' => 100,
58
            ],
59
            [
60
                'Log_name' => 'index2',
61
                'File_size' => 200,
62
            ],
63
        ];
64
        $result = [
65
            [
66
                "SHOW BINLOG EVENTS IN 'index1' LIMIT 3, 10",
67
                null,
68
                1,
69
                true,
70
                ['log1' => 'logd'],
71
            ],
72
            [
73
                ['log2' => 'logb'],
74
                null,
75
                0,
76
                false,
77
                'executed',
78
            ],
79
        ];
80
        $value = [
81
            'Info' => 'index1_Info',
82
            'Log_name' => 'index1_Log_name',
83
            'Pos' => 'index1_Pos',
84
            'Event_type' => 'index1_Event_type',
85
            'Orig_log_pos' => 'index1_Orig_log_pos',
86
            'End_log_pos' => 'index1_End_log_pos',
87
            'Server_id' => 'index1_Server_id',
88
        ];
89
        $count = 3;
90
91
        $dbi = $this->getMockBuilder(DatabaseInterface::class)
92
            ->disableOriginalConstructor()
93
            ->getMock();
94
        $dbi->expects($this->once())->method('fetchResult')
95
            ->will($this->returnValue($binaryLogs));
96
        $dbi->expects($this->once())->method('query')
97
            ->will($this->returnValue($result));
98
        $dbi->expects($this->once())->method('numRows')
99
            ->will($this->returnValue($count));
100
        $dbi->expects($this->at(3))->method('fetchAssoc')
101
            ->will($this->returnValue($value));
102
        $dbi->expects($this->at(4))->method('fetchAssoc')
103
            ->will($this->returnValue(false));
104
105
        $controller = new ServerBinlogController(
106
            Response::getInstance(),
107
            $dbi
108
        );
109
        $actual = $controller->indexAction([
110
            'log' => 'index1',
111
            'pos' => '3',
112
            'is_full_query' => null,
113
        ]);
114
115
        $this->assertContains(
116
            'Select binary log to view',
117
            $actual
118
        );
119
        $this->assertContains(
120
            '<option value="index1" selected>',
121
            $actual
122
        );
123
        $this->assertContains(
124
            '<option value="index2">',
125
            $actual
126
        );
127
128
        $this->assertContains(
129
            'Your SQL query has been executed successfully',
130
            $actual
131
        );
132
133
        $this->assertContains(
134
            "SHOW BINLOG EVENTS IN 'index1' LIMIT 3, 10",
135
            $actual
136
        );
137
138
        $this->assertContains(
139
            '<table id="binlogTable">',
140
            $actual
141
        );
142
143
        $urlNavigation = 'server_binlog.php" data-post="pos=3&amp;'
144
            . 'is_full_query=1&amp;server=1&amp';
145
        $this->assertContains(
146
            $urlNavigation,
147
            $actual
148
        );
149
        $this->assertContains(
150
            'title="Previous"',
151
            $actual
152
        );
153
154
        $this->assertContains(
155
            'Log name',
156
            $actual
157
        );
158
        $this->assertContains(
159
            'Position',
160
            $actual
161
        );
162
        $this->assertContains(
163
            'Event type',
164
            $actual
165
        );
166
        $this->assertContains(
167
            'Server ID',
168
            $actual
169
        );
170
        $this->assertContains(
171
            'Original position',
172
            $actual
173
        );
174
175
        $this->assertContains(
176
            $value['Log_name'],
177
            $actual
178
        );
179
        $this->assertContains(
180
            $value['Pos'],
181
            $actual
182
        );
183
        $this->assertContains(
184
            $value['Event_type'],
185
            $actual
186
        );
187
        $this->assertContains(
188
            $value['Server_id'],
189
            $actual
190
        );
191
        $this->assertContains(
192
            $value['Orig_log_pos'],
193
            $actual
194
        );
195
        $this->assertContains(
196
            $value['Info'],
197
            $actual
198
        );
199
    }
200
}
201