| Conditions | 1 |
| Paths | 1 |
| Total Lines | 64 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 155 | public function testNonCompletedAck() |
||
| 156 | { |
||
| 157 | $statsTubeResponse1 = new ArrayResponse('test', ['current-jobs-delayed' => 1,]); |
||
| 158 | $statsTubeResponse2 = new ArrayResponse( |
||
| 159 | 'test', [ |
||
| 160 | 'current-jobs-delayed' => 0, |
||
| 161 | 'current-jobs-urgent' => 0, |
||
| 162 | 'current-jobs-ready' => 0 |
||
| 163 | ] |
||
| 164 | ); |
||
| 165 | $payload = json_decode($this->payload, true); |
||
| 166 | $payload['job'] = new Job(1, 'demo'); |
||
| 167 | $btJob2 = Mockery::mock('\Pheanstalk\Job') |
||
| 168 | ->shouldReceive('getData') |
||
| 169 | ->andReturn(json_encode($payload)) |
||
| 170 | ->getMock(); |
||
| 171 | $btClient = Mockery::mock('\Pheanstalk\Pheanstalk') |
||
| 172 | ->shouldReceive('useTube') |
||
| 173 | ->with(Mockery::mustBe('mail_queue')) |
||
| 174 | ->andReturnSelf() |
||
| 175 | ->shouldReceive('put') |
||
| 176 | ->withAnyArgs() |
||
| 177 | ->andReturn(3) |
||
| 178 | ->shouldReceive('statsTube') |
||
| 179 | ->twice() |
||
| 180 | ->andReturn($statsTubeResponse1, $statsTubeResponse2) |
||
| 181 | ->shouldReceive('watchOnly') |
||
| 182 | ->with(Mockery::mustBe('mail_queue')) |
||
| 183 | ->andReturnSelf() |
||
| 184 | ->shouldReceive('reserve') |
||
| 185 | ->with(0) |
||
| 186 | ->andReturn($btJob2) |
||
| 187 | ->shouldReceive('release') |
||
| 188 | ->andReturn(1) |
||
| 189 | ->shouldReceive('delete') |
||
| 190 | ->andReturn(1) |
||
| 191 | ->getMock(); |
||
| 192 | |||
| 193 | $btConnection = Mockery::mock('\Da\Mailer\Queue\Backend\Beanstalk\BeanstalkdQueueStoreConnection') |
||
| 194 | ->shouldReceive('connect') |
||
| 195 | ->andReturnSelf() |
||
| 196 | ->shouldReceive('getInstance') |
||
| 197 | ->andReturn($btClient) |
||
| 198 | ->getMock(); |
||
| 199 | |||
| 200 | $btQueueStore = new BeanstalkdQueueStoreAdapter($btConnection); |
||
| 201 | |||
| 202 | |||
| 203 | $this->assertSame($btQueueStore, $btQueueStore->init()); |
||
| 204 | $this->assertTrue($btQueueStore->enqueue($this->mailJob) > 1); |
||
| 205 | |||
| 206 | $this->assertTrue($btQueueStore->isEmpty() === false); |
||
| 207 | |||
| 208 | $mailJob = $btQueueStore->dequeue(); |
||
| 209 | |||
| 210 | $this->assertTrue($btQueueStore->isEmpty() === true); |
||
| 211 | |||
| 212 | $this->assertTrue(!empty($mailJob->getMessage())); |
||
| 213 | |||
| 214 | $dequeuedMailMessage = MailMessage::fromArray(json_decode($mailJob->getMessage(), true)); |
||
| 215 | |||
| 216 | $this->assertEquals(FixtureHelper::getMailMessage(), $dequeuedMailMessage); |
||
| 217 | $btQueueStore->ack($mailJob); |
||
| 218 | } |
||
| 219 | } |
||
| 220 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: