/**
  * Send messages for remaining associations.
  *
  * This method is limited to 20 seconds to be able to display nice error message instead of being timed out by Heroku.
  *
  * @param SecretSanta $secretSanta
  *
  * @throws \RuntimeException
  */
 public function dispatchRemainingMessages(SecretSanta $secretSanta)
 {
     $startTime = time();
     try {
         foreach ($secretSanta->getRemainingAssociations() as $giver => $receiver) {
             if (time() - $startTime > 19) {
                 throw new \RuntimeException('It takes too much time to contact Slack! Please press the Retry button.');
             }
             $text = sprintf("Hi! You have been chosen to be part of a Secret Santa!\n\nSomeone has been chosen to get you a gift; and *you* have been chosen to gift <@%s>!", $receiver);
             if (!empty($secretSanta->getAdminMessage())) {
                 $text .= "\n\nHere is a message from the Secret Santa admin:\n\n```" . $secretSanta->getAdminMessage() . '```';
             }
             if ($secretSanta->getAdminUserId()) {
                 $text .= sprintf("\n\nMessage sent via <@%s>.", $secretSanta->getAdminUserId());
             }
             $message = new ChatPostMessagePayload();
             $message->setChannel(sprintf('@%s', $giver));
             $message->setText($text);
             $message->setUsername('Secret Santa Bot');
             $message->setIconUrl('https://slack-secret-santa.herokuapp.com/images/logo.png');
             $this->sendPayload($message);
             $secretSanta->markAssociationAsProceeded($giver);
         }
     } catch (\Exception $e) {
         $secretSanta->addError($e->getMessage());
     }
 }
 public function test_summary_works_with_valid_hash()
 {
     $secretSanta = new SecretSanta('yolo', ['toto1' => 'toto2', 'toto2' => 'toto3', 'toto3' => 'toto1'], null);
     $secretSanta->markAssociationAsProceeded('toto1');
     $secretSanta->markAssociationAsProceeded('toto2');
     $secretSanta->markAssociationAsProceeded('toto3');
     $client = static::createClient();
     $this->prepareSession($client, 'secret-santa-yolo', $secretSanta);
     $crawler = $client->request('GET', '/summary/yolo');
     $response = $client->getResponse();
     $this->assertSame(200, $response->getStatusCode());
     $this->assertContains('Spoiler alert', $response->getContent());
     $this->assertContains('@toto1 must offer a gift to @toto2', $response->getContent());
 }