3 Diff implementation for PHP, factored out of PHPUnit into a stand-alone component.
7 You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):
9 composer require sebastian/diff
11 If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:
13 composer require --dev sebastian/diff
17 The `Differ` class can be used to generate a textual representation of the difference between two strings:
20 use SebastianBergmann\Diff\Differ;
23 print $differ->diff('foo', 'bar');
26 The code above yields the output below:
34 The `Parser` class can be used to parse a unified diff into an object graph:
37 use SebastianBergmann\Diff\Parser;
38 use SebastianBergmann\Git;
40 $git = new Git('/usr/local/src/money');
42 $diff = $git->getDiff(
43 '948a1a07768d8edd10dcefa8315c1cbeffb31833',
44 'c07a373d2399f3e686234c4f7f088d635eb9641b'
49 print_r($parser->parse($diff));
52 The code above yields the output below:
56 [0] => SebastianBergmann\Diff\Diff Object
58 [from:SebastianBergmann\Diff\Diff:private] => a/tests/MoneyTest.php
59 [to:SebastianBergmann\Diff\Diff:private] => b/tests/MoneyTest.php
60 [chunks:SebastianBergmann\Diff\Diff:private] => Array
62 [0] => SebastianBergmann\Diff\Chunk Object
64 [start:SebastianBergmann\Diff\Chunk:private] => 87
65 [startRange:SebastianBergmann\Diff\Chunk:private] => 7
66 [end:SebastianBergmann\Diff\Chunk:private] => 87
67 [endRange:SebastianBergmann\Diff\Chunk:private] => 7
68 [lines:SebastianBergmann\Diff\Chunk:private] => Array
70 [0] => SebastianBergmann\Diff\Line Object
72 [type:SebastianBergmann\Diff\Line:private] => 3
73 [content:SebastianBergmann\Diff\Line:private] => * @covers SebastianBergmann\Money\Money::add
76 [1] => SebastianBergmann\Diff\Line Object
78 [type:SebastianBergmann\Diff\Line:private] => 3
79 [content:SebastianBergmann\Diff\Line:private] => * @covers SebastianBergmann\Money\Money::newMoney
82 [2] => SebastianBergmann\Diff\Line Object
84 [type:SebastianBergmann\Diff\Line:private] => 3
85 [content:SebastianBergmann\Diff\Line:private] => */
88 [3] => SebastianBergmann\Diff\Line Object
90 [type:SebastianBergmann\Diff\Line:private] => 2
91 [content:SebastianBergmann\Diff\Line:private] => public function testAnotherMoneyWithSameCurrencyObjectCanBeAdded()
94 [4] => SebastianBergmann\Diff\Line Object
96 [type:SebastianBergmann\Diff\Line:private] => 1
97 [content:SebastianBergmann\Diff\Line:private] => public function testAnotherMoneyObjectWithSameCurrencyCanBeAdded()
100 [5] => SebastianBergmann\Diff\Line Object
102 [type:SebastianBergmann\Diff\Line:private] => 3
103 [content:SebastianBergmann\Diff\Line:private] => {
106 [6] => SebastianBergmann\Diff\Line Object
108 [type:SebastianBergmann\Diff\Line:private] => 3
109 [content:SebastianBergmann\Diff\Line:private] => $a = new Money(1, new Currency('EUR'));
112 [7] => SebastianBergmann\Diff\Line Object
114 [type:SebastianBergmann\Diff\Line:private] => 3
115 [content:SebastianBergmann\Diff\Line:private] => $b = new Money(2, new Currency('EUR'));