Пример #1
0
 public function it_creates_diff_from_buffer(PatchBuffer $buffer)
 {
     $originalFile = 'aaa/aaa/file.txt';
     $newFile = 'bbb/bbb/file.txt';
     $buffer->isModified()->willReturn(true);
     $buffer->getOriginalContents()->willReturn(array('line1', 'line3', 'line 4', 'line5'));
     $buffer->getModifiedContents()->willReturn(array('line1', 'line2', 'line3', 'line4', 'line5'));
     $this->buildPatch($originalFile, $newFile, $buffer)->shouldReturn("--- aaa/aaa/file.txt\n" . "+++ bbb/bbb/file.txt\n" . "@@ -1,4 +1,5 @@\n" . " line1\n" . "+line2\n" . " line3\n" . "-line 4\n" . "+line4\n" . " line5\n");
 }
Пример #2
0
 public function buildPatch($originalFile, $modfiedFileName, PatchBuffer $buffer)
 {
     if (!$buffer->isModified()) {
         return '';
     }
     $diff = new \Diff($buffer->getOriginalContents(), $buffer->getModifiedContents());
     $renderer = new \Diff_Renderer_Text_Unified();
     return "--- {$originalFile}\n" . "+++ {$modfiedFileName}\n" . $diff->render($renderer);
 }
 /**
  * Replace a range of lines with a set of new lines.
  *
  * @param int $startOriginalLine
  * @param int $endOriginalLine
  * @param array $newLines
  *
  * @return void
  */
 public function replaceLines($startOriginalLine, $endOriginalLine, array $newLines)
 {
     $this->buffer->replace($this->createLineRange($startOriginalLine, $endOriginalLine), $newLines);
 }