public function testSetRawContentAndGetRawContent()
 {
     $this->assertSame('', $this->rfc->getRawContent());
     $html = '<html><head><title>Testing :)</title></head><body></body></html>';
     $this->rfc->setRawContent($html);
     $this->assertSame($html, $this->rfc->getRawContent());
 }
 /**
  * @param Rfc $rfc
  * @param array $voteDiff
  */
 public function notify(Rfc $rfc, array $voteDiff)
 {
     foreach ($this->emailSubscriberRepository->findAll() as $subscriber) {
         $email = $this->twig->render('rfc.twig', ['rfcName' => $rfc->getName(), 'details' => $voteDiff['details'], 'changeLog' => $voteDiff['changeLog'], 'voteDiffs' => $voteDiff['votes'], 'rfcVotes' => $rfc->getVotes(), 'unsubscribeUrl' => sprintf('%s/unsubscribe/%s', $this->config->get('app.url'), $subscriber->getUnsubscribeToken())]);
         $message = $this->mailer->createMessage()->setSubject(sprintf('%s updated!', $rfc->getName()))->setFrom('*****@*****.**')->setTo($subscriber->getEmail())->setBody($email, 'text/html');
         $this->mailer->send($message);
     }
 }
 /**
  * @dataProvider rfcDiffDataProvider
  */
 public function testRfcDiffReturnsCorrectDiff($details, $changeLogs, $votes, $expectedDiff)
 {
     $rfc1 = new Rfc();
     $rfc2 = new Rfc();
     $rfc1->setDetails($details[0]);
     $rfc1->setChangeLog($changeLogs[0]);
     $rfc1->setVotes($votes[0]);
     $rfc2->setDetails($details[1]);
     $rfc2->setChangeLog($changeLogs[1]);
     $rfc2->setVotes($votes[1]);
     $this->assertSame($expectedDiff, $this->diffService->rfcDiff($rfc1, $rfc2));
 }
 /**
  * @param Rfc $rfc
  * @param array $voteDiff
  */
 public function notify(Rfc $rfc, array $voteDiff)
 {
     $attachments = [];
     foreach ($voteDiff['votes'] as $title => $voteDiffs) {
         $attachment = ['text' => $title, 'color' => 'good', 'fields' => []];
         if (!empty($voteDiffs['new'])) {
             $newVotes = array_map(function ($voter, $vote) {
                 return sprintf('%s: %s', $voter, $vote);
             }, array_keys($voteDiffs['new']), $voteDiffs['new']);
             $attachment['fields'][] = ['title' => 'New Votes', 'value' => implode(", ", $newVotes)];
         }
         if (!empty($voteDiffs['updated'])) {
             $updatedVotes = array_map(function ($voter, $vote) {
                 return sprintf('%s: %s', $voter, $vote);
             }, array_keys($voteDiffs['updated']), $voteDiffs['updated']);
             $attachment['fields'][] = ['title' => 'Updated Votes', 'value' => implode(", ", $updatedVotes)];
         }
         $counts = [];
         foreach ($rfc->getVotes()[$title]['counts'] as $header => $standing) {
             if ($header === 'Real name') {
                 continue;
             }
             $counts[$header] = $standing;
         }
         $counts = array_map(function ($vote, $count) {
             return sprintf('%s: %s', $vote, $count);
         }, array_keys($counts), $counts);
         $attachment['fields'][] = ['title' => 'Current Standings', 'value' => implode(", ", $counts)];
         $attachments[] = $attachment;
     }
     $message = ['text' => sprintf("*PHP RFC Updates for %s*", $rfc->getName()), 'username' => 'PHP RFC Digestor', 'icon_url' => 'http://php.net/images/logos/php.ico', 'attachments' => json_encode($attachments)];
     foreach ($this->slackSubscriberRepository->findAll() as $slackSubscriber) {
         $this->commander->setToken($slackSubscriber->getToken());
         $message['channel'] = '#' . $slackSubscriber->getChannel();
         $this->commander->execute('chat.postMessage', $message);
     }
 }
 /**
  * Returns array of changes in RFC 1 compared to RFC 2
  *
  * @param Rfc $rfc1
  * @param Rfc $rfc2
  * @return array
  */
 public function rfcDiff(Rfc $rfc1, Rfc $rfc2)
 {
     // Get any vote diffs between two RFCs
     $voteDiffs = $this->recursiveArrayDiff($rfc1->getVotes(), $rfc2->getVotes());
     return ['details' => $this->recursiveArrayDiff($rfc1->getDetails(), $rfc2->getDetails()), 'changeLog' => $this->recursiveArrayDiff($rfc1->getChangeLog(), $rfc2->getChangeLog()), 'votes' => $this->parseVotesDiff($voteDiffs, $rfc2->getVotes())];
 }
 public function testGetVotesAsTableRows()
 {
     $rfc = new Rfc();
     $rfc->setVotes(['Introduce the in operator?' => ['headers' => ['Real name', 'Yes', 'No'], 'votes' => ['aharvey (aharvey)' => ['Yes' => false, 'No' => true], 'ajf (ajf)' => ['Yes' => false, 'No' => true], 'ben (ben)' => ['Yes' => true, 'No' => false]], 'counts' => ['Real name' => 'Count:', 'Yes' => 0, 'No' => 2], 'closed' => false]]);
     $result = $this->rfcService->getVotesAsTableRows($rfc, 'Introduce the in operator?');
     $expected = [['aharvey (aharvey)', false, true], ['ajf (ajf)', false, true], ['ben (ben)', true, false]];
     $this->assertSame($expected, $result);
 }
 /**
  * Add Change Log to RFC
  *
  * @return self
  */
 public function loadChangeLog()
 {
     $this->rfc->setChangeLog($this->parseChangeLog());
     return $this;
 }
 /**
  * Get the votes in a flat format
  *
  * @param Rfc    $rfc
  * @param string $voteKey
  * @return array
  */
 public function getVotesAsTableRows(Rfc $rfc, $voteKey)
 {
     $votes = $rfc->getVotes();
     return $this->assocArrayToRows($votes[$voteKey]['votes']);
 }