| Conditions | 1 |
| Paths | 1 |
| Total Lines | 65 |
| Code Lines | 37 |
| 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 |
||
| 40 | public function testExecute(): void |
||
| 41 | { |
||
| 42 | $Reports = $this->getTableLocator()->get('Reports'); |
||
| 43 | // Mock functions `curl_exec` and `curl_getinfo` in GithubApiComponent |
||
| 44 | // so that we don't actually hit the Github Api |
||
| 45 | $curlExecMock = $this->getFunctionMock('\App\Controller\Component', 'curl_exec'); |
||
| 46 | $curlGetInfoMock = $this->getFunctionMock('\App\Controller\Component', 'curl_getinfo'); |
||
| 47 | |||
| 48 | $issueResponse = file_get_contents(TESTS . 'Fixture' . DS . 'issue_response.json'); |
||
| 49 | $decodedResponse = json_decode($issueResponse, true); |
||
| 50 | $decodedResponse['state'] = 'closed'; |
||
| 51 | $issueResponseWithClosed = json_encode($decodedResponse); |
||
| 52 | |||
| 53 | $curlExecMock->expects($this->exactly(3))->willReturnOnConsecutiveCalls( |
||
| 54 | $issueResponse, |
||
| 55 | $issueResponse, |
||
| 56 | $issueResponseWithClosed |
||
| 57 | ); |
||
| 58 | $curlGetInfoMock->expects($this->exactly(3))->willReturnOnConsecutiveCalls( |
||
| 59 | 200, |
||
| 60 | 200, |
||
| 61 | 200 |
||
| 62 | ); |
||
| 63 | |||
| 64 | // Fetch all linked reports |
||
| 65 | $reports = $Reports->find( |
||
| 66 | 'all', |
||
| 67 | [ |
||
| 68 | 'conditions' => [ |
||
| 69 | 'sourceforge_bug_id IS NOT NULL', |
||
| 70 | 'NOT' => ['status' => 'resolved'], |
||
| 71 | ], |
||
| 72 | ] |
||
| 73 | ); |
||
| 74 | $this->assertEquals(3, $reports->count()); |
||
| 75 | |||
| 76 | // Run the shell command |
||
| 77 | $this->exec('sync_github_issue_states'); |
||
| 78 | $this->assertExitCode(Command::CODE_SUCCESS); |
||
| 79 | |||
| 80 | // Fetch all linked reports |
||
| 81 | $reports = $Reports->find( |
||
| 82 | 'all', |
||
| 83 | [ |
||
| 84 | 'conditions' => [ |
||
| 85 | 'sourceforge_bug_id IS NOT NULL', |
||
| 86 | 'NOT' => ['status' => 'resolved'], |
||
| 87 | ], |
||
| 88 | ] |
||
| 89 | ); |
||
| 90 | $this->assertEquals(2, $reports->count()); |
||
| 91 | |||
| 92 | // Fetch all closed reports |
||
| 93 | $reports = $Reports->find( |
||
| 94 | 'all', |
||
| 95 | [ |
||
| 96 | 'conditions' => [ |
||
| 97 | 'sourceforge_bug_id IS NOT NULL', |
||
| 98 | 'status' => 'resolved', |
||
| 99 | ], |
||
| 100 | ] |
||
| 101 | ); |
||
| 102 | $this->assertEquals(1, $reports->count()); |
||
| 103 | $report5 = $Reports->get(4); |
||
| 104 | $this->assertEquals('resolved', $report5->status); |
||
| 105 | } |
||
| 107 |