/** * @param string[] $userIds * @param string|null $adminMessage * @param null $adminUserId * * @return Result */ public function dispatchTo($userIds, $adminMessage = null, $adminUserId = null) { $rudolph = new Rudolph(); $associatedUsers = $rudolph->associateUsers($userIds); $hash = md5(serialize($associatedUsers)); $remainingAssociations = $associatedUsers; $error = null; try { foreach ($associatedUsers as $giver => $receiver) { $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($adminMessage)) { $text .= "\n\nHere is a message from the Secret Santa admin:\n\n```" . strip_tags($adminMessage) . '```'; } if ($adminUserId) { $text .= sprintf("\n\nMessage sent via <@%s>.", $adminUserId); } $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); unset($remainingAssociations[$giver]); } } catch (\Exception $e) { $error = $e->getMessage(); } return new Result($hash, $remainingAssociations, $error); }
/** * @param $users * * @dataProvider userListDataProvider */ public function test_it_create_associations(array $users) { $associations = $this->SUT->associateUsers($users); $this->assertCount(count($users), $associations); foreach ($users as $user) { $this->assertTrue(array_key_exists($user, $associations)); $this->assertTrue(in_array($user, $associations, true)); $this->assertNotEquals($user, $associations[$user]); } }