| Conditions | 2 |
| Paths | 2 |
| Total Lines | 57 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 153 | public function testChangeMembers() |
||
| 154 | { |
||
| 155 | // Set up |
||
| 156 | // Make a new user so it doesn't matter if something goes wrong |
||
| 157 | $account = array( |
||
| 158 | 'account_lid' => 'test_user', |
||
| 159 | 'account_firstname' => 'TestUser', |
||
| 160 | 'account_lastname' => 'Test', |
||
| 161 | 'account_primary_group' => 'Default', |
||
| 162 | 'account_groups' => array('Default') |
||
| 163 | ); |
||
| 164 | |||
| 165 | if(($account_id = $GLOBALS['egw']->accounts->name2id($account['account_lid']))) |
||
| 166 | { |
||
| 167 | // Delete if there in case something went wrong |
||
| 168 | $GLOBALS['egw']->accounts->delete($account_id); |
||
| 169 | } |
||
| 170 | |||
| 171 | $command = new admin_cmd_edit_user(false, $account); |
||
| 172 | $command->comment = 'Needed for unit test ' . $this->getName(); |
||
| 173 | $command->run(); |
||
| 174 | $this->account_id = $command->account; |
||
| 175 | |||
| 176 | $command = new admin_cmd_edit_group(false, $this->group); |
||
| 177 | $command->comment = 'Needed for unit test ' . $this->getName(); |
||
| 178 | $command->run(); |
||
| 179 | $this->group_id = $command->account; |
||
| 180 | |||
| 181 | // Count accounts |
||
| 182 | $pre_search = $GLOBALS['egw']->accounts->search(array('type' => 'both')); |
||
| 183 | $log_count = $this->get_log_count(); |
||
| 184 | |||
| 185 | // Execute |
||
| 186 | $account = $this->account; |
||
| 187 | $account['account_members'][] = $this->account_id; |
||
| 188 | $command = new admin_cmd_edit_group($this->group_id, $account); |
||
| 189 | $command->comment = 'Needed for unit test ' . $this->getName(); |
||
| 190 | $command->run(); |
||
| 191 | |||
| 192 | // Check |
||
| 193 | $post_search = $GLOBALS['egw']->accounts->search(array('type' => 'both')); |
||
| 194 | $this->assertEquals(count($pre_search), count($post_search), 'Should have same number of accounts as before'); |
||
| 195 | $this->assertGreaterThan($log_count, $this->get_log_count(), "Command ($command) did not log"); |
||
| 196 | |||
| 197 | // Now remove |
||
| 198 | $pre_search = $post_search; |
||
| 199 | $log_count = $this->get_log_count(); |
||
| 200 | |||
| 201 | $account = $this->account; |
||
| 202 | $command = new admin_cmd_edit_group($this->group_id, $account); |
||
| 203 | $command->comment = 'Needed for unit test ' . $this->getName(); |
||
| 204 | $command->run(); |
||
| 205 | |||
| 206 | // Check |
||
| 207 | $post_search = $GLOBALS['egw']->accounts->search(array('type' => 'both')); |
||
| 208 | $this->assertEquals(count($pre_search), count($post_search), 'Should have same number of accounts as before'); |
||
| 209 | $this->assertGreaterThan($log_count, $this->get_log_count(), "Command ($command) did not log"); |
||
| 210 | } |
||
| 211 | } |