Conditions | 2 |
Paths | 2 |
Total Lines | 66 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 |
||
138 | public function testReadCampaignResponse() |
||
139 | { |
||
140 | // Login as admin user |
||
141 | $group = $this->objFromFixture(Group::class, 'admins'); |
||
142 | Permission::grant($group->ID, 'ADMIN'); |
||
143 | |||
144 | $admin = $this->objFromFixture(Member::class, 'admin_user'); |
||
145 | $this->logInAs($admin); |
||
146 | |||
147 | // Create new ChangeSet object |
||
148 | $changeset = ChangeSet::create(); |
||
149 | $changeset->ID = '123'; |
||
150 | $changeset->Name = 'changeset 123'; |
||
151 | $changeset->State = 'open'; |
||
152 | $changeset->IsInferred = false; |
||
153 | |||
154 | $changeset->write(); |
||
155 | |||
156 | // ChangeSet should be accessable for Admin |
||
157 | $this->assertTrue($changeset->canView()); |
||
158 | |||
159 | $expectedStatus = [ |
||
160 | '200' => [ |
||
161 | 'ID' => '123', |
||
162 | 'Name' => 'show' |
||
163 | ], |
||
164 | '400' => [ |
||
165 | 'ID' => '123', |
||
166 | 'Name' => '' |
||
167 | ], |
||
168 | '404' => [ |
||
169 | 'ID' => '12345', |
||
170 | 'Name' => 'show' |
||
171 | ] |
||
172 | ]; |
||
173 | |||
174 | // Create new CampaignAdmin object |
||
175 | $campaignAdmin = CampaignAdmin::create(); |
||
176 | |||
177 | $request = new HTTPRequest('GET', '/admin/campaigns/set/'); |
||
178 | $request->addHeader('Accept', 'application/json'); |
||
179 | |||
180 | foreach ($expectedStatus as $key => $val) { |
||
181 | $request->setRouteParams($val); |
||
182 | $response = $campaignAdmin->readCampaign($request); |
||
183 | $status = $response->getStatusCode(); |
||
184 | |||
185 | // Method should return correct status |
||
186 | $this->assertInstanceOf(HTTPResponse::class, $response); |
||
187 | $this->assertEquals($key, $status); |
||
188 | } |
||
189 | |||
190 | // Login as user without admin permissions |
||
191 | $user = $this->objFromFixture(Member::class, 'mock_user'); |
||
192 | $this->logInAs($user); |
||
193 | |||
194 | // ChangeSet should not be accessable for Mock User |
||
195 | $this->assertFalse($changeset->canView()); |
||
196 | |||
197 | $request->setRouteParams([ 'ID' => '123', 'Name' => 'show']); |
||
198 | $response = $campaignAdmin->readCampaign($request); |
||
199 | $status = $response->getStatusCode(); |
||
200 | |||
201 | // Method should return correct status if access forbidden |
||
202 | $this->assertInstanceOf(HTTPResponse::class, $response); |
||
203 | $this->assertEquals('403', $status); |
||
204 | } |
||
206 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.