/**
  * Test delayed notification
  */
 public function testSendDelay()
 {
     $step = $this->getDummyConfirmationStep();
     // Assert dependencies are injected
     $this->assertTrue($step->getMessagingService() instanceof ConfirmationMessagingService);
     $step->start();
     // Assert not error at startup
     $this->assertEquals('Started', $step->Status);
     $this->assertHasLog('Starting TestConfirmStep...');
     // Check only recipient and first admin has been notified
     $this->assertFalse($step->isTimedOut());
     $link = Director::absoluteURL('naut/project/testproject/environment/uat');
     $this->assertSentMessage("You requested approval for deployment of testproject/uat. Cancel? {$link}", '*****@*****.**');
     $this->assertSentMessage("Deployment for testproject/uat requested by Marley, Bob. Approve? {$link}", '*****@*****.**');
     $this->assertEquals(2, count(PipelineTest_RecordingMessageSender::get_messages()));
     // Advance 1 hour and ensure no other notifications have been sent
     SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+1 hour')));
     $this->clearLog();
     $step->start();
     $this->assertFalse($step->isTimedOut());
     $this->assertEmpty(PipelineTest_RecordingMessageSender::get_messages());
     // Advance 3 hours (2 more) and ensure the next notification is sent out
     SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+3 hour')));
     $this->clearLog();
     $step->start();
     $this->assertFalse($step->isTimedOut());
     $this->assertSentMessage("Deployment for testproject/uat requested by Marley, Bob. Approve? {$link}", '*****@*****.**');
     $this->assertSentMessage("Deployment for testproject/uat requested by Marley, Bob. Approve? {$link}", '*****@*****.**');
     $this->assertEquals(2, count(PipelineTest_RecordingMessageSender::get_messages()));
     // Go to 5 hours (another 2) and ensure the final notification is sent
     SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+5 hour')));
     $this->clearLog();
     $step->start();
     $this->assertFalse($step->isTimedOut());
     $this->assertSentMessage("Deployment for testproject/uat requested by Marley, Bob. Approve? {$link}", '*****@*****.**');
     $this->assertEquals(1, count(PipelineTest_RecordingMessageSender::get_messages()));
     // Go to 24 hours and ensure no notifications are sent
     SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+24 hour')));
     $this->clearLog();
     $step->start();
     $this->assertFalse($step->isTimedOut());
     $this->assertEmpty(PipelineTest_RecordingMessageSender::get_messages());
 }
 public static function clear()
 {
     self::$messages = array();
 }