Conditions | 1 |
Paths | 1 |
Total Lines | 64 |
Code Lines | 44 |
Lines | 0 |
Ratio | 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 |
||
86 | public function testSendDelay() { |
||
87 | $step = $this->getDummyConfirmationStep(); |
||
88 | |||
89 | // Assert dependencies are injected |
||
90 | $this->assertTrue($step->getMessagingService() instanceof ConfirmationMessagingService); |
||
1 ignored issue
–
show
|
|||
91 | $step->start(); |
||
92 | |||
93 | // Assert not error at startup |
||
94 | $this->assertEquals('Started', $step->Status); |
||
1 ignored issue
–
show
|
|||
95 | $this->assertHasLog('Starting TestConfirmStep...'); |
||
96 | |||
97 | // Check only recipient and first admin has been notified |
||
98 | $this->assertFalse($step->isTimedOut()); |
||
99 | $link = Director::absoluteURL('naut/project/testproject/environment/uat'); |
||
100 | $this->assertSentMessage( |
||
101 | "You requested approval for deployment of testproject/uat. Cancel? {$link}", |
||
102 | '[email protected]' |
||
103 | ); |
||
104 | $this->assertSentMessage( |
||
105 | "Deployment for testproject/uat requested by Marley, Bob. Approve? {$link}", |
||
106 | '[email protected]' |
||
107 | ); |
||
108 | $this->assertEquals(2, count(PipelineTest_RecordingMessageSender::get_messages())); |
||
1 ignored issue
–
show
|
|||
109 | |||
110 | // Advance 1 hour and ensure no other notifications have been sent |
||
111 | SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+1 hour'))); |
||
112 | $this->clearLog(); |
||
113 | $step->start(); |
||
114 | $this->assertFalse($step->isTimedOut()); |
||
115 | $this->assertEmpty(PipelineTest_RecordingMessageSender::get_messages()); |
||
116 | |||
117 | // Advance 3 hours (2 more) and ensure the next notification is sent out |
||
118 | SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+3 hour'))); |
||
119 | $this->clearLog(); |
||
120 | $step->start(); |
||
121 | $this->assertFalse($step->isTimedOut()); |
||
122 | $this->assertSentMessage( |
||
123 | "Deployment for testproject/uat requested by Marley, Bob. Approve? {$link}", |
||
124 | '[email protected]' |
||
125 | ); |
||
126 | $this->assertSentMessage( |
||
127 | "Deployment for testproject/uat requested by Marley, Bob. Approve? {$link}", |
||
128 | '[email protected]' |
||
129 | ); |
||
130 | $this->assertEquals(2, count(PipelineTest_RecordingMessageSender::get_messages())); |
||
1 ignored issue
–
show
|
|||
131 | |||
132 | // Go to 5 hours (another 2) and ensure the final notification is sent |
||
133 | SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+5 hour'))); |
||
134 | $this->clearLog(); |
||
135 | $step->start(); |
||
136 | $this->assertFalse($step->isTimedOut()); |
||
137 | $this->assertSentMessage( |
||
138 | "Deployment for testproject/uat requested by Marley, Bob. Approve? {$link}", |
||
139 | '[email protected]' |
||
140 | ); |
||
141 | $this->assertEquals(1, count(PipelineTest_RecordingMessageSender::get_messages())); |
||
1 ignored issue
–
show
|
|||
142 | |||
143 | // Go to 24 hours and ensure no notifications are sent |
||
144 | SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+24 hour'))); |
||
145 | $this->clearLog(); |
||
146 | $step->start(); |
||
147 | $this->assertFalse($step->isTimedOut()); |
||
148 | $this->assertEmpty(PipelineTest_RecordingMessageSender::get_messages()); |
||
149 | } |
||
150 | |||
188 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.