Conditions | 1 |
Paths | 1 |
Total Lines | 51 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
25 | public function testDeleteAccount() { |
||
26 | $this->specify('deleteAccount() should return false if the form does not validate', function() { |
||
27 | $user = $this->getUser(); |
||
28 | $user |
||
29 | ->expects($this->never()) |
||
30 | ->method('delete'); |
||
31 | |||
32 | $form = new DeleteAccountForm($user); |
||
33 | $form->password = '1'; |
||
34 | $this->assertFalse($form->deleteAccount(), 'deleteAccount should not be successful'); |
||
35 | }); |
||
36 | |||
37 | $this->specify('deleteAccount() should return false if the user\'s password is incorrect', function() { |
||
38 | $user = $this->getUser(); |
||
39 | $user |
||
40 | ->expects($this->never()) |
||
41 | ->method('delete'); |
||
42 | |||
43 | $form = new DeleteAccountForm($user); |
||
44 | $form->password = '1'; |
||
45 | $this->assertFalse($form->deleteAccount(), 'deleteAccount should not be successful'); |
||
46 | }); |
||
47 | |||
48 | $this->specify('deleteAccount() should return true, send a notification email, and delete the user when the form validates and the user\'s password is correct', function() { |
||
49 | $password = 'password'; |
||
50 | $user = $this->getUser(); |
||
51 | $user->email = '[email protected]'; |
||
52 | $user->partner_email1 = '[email protected]'; |
||
53 | $user->setPassword($password); |
||
54 | $user |
||
55 | ->method('isPartnerEnabled') |
||
56 | ->willReturn(true); |
||
57 | |||
58 | $user |
||
59 | ->expects($this->once()) |
||
60 | ->method('delete'); |
||
61 | |||
62 | $form = new DeleteAccountForm($user); |
||
63 | $form->password = $password; |
||
64 | |||
65 | $this->assertTrue($form->deleteAccount(), 'should be successful'); |
||
66 | |||
67 | $this->tester->seeEmailIsSent(); |
||
68 | $emailMessage = $this->tester->grabLastSentEmail(); |
||
69 | expect('valid email is sent', $emailMessage)->isInstanceOf('yii\mail\MessageInterface'); |
||
70 | // an email was sent to both the user |
||
71 | // and to partner1. We grab the most recently sent one to examine though, thus partner1 |
||
72 | expect($emailMessage->getTo())->hasKey('[email protected]'); |
||
73 | expect($emailMessage->getFrom())->hasKey(Yii::$app->params['supportEmail']); |
||
74 | expect($emailMessage->getSubject())->equals('[email protected] has deleted their The Faster Scale App account'); |
||
75 | expect($emailMessage->toString())->contains($user->email); |
||
76 | }); |
||
95 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.