Пример #1
0
 /**
  * @dataProvider cliEscaperProvider
  *
  * @param string $from
  * @param string $to
  * @param string $expected
  */
 public function testCliEscaper($from, $to, $expected)
 {
     $formatter = new POSIX();
     $formatter->setEscaper(new Escape\Cli());
     $output = $formatter->format(Diff::create($from, $to));
     $this->assertSame($expected, $output);
 }
Пример #2
0
 /**
  * @dataProvider contextProvider
  */
 public function testContext($maxContext, $from, $to, $expected)
 {
     $gh = new GithubMarkdown();
     $context = new ContextDiff();
     $context->setMaxContext($maxContext);
     $this->assertEquals($expected, $gh->format(Diff::create($from, $to, $context)));
 }
Пример #3
0
 public function testTypesOtherThanArrayAndStringCanBePassed()
 {
     $expected = "--- Original\n+++ New\n@@ @@\n-1\n+2\n";
     $diff = Diff::create(1, 2);
     $formatter = new Upstream();
     $this->assertEquals($expected, $formatter->format($diff));
 }
Пример #4
0
 /**
  * @dataProvider formatWithoutLineNumberProvider
  *
  * @param string $from
  * @param string $to
  * @param string $expected
  */
 public function testFormatWithoutLineNumber($from, $to, $expected)
 {
     $diff = Diff::create($from, $to);
     $formatter = new HTML();
     $formatter->getPrintf()->disableLineNumber();
     $output = $formatter->format($diff);
     $this->assertSame($expected, $output);
 }
Пример #5
0
 /**
  * @dataProvider contextProvider
  *
  * @param int    $maxContext
  * @param string $from
  * @param string $to
  * @param string $expected
  */
 public function testContext($maxContext, $from, $to, $expected)
 {
     $context = new ContextDiff();
     $context->setMaxContext($maxContext);
     $diff = Diff::create($from, $to, $context);
     $formatter = new Text();
     $this->assertSame($expected, $formatter->format($diff));
 }
Пример #6
0
 /**
  * @dataProvider lineEndingProvider
  */
 public function testLineEndingWarning($from, $to, $expectedFromEol, $expectedToEol)
 {
     $formatter = new Upstream();
     $diff = $formatter->format(Diff::create($from, $to));
     // No warning
     if ($expectedFromEol === null) {
         $this->assertNotRegExp('/#Warning: Line ending changed from .+ to .+$/m', $diff);
         return;
     }
     $fromEolName = (new EOL($expectedFromEol))->getName();
     $toEolName = (new EOL($expectedToEol))->getName();
     $pattern = sprintf('/^#Warning: Line ending changed from %s to %s$/m', preg_quote($fromEolName), preg_quote($toEolName));
     $this->assertRegExp($pattern, $diff);
 }
Пример #7
0
 public function setDiff($sourceBefore, $sourceAfter)
 {
     $this->diff = Diff::create($sourceBefore, $sourceAfter);
 }
Пример #8
0
 private function showDiff(Document $document, $existingFilepath)
 {
     $before = file_get_contents($existingFilepath);
     $after = $document->getContent();
     $diff = Diff\Diff::create($before, $after);
     $this->stdio->out('Differences to existing file:');
     if (!count($diff->getDiffLines())) {
         $this->stdio->outln(' <<yellow>>None<<reset>>');
         $this->stdio->outln();
         return;
     }
     $this->stdio->outln();
     $this->stdio->outln();
     if ($this->stdio->getStdout()->isPosix()) {
         $t = new Diff\Format\Template\POSIX();
     } else {
         $t = new Diff\Format\Template\Text();
     }
     $this->stdio->outln($t->format($diff));
     $this->stdio->outln();
 }