Example #1
0
File: Diff.php Project: nochso/diff
 /**
  * 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;
 }
Example #2
0
 /**
  * @param array  $expected
  * @param string $from
  * @param string $to
  * @dataProvider arrayProvider
  * @covers       nochso\Diff\Format\Upstream::format
  * @covers       nochso\Diff\LCS\MemoryEfficientImplementation
  */
 public function testArrayRepresentationOfDiffCanBeDiffedUsingMemoryEfficientLcsImplementation(array $expected, $from, $to)
 {
     $this->assertEquals($expected, $this->differ->diffToArray($from, $to, new MemoryEfficientImplementation()));
 }