Conditions | 1 |
Paths | 1 |
Total Lines | 66 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
64 | public function testMain() |
||
65 | { |
||
66 | // Mock functions `curl_exec` and `curl_getinfo` in GithubApiComponent |
||
67 | // so that we don't actually hit the Github Api |
||
68 | $curlExecMock = $this->getFunctionMock('\App\Controller\Component', 'curl_exec'); |
||
69 | $curlGetInfoMock = $this->getFunctionMock('\App\Controller\Component', 'curl_getinfo'); |
||
70 | |||
71 | $issueResponse = file_get_contents(TESTS . 'Fixture' . DS . 'issue_response.json'); |
||
72 | $decodedResponse = json_decode($issueResponse, true); |
||
73 | $decodedResponse['state'] = 'closed'; |
||
74 | $issueResponseWithClosed = json_encode($decodedResponse); |
||
75 | |||
76 | $curlExecMock->expects($this->exactly(3))->willReturnOnConsecutiveCalls( |
||
77 | $issueResponse, |
||
78 | $issueResponse, |
||
79 | $issueResponseWithClosed |
||
80 | ); |
||
81 | $curlGetInfoMock->expects($this->exactly(3))->willReturnOnConsecutiveCalls( |
||
82 | 200, |
||
83 | 200, |
||
84 | 200 |
||
85 | ); |
||
86 | |||
87 | // Fetch all linked reports |
||
88 | $reports = $this->Reports->find( |
||
89 | 'all', |
||
90 | [ |
||
91 | 'conditions' => [ |
||
92 | 'sourceforge_bug_id IS NOT NULL', |
||
93 | 'NOT' => [ |
||
94 | 'status' => 'resolved', |
||
95 | ] |
||
96 | ], |
||
97 | ] |
||
98 | ); |
||
99 | $this->assertEquals(3, $reports->count()); |
||
100 | |||
101 | $this->SyncGithubIssueStates->main(); |
||
102 | |||
103 | // Fetch all linked reports |
||
104 | $reports = $this->Reports->find( |
||
105 | 'all', |
||
106 | [ |
||
107 | 'conditions' => [ |
||
108 | 'sourceforge_bug_id IS NOT NULL', |
||
109 | 'NOT' => [ |
||
110 | 'status' => 'resolved', |
||
111 | ] |
||
112 | ], |
||
113 | ] |
||
114 | ); |
||
115 | $this->assertEquals(2, $reports->count()); |
||
116 | |||
117 | // Fetch all closed reports |
||
118 | $reports = $this->Reports->find( |
||
119 | 'all', |
||
120 | [ |
||
121 | 'conditions' => [ |
||
122 | 'sourceforge_bug_id IS NOT NULL', |
||
123 | 'status' => 'resolved' |
||
124 | ], |
||
125 | ] |
||
126 | ); |
||
127 | $this->assertEquals(1, $reports->count()); |
||
128 | $report5 = $this->Reports->get(4); |
||
129 | $this->assertEquals('resolved', $report5->status); |
||
130 | } |
||
132 |