Conditions | 1 |
Paths | 1 |
Total Lines | 87 |
Code Lines | 61 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
26 | public function testIndex(): void |
||
27 | { |
||
28 | global $dbi, $db, $table, $server, $cfg, $PMA_PHP_SELF, $is_grantuser, $is_createuser; |
||
29 | |||
30 | $db = 'db'; |
||
31 | $table = 'table'; |
||
32 | $server = 0; |
||
33 | $cfg['Server']['DisableIS'] = false; |
||
34 | $PMA_PHP_SELF = 'index.php'; |
||
35 | $is_grantuser = true; |
||
36 | $is_createuser = true; |
||
37 | |||
38 | $privileges = []; |
||
39 | |||
40 | $serverPrivileges = $this->createMock(Privileges::class); |
||
41 | $serverPrivileges->method('getAllPrivileges') |
||
42 | ->willReturn($privileges); |
||
43 | |||
44 | $controller = new PrivilegesController( |
||
45 | Response::getInstance(), |
||
46 | $dbi, |
||
47 | new Template(), |
||
48 | $db, |
||
49 | $table, |
||
50 | $serverPrivileges |
||
51 | ); |
||
52 | $actual = $controller->index([ |
||
53 | 'checkprivsdb' => $db, |
||
54 | 'checkprivstable' => $table, |
||
55 | ]); |
||
56 | |||
57 | $this->assertStringContainsString( |
||
58 | $db . '.' . $table, |
||
59 | $actual |
||
60 | ); |
||
61 | |||
62 | //validate 2: Url::getCommon |
||
63 | $item = Url::getCommon([ |
||
64 | 'db' => $db, |
||
65 | 'table' => $table, |
||
66 | ], ''); |
||
67 | $this->assertStringContainsString( |
||
68 | $item, |
||
69 | $actual |
||
70 | ); |
||
71 | |||
72 | //validate 3: items |
||
73 | $this->assertStringContainsString( |
||
74 | __('User'), |
||
75 | $actual |
||
76 | ); |
||
77 | $this->assertStringContainsString( |
||
78 | __('Host'), |
||
79 | $actual |
||
80 | ); |
||
81 | $this->assertStringContainsString( |
||
82 | __('Type'), |
||
83 | $actual |
||
84 | ); |
||
85 | $this->assertStringContainsString( |
||
86 | __('Privileges'), |
||
87 | $actual |
||
88 | ); |
||
89 | $this->assertStringContainsString( |
||
90 | __('Grant'), |
||
91 | $actual |
||
92 | ); |
||
93 | $this->assertStringContainsString( |
||
94 | __('Action'), |
||
95 | $actual |
||
96 | ); |
||
97 | $this->assertStringContainsString( |
||
98 | __('No user found'), |
||
99 | $actual |
||
100 | ); |
||
101 | |||
102 | //_pgettext('Create new user', 'New') |
||
103 | $this->assertStringContainsString( |
||
104 | _pgettext('Create new user', 'New'), |
||
105 | $actual |
||
106 | ); |
||
107 | $this->assertStringContainsString( |
||
108 | Url::getCommon([ |
||
109 | 'checkprivsdb' => $db, |
||
110 | 'checkprivstable' => $table, |
||
111 | ]), |
||
112 | $actual |
||
113 | ); |
||
116 |