Пример #1
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)));
 }
Пример #2
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));
 }
Пример #3
0
 /**
  * Create a new Diff from two strings.
  *
  * @param string                                         $from    From/before string.
  * @param string                                         $to      To/after string.
  * @param \nochso\Diff\ContextDiff|null                  $context Optional ContextDiff to control the surrounding
  *                                                                context lines. If null, a default ContextDiff
  *                                                                is used.
  * @param \nochso\Diff\LCS\LongestCommonSubsequence|null $lcs     Optional LCS implementation to use. If null, an
  *                                                                appropiate implementation will be chosen automatically.
  *
  * @return \nochso\Diff\Diff
  */
 public static function create($from, $to, ContextDiff $context = null, LongestCommonSubsequence $lcs = null)
 {
     $diff = new self();
     $differ = new Differ();
     $fullDiffLines = $differ->diffToArray($from, $to, $lcs);
     if ($context === null) {
         $context = new ContextDiff();
     }
     $diff->addLineEndingWarning($from, $to);
     $contextDiffLines = $context->create($fullDiffLines);
     foreach ($contextDiffLines as $contextDiffLine) {
         $diff->diffLines[] = new DiffLine($contextDiffLine);
     }
     return $diff;
 }