diff --git a/composer.json b/composer.json index cddb475..0b0c2ad 100644 --- a/composer.json +++ b/composer.json @@ -24,9 +24,7 @@ "ock/class-files-iterator": "self.version", "ock/helpers": "self.version", "ock/reflection": "self.version", + "phpunit/phpunit": "^10.5.38", "symfony/yaml": "^7.1.5" - }, - "require-dev": { - "phpunit/phpunit": "^10.5.38" } } diff --git a/src/Diff/ExportedArrayDiffer.php b/src/Diff/ExportedArrayDiffer.php index 2e4ceb2..1008266 100644 --- a/src/Diff/ExportedArrayDiffer.php +++ b/src/Diff/ExportedArrayDiffer.php @@ -138,7 +138,7 @@ protected function doCompareLists(array $before, array $after, int $i_before = 0 if ($i_after >= count($after)) { // There are more items in "before" list. for (; $i_before < count($before); ++$i_before) { - $diff[] = new TaggedValue('--', $before[$i_before]); + $diff[] = new TaggedValue('rm', $before[$i_before]); } return $diff; } @@ -165,7 +165,7 @@ protected function doCompareLists(array $before, array $after, int $i_before = 0 if (count($diff_minus) <= count($diff_plus)) { return [ ...$diff, - new TaggedValue('--', $before[$i_before]), + new TaggedValue('rm', $before[$i_before]), ...$diff_minus, ]; } @@ -193,16 +193,15 @@ protected function compareAssoc(array $before, array $after): array|false { $diff = []; $similar = false; foreach (array_diff_key($before, $after) as $key => $item) { - $diff['-- ' . $key] = $item; + $diff[$key] = new TaggedValue('rm', $item); } foreach ($shared_keys as $key) { $item_diff = $this->compareValues($before[$key], $after[$key]); if ($item_diff === false) { - $diff['~- ' . $key] = $before[$key]; - $diff['~+ ' . $key] = $after[$key]; + $diff[$key] = new TaggedValue('replace', $after[$key]); } elseif ($item_diff) { - $diff['~~ ' . $key] = $item_diff; + $diff[$key] = new TaggedValue('diff', $item_diff); $similar = true; } else { @@ -213,7 +212,7 @@ protected function compareAssoc(array $before, array $after): array|false { return false; } foreach (array_diff_key($after, $before) as $key => $item) { - $diff['++ ' . $key] = $item; + $diff[$key] = new TaggedValue('add', $item); } return $diff; } @@ -235,16 +234,15 @@ protected function compareExportedObjects(array $before, array $after, string $c ); $diff = []; foreach (array_diff_key($before, $after) as $key => $item) { - $diff['-- ' . $key] = $item; + $diff[$key] = new TaggedValue('rm', $item); } foreach ($shared_keys as $key) { $item_diff = $this->compareExportedObjectProperty($class, $key, $before[$key], $after[$key]); if ($item_diff === false) { - $diff['~- ' . $key] = $before[$key]; - $diff['~+ ' . $key] = $after[$key]; + $diff[$key] = new TaggedValue('replace', $after[$key]); } elseif ($item_diff) { - $diff['~~ ' . $key] = $item_diff; + $diff[$key] = new TaggedValue('diff', $item_diff); } } if (!$diff) { diff --git a/tests/fixtures/ExportedArrayDifferTest/assoc.hello.yml b/tests/fixtures/ExportedArrayDifferTest/assoc.hello.yml new file mode 100644 index 0000000..58b4659 --- /dev/null +++ b/tests/fixtures/ExportedArrayDifferTest/assoc.hello.yml @@ -0,0 +1,44 @@ +before: + hello: hello + 'good day': 'good day' + remove: remove + assoc_diff: + a: A + b: B + assoc_replace: + r: R + assoc_keep: + b: B + assoc_drop: + x: X + internet: internet + goodbye: goodbye +after: + assoc_replace: + rr: RR + assoc_diff: + a: A + b: BB + hello: salut + goodbye: 'a bientot' + assoc_keep: + b: B + assoc_new: + new: New + ajouter: ajouter + 'good day': bonjour + internet: internet +diff: + assoc_drop: !rm + x: X + remove: !rm remove + assoc_diff: !diff + b: !replace BB + assoc_replace: !replace + rr: RR + 'good day': !replace bonjour + goodbye: !replace 'a bientot' + hello: !replace salut + ajouter: !add ajouter + assoc_new: !add + new: New diff --git a/tests/fixtures/ExportedArrayDifferTest/list.change-assoc-value.yml b/tests/fixtures/ExportedArrayDifferTest/list.change-assoc-value.yml index 50a4106..a788a94 100644 --- a/tests/fixtures/ExportedArrayDifferTest/list.change-assoc-value.yml +++ b/tests/fixtures/ExportedArrayDifferTest/list.change-assoc-value.yml @@ -17,12 +17,11 @@ after: b: 'B orig' - after diff: - - !-- + - !rm a: 'A orig' b: 'B orig' - !add a: 'A changed' b: 'B changed' - !diff - '~- a': 'A orig' - '~+ a': 'A changed' + a: !replace 'A changed' diff --git a/tests/fixtures/ExportedArrayDifferTest/list.hello.yml b/tests/fixtures/ExportedArrayDifferTest/list.hello.yml index 9e13c7a..2426777 100644 --- a/tests/fixtures/ExportedArrayDifferTest/list.hello.yml +++ b/tests/fixtures/ExportedArrayDifferTest/list.hello.yml @@ -5,5 +5,5 @@ after: - goodbye - world diff: - - !-- hello + - !rm hello - !add goodbye