Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
PHP8 (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpacePossum committed Oct 14, 2020
1 parent 78bb099 commit dbd31ae
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
}
],
"require": {
"php": "^5.6 || ^7.0"
"php": "^5.6 || ^7.0 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7.23 || ^6.4.3",
"phpunit/phpunit": "^5.7.23 || ^6.4.3 || ^7.0",
"symfony/process": "^3.3"
},
"autoload": {
Expand Down
4 changes: 2 additions & 2 deletions src/v3_0/Output/UnifiedDiffOutputBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public function getDiff(array $diff)

\fclose($buffer);

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

return "\n" !== $last && "\r" !== $last
return 0 !== \strlen($diff) && "\n" !== $last && "\r" !== $last
? $diff . "\n"
: $diff
;
Expand Down
29 changes: 29 additions & 0 deletions tests/v3_0/Output/StrictUnifiedDiffOutputBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,35 @@ public function testEmptyDiff()
);
}

/**
* @param string $from
* @param string $to
*
* @dataProvider provideSameEmptyDiff
*/
public function testSameEmptyDiff($from, $to)
{
$builder = new StrictUnifiedDiffOutputBuilder([
'fromFile' => 'input.txt',
'toFile' => 'output.txt',
]);

$differ = new Differ($builder);

$this->assertSame(
'',
$differ->diff($from, $to)
);
}

public function provideSameEmptyDiff()
{
return [
['', ''],
['a', 'a'],
];
}

/**
* @param array $options
* @param string $message
Expand Down
24 changes: 24 additions & 0 deletions tests/v3_0/Output/UnifiedDiffOutputBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,28 @@ public function provideDiffWithLineNumbers()
{
return UnifiedDiffOutputBuilderDataProvider::provideDiffWithLineNumbers();
}

/**
* @param string $from
* @param string $to
*
* @dataProvider provideStringsThatAreTheSame
*/
public function testEmptyDiffProducesEmptyOutput($from, $to)
{
$differ = new Differ(new UnifiedDiffOutputBuilder('', false));
$output = $differ->diff($from, $to);
$this->assertEmpty($output);
}

public function provideStringsThatAreTheSame()
{
return [
['', ''],
['a', 'a'],
['these strings are the same', 'these strings are the same'],
["\n", "\n"],
["multi-line strings\nare the same", "multi-line strings\nare the same"]
];
}
}

0 comments on commit dbd31ae

Please sign in to comment.