Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 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.');
     }
 }