Skip to content

Commit 907c73b

Browse files
SpacePossumsebastianbergmann
authored andcommitted
Differ - fix diffing array's.
1 parent abcc704 commit 907c73b

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/Differ.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public function __construct($outputBuilder = null)
6161
*/
6262
public function diff($from, $to, LongestCommonSubsequenceCalculator $lcs = null): string
6363
{
64-
$from = $this->validateDiffInput($from);
65-
$to = $this->validateDiffInput($to);
64+
$from = $this->normalizeDiffInput($from);
65+
$to = $this->normalizeDiffInput($to);
6666
$diff = $this->diffToArray($from, $to, $lcs);
6767

6868
return $this->outputBuilder->getDiff($diff);
@@ -73,9 +73,9 @@ public function diff($from, $to, LongestCommonSubsequenceCalculator $lcs = null)
7373
*
7474
* @param mixed $input
7575
*
76-
* @return string
76+
* @return string|array
7777
*/
78-
private function validateDiffInput($input): string
78+
private function normalizeDiffInput($input)
7979
{
8080
if (!\is_array($input) && !\is_string($input)) {
8181
return (string) $input;

tests/DifferTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ public function testTypesOtherThanArrayAndStringCanBePassed()
9090
);
9191
}
9292

93+
public function testArrayDiffs()
94+
{
95+
$this->assertSame(
96+
'--- Original
97+
+++ New
98+
@@ @@
99+
-one
100+
+two
101+
',
102+
$this->differ->diff(array('one'), array('two'))
103+
);
104+
}
105+
93106
public function arrayProvider(): array
94107
{
95108
return [

0 commit comments

Comments
 (0)