Skip to content

Commit 29dc0d5

Browse files
authored
PHP8 (#20)
1 parent c7fe15b commit 29dc0d5

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
}
1616
],
1717
"require": {
18-
"php": "^5.6 || ^7.0"
18+
"php": "^5.6 || ^7.0 || ^8.0"
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "^5.7.23 || ^6.4.3",
21+
"phpunit/phpunit": "^5.7.23 || ^6.4.3 || ^7.0",
2222
"symfony/process": "^3.3"
2323
},
2424
"config": {

src/Output/UnifiedDiffOutputBuilder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ public function getDiff(array $diff)
6767

6868
\fclose($buffer);
6969

70-
// If the last char is not a linebreak: add it.
70+
// If the diff is non-empty and a linebreak: add it.
7171
// This might happen when both the `from` and `to` do not have a trailing linebreak
7272
$last = \substr($diff, -1);
7373

74-
return "\n" !== $last && "\r" !== $last
74+
return 0 !== \strlen($diff) && "\n" !== $last && "\r" !== $last
7575
? $diff . "\n"
7676
: $diff
7777
;

tests/Output/StrictUnifiedDiffOutputBuilderTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,35 @@ public function testEmptyDiff()
305305
);
306306
}
307307

308+
/**
309+
* @param string $from
310+
* @param string $to
311+
*
312+
* @dataProvider provideSameEmptyDiff
313+
*/
314+
public function testSameEmptyDiff($from, $to)
315+
{
316+
$builder = new StrictUnifiedDiffOutputBuilder([
317+
'fromFile' => 'input.txt',
318+
'toFile' => 'output.txt',
319+
]);
320+
321+
$differ = new Differ($builder);
322+
323+
$this->assertSame(
324+
'',
325+
$differ->diff($from, $to)
326+
);
327+
}
328+
329+
public function provideSameEmptyDiff()
330+
{
331+
return [
332+
['', ''],
333+
['a', 'a'],
334+
];
335+
}
336+
308337
/**
309338
* @param array $options
310339
* @param string $message

tests/Output/UnifiedDiffOutputBuilderTest.php

+24
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,28 @@ public function provideDiffWithLineNumbers()
8787
{
8888
return UnifiedDiffOutputBuilderDataProvider::provideDiffWithLineNumbers();
8989
}
90+
91+
/**
92+
* @param string $from
93+
* @param string $to
94+
*
95+
* @dataProvider provideStringsThatAreTheSame
96+
*/
97+
public function testEmptyDiffProducesEmptyOutput($from, $to)
98+
{
99+
$differ = new Differ(new UnifiedDiffOutputBuilder('', false));
100+
$output = $differ->diff($from, $to);
101+
$this->assertEmpty($output);
102+
}
103+
104+
public function provideStringsThatAreTheSame()
105+
{
106+
return [
107+
['', ''],
108+
['a', 'a'],
109+
['these strings are the same', 'these strings are the same'],
110+
["\n", "\n"],
111+
["multi-line strings\nare the same", "multi-line strings\nare the same"]
112+
];
113+
}
90114
}

0 commit comments

Comments
 (0)