3030 */
3131final class DifferTest extends TestCase
3232{
33+ const WARNING = 3 ;
3334 const REMOVED = 2 ;
3435 const ADDED = 1 ;
3536 const OLD = 0 ;
@@ -61,7 +62,7 @@ public function testArrayRepresentationOfDiffCanBeRenderedUsingTimeEfficientLcsI
6162 * @param string $to
6263 * @dataProvider textProvider
6364 */
64- public function testTextRepresentationOfDiffCanBeRenderedUsingTimeEfficientLcsImplementation ($ expected , $ from , $ to )
65+ public function testTextRepresentationOfDiffCanBeRenderedUsingTimeEfficientLcsImplementation (string $ expected , string $ from , string $ to )
6566 {
6667 $ this ->assertSame ($ expected , $ this ->differ ->diff ($ from , $ to , new TimeEfficientLongestCommonSubsequenceCalculator ));
6768 }
@@ -88,16 +89,53 @@ public function testTextRepresentationOfDiffCanBeRenderedUsingMemoryEfficientLcs
8889 $ this ->assertSame ($ expected , $ this ->differ ->diff ($ from , $ to , new MemoryEfficientLongestCommonSubsequenceCalculator ));
8990 }
9091
91- public function testCustomHeaderCanBeUsed ()
92+ /**
93+ * @param string $expected
94+ * @param string $from
95+ * @param string $to
96+ * @param string $header
97+ * @dataProvider headerProvider
98+ */
99+ public function testCustomHeaderCanBeUsed (string $ expected , string $ from , string $ to , string $ header )
92100 {
93- $ differ = new Differ (new UnifiedDiffOutputBuilder (' CUSTOM HEADER ' ));
101+ $ differ = new Differ (new UnifiedDiffOutputBuilder ($ header ));
94102
95103 $ this ->assertSame (
96- " CUSTOM HEADER@@ @@ \n -a \n +b \n" ,
97- $ differ ->diff (' a ' , ' b ' )
104+ $ expected ,
105+ $ differ ->diff ($ from , $ to )
98106 );
99107 }
100108
109+ public function headerProvider ()
110+ {
111+ return [
112+ [
113+ "CUSTOM HEADER \n@@ @@ \n-a \n+b \n" ,
114+ 'a ' ,
115+ 'b ' ,
116+ 'CUSTOM HEADER '
117+ ],
118+ [
119+ "CUSTOM HEADER \n@@ @@ \n-a \n+b \n" ,
120+ 'a ' ,
121+ 'b ' ,
122+ "CUSTOM HEADER \n"
123+ ],
124+ [
125+ "CUSTOM HEADER \n\n@@ @@ \n-a \n+b \n" ,
126+ 'a ' ,
127+ 'b ' ,
128+ "CUSTOM HEADER \n\n"
129+ ],
130+ [
131+ "@@ @@ \n-a \n+b \n" ,
132+ 'a ' ,
133+ 'b ' ,
134+ ''
135+ ],
136+ ];
137+ }
138+
101139 public function testTypesOtherThanArrayAndStringCanBePassed ()
102140 {
103141 $ this ->assertSame (
@@ -245,7 +283,7 @@ public function arrayProvider(): array
245283 [
246284 [
247285 '#Warning: Strings contain different line endings! ' ,
248- self ::OLD ,
286+ self ::WARNING ,
249287 ],
250288 [
251289 '<?php ' ,
@@ -363,25 +401,49 @@ public function diffProvider(): array
363401 * @param string $expected
364402 * @param string $from
365403 * @param string $to
404+ * @param string $header
366405 * @dataProvider textForNoNonDiffLinesProvider
367406 */
368- public function testDiffDoNotShowNonDiffLines (string $ expected , string $ from , string $ to )
407+ public function testDiffDoNotShowNonDiffLines (string $ expected , string $ from , string $ to, string $ header = '' )
369408 {
370- $ differ = new Differ (new DiffOnlyOutputBuilder ('' ));
409+ $ differ = new Differ (new DiffOnlyOutputBuilder ($ header ));
410+
371411 $ this ->assertSame ($ expected , $ differ ->diff ($ from , $ to ));
372412 }
373413
374414 public function textForNoNonDiffLinesProvider (): array
375415 {
376416 return [
377417 [
378- '' , 'a ' , 'a '
418+ ' #Warning: Strings contain different line endings!
419+ -A
420+ +B
421+ ' ,
422+ "A \r\n" ,
423+ "B \n" ,
424+ ],
425+ [
426+ '' ,
427+ 'a ' ,
428+ 'a '
379429 ],
380430 [
381431 "-A \n+C \n" ,
382432 "A \n\n\nB " ,
383433 "C \n\n\nB " ,
384434 ],
435+ [
436+ "header \n" ,
437+ 'a ' ,
438+ 'a ' ,
439+ 'header '
440+ ],
441+ [
442+ "header \n" ,
443+ 'a ' ,
444+ 'a ' ,
445+ "header \n"
446+ ],
385447 ];
386448 }
387449
0 commit comments