Conditions | 1 |
Paths | 1 |
Total Lines | 63 |
Code Lines | 48 |
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 |
||
31 | public function testEnqueueDequeueAndAcknowledge() |
||
32 | { |
||
33 | $statsTubeResponse2 = new ArrayResponse( |
||
34 | 'test', [ |
||
35 | 'current-jobs-delayed' => 0, |
||
36 | 'current-jobs-urgent' => 0, |
||
37 | 'current-jobs-ready' => 0 |
||
38 | ] |
||
39 | ); |
||
40 | $statsTubeResponse1= new ArrayResponse('test', ['current-jobs-delayed' => 1,]); |
||
41 | $payload = json_decode($this->payload, true); |
||
42 | $payload['job'] = new Job(1, 'demo'); |
||
43 | $btJob2 = Mockery::mock('\Pheanstalk\Job') |
||
44 | ->shouldReceive('getData') |
||
45 | ->andReturn(json_encode($payload)) |
||
46 | ->getMock(); |
||
47 | $btClient = Mockery::mock('\Pheanstalk\Pheanstalk') |
||
48 | ->shouldReceive('useTube') |
||
49 | ->with('mail_queue') |
||
50 | ->andReturnSelf() |
||
51 | ->shouldReceive('put') |
||
52 | ->andReturn(1) |
||
53 | ->shouldReceive('watchOnly') |
||
54 | ->andReturnSelf() |
||
55 | ->shouldReceive('statsTube') |
||
56 | ->twice() |
||
57 | ->andReturn($statsTubeResponse1, $statsTubeResponse2) |
||
58 | ->shouldReceive('reserve') |
||
59 | ->with(0) |
||
60 | ->andReturn($btJob2, null) |
||
61 | ->shouldReceive('delete') |
||
62 | ->andReturn(1) |
||
63 | ->getMock(); |
||
64 | |||
65 | $btStoreConnection = Mockery::mock('\Da\Mailer\Queue\Backend\Beanstalk\BeanstalkdQueueStoreConnection') |
||
66 | ->shouldReceive('connect') |
||
67 | ->andReturnSelf() |
||
68 | ->shouldReceive('getInstance') |
||
69 | ->andReturn($btClient) |
||
70 | ->getMock(); |
||
71 | |||
72 | $btQueueStore = new BeanstalkdQueueStoreAdapter($btStoreConnection); |
||
73 | |||
74 | $this->assertSame($btQueueStore, $btQueueStore->init()); |
||
75 | $this->assertTrue($btQueueStore->enqueue($this->mailJob) > 0); |
||
76 | |||
77 | $this->assertTrue($btQueueStore->isEmpty() === false); |
||
78 | |||
79 | $mailJob = $btQueueStore->dequeue(); |
||
80 | |||
81 | $this->assertTrue($btQueueStore->isEmpty() === true); |
||
82 | |||
83 | $this->assertTrue(!empty($mailJob->getMessage())); |
||
84 | |||
85 | $dequeuedMailMessage = MailMessage::fromArray(json_decode($mailJob->getMessage(), true)); |
||
86 | |||
87 | $this->assertEquals(FixtureHelper::getMailMessage(), $dequeuedMailMessage); |
||
88 | |||
89 | $mailJob->markAsCompleted(); |
||
90 | $btQueueStore->ack($mailJob); |
||
|
|||
91 | |||
92 | $this->assertTrue($btQueueStore->dequeue() === null); |
||
93 | } |
||
94 | |||
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: