/** * @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 testGetRfcFromStorageCorrectlyBuildsRfc($details, $changeLog, $votes) { $rfc = new Rfc(); $this->rfcBuilderMock->expects($this->once())->method('loadFromStorage')->with('generator-delegation'); $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->getRfcFromStorage('generator-delegation', $details, $changeLog, $votes)); }