function it_should_set_the_correct_output_class(FormatInterface $formatter) { $formatter->setLog([])->shouldBeCalled(); $formatter->setIssueTrackerUrlPattern('')->shouldBeCalled(); $formatter->decorate()->willReturn('foo'); $this->setLog([]); $this->setIssueTrackerUrlPattern(''); $this->decorate()->shouldReturn('foo'); }
/** * Writes the output to a file. * @return boolean */ public function write() { $result = false; $messages = $this->formatter->generate(); if (count($messages)) { $log = implode("\n", $messages) . "\n"; $result = $this->appendLog($log, $this->formatter->getFileName()); } return $result; }
function it_should_add_content_after_breakpoint(FormatInterface $formatter) { $logContent = ['Features:', '- foo', '- bar']; $resultContent = ['line one', $this->break, 'Features:', '- foo', '- bar', '', 'line two', '##' . $this->break, 'line three']; $formatter->generate()->willReturn($logContent); $formatter->getFileName()->willReturn($this->fileNameWithBreakpoint); $this->setBreak($this->break); $this->write(); $content = file_get_contents($this->fileNameWithBreakpoint); if (trim($content) !== join("\n", $resultContent)) { throw new \Exception('File content differs from expectations.'); } }
/** * Writes the output to a file. * * @return bool */ public function write() { // Crete the file if it does not exist $this->makeFile($this->formatter->getFileName()); // Contents of the original file $fileContent = file_get_contents($this->formatter->getFileName()); // Final log $log = join("\n", (array) $this->formatter->generate()) . "\n"; // Include the breakpoint if (false === empty($this->break) && 1 === preg_match("/^{$this->break}/m", $fileContent)) { $splitFileContent = preg_split("/^{$this->break}/m", $fileContent); file_put_contents($this->formatter->getFileName(), $splitFileContent[0] . $this->break . "\n" . $log . $splitFileContent[1]); return true; } file_put_contents($this->formatter->getFileName(), $log . $fileContent); return true; }
/** * Returns the decorated log. * @return FormatInterface */ public function decorate() { return $this->formatter->decorate(); }