Пример #1
0
 /**
  * @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());
 }
 /**
  * @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));
 }