Example #1
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $lists = $this->rfcService->getLists([RfcService::IN_VOTING]);
     $rfcs = array_pop($lists);
     $table = new Table($output);
     $voteStyle = new TableStyle();
     $voteStyle->setCellRowFormat('<comment>%s</comment>');
     $rfcStyle = new TableStyle();
     $rfcStyle->setCellRowFormat('<info>%s</info>');
     foreach ($rfcs as $i => $rfcDetails) {
         $rfcCode = $rfcDetails[1];
         // Build RFC
         $rfc = $this->rfcService->getRfc($rfcCode);
         $table->addRow([$rfcDetails[0]], $rfcStyle);
         $table->addRow(new TableSeparator());
         foreach ($rfc->getVotes() as $title => $vote) {
             $table->addRow([$title], $voteStyle);
             array_shift($vote['counts']);
             foreach ($vote['counts'] as $key => $total) {
                 $table->addRow([$key, $total]);
             }
         }
         if ($rfcDetails !== end($rfcs)) {
             $table->addRow(new TableSeparator());
         }
     }
     $table->render();
 }
 /**
  * @param string $rfcCode
  */
 public function notify($rfcCode)
 {
     $oldRfcPath = sprintf('%s/%s.html', $this->config->get('storagePath'), $rfcCode);
     try {
         // Build current RFC
         $currentRfc = $this->rfcService->getRfc($rfcCode);
     } catch (\InvalidArgumentException $e) {
         throw new \RuntimeException('Invalid RFC code, check rfc:list for valid codes');
     }
     if (!file_exists($oldRfcPath)) {
         file_put_contents($oldRfcPath, $currentRfc->getRawContent());
         $oldRfc = new \MikeyMike\RfcDigestor\Entity\Rfc();
     } else {
         try {
             // Get oldRfc
             $oldRfc = $this->rfcService->getRfcFromStorage($rfcCode);
         } catch (\InvalidArgumentException $e) {
             throw new \RuntimeException($e->getMessage());
         }
     }
     // Get diffs
     $diffs = $this->diffService->rfcDiff($currentRfc, $oldRfc);
     // Only send email if we have diffs
     if (count(array_filter($diffs)) === 0) {
         return;
     }
     foreach ($this->notifiers as $notifier) {
         $notifier->notify($currentRfc, $diffs);
     }
     file_put_contents($oldRfcPath, $currentRfc->getRawContent());
 }
 /**
  * @param $details
  * @param $changeLog
  * @param $votes
  *
  * @dataProvider getRfcTestsDataProvider
  */
 public function testGetRfcCorrectlyBuildsRfc($details, $changeLog, $votes)
 {
     $rfc = new Rfc();
     $this->rfcBuilderMock->expects($this->once())->method('loadFromWiki')->with('generator-delegation', 'https://wiki.php.net/rfc');
     $this->rfcBuilderMock->expects($this->once())->method('loadName');
     if ($details) {
         $this->rfcBuilderMock->expects($this->once())->method('loadDetails');
     }
     if ($changeLog) {
         $this->rfcBuilderMock->expects($this->once())->method('loadChangeLog');
     }
     if ($votes) {
         $this->rfcBuilderMock->expects($this->once())->method('loadVotes');
     }
     $this->rfcBuilderMock->expects($this->once())->method('getRfc')->will($this->returnValue($rfc));
     $this->assertSame($rfc, $this->rfcService->getRfc('generator-delegation', $details, $changeLog, $votes));
 }