Skip to content

Commit

Permalink
Merge branch '5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Aug 12, 2024
2 parents 82d8c81 + 2d3e04c commit 9952ac3
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="php-cs-fixer" version="^3.59" installed="3.59.3" location="./tools/php-cs-fixer" copy="true"/>
<phar name="php-cs-fixer" version="^3.59" installed="3.62.0" location="./tools/php-cs-fixer" copy="true"/>
<phar name="composer" version="^2.7" installed="2.7.7" location="./tools/composer" copy="true"/>
<phar name="phpstan" version="^1.11" installed="1.11.5" location="./tools/phpstan" copy="true"/>
<phar name="phpstan" version="^1.11" installed="1.11.10" location="./tools/phpstan" copy="true"/>
</phive>
7 changes: 7 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt

* Removed support for PHP 8.1

## [5.0.2] - 2024-08-12

### Fixed

* [#112](https://github.com/sebastianbergmann/comparator/issues/112): Arrays with different keys and the same values are considered equal in canonicalize mode

## [5.0.1] - 2023-08-14

### Fixed
Expand Down Expand Up @@ -158,6 +164,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt

[6.0.1]: https://github.com/sebastianbergmann/comparator/compare/6.0.0...6.0.1
[6.0.0]: https://github.com/sebastianbergmann/comparator/compare/5.0...6.0.0
[5.0.2]: https://github.com/sebastianbergmann/comparator/compare/5.0.1...5.0.2
[5.0.1]: https://github.com/sebastianbergmann/comparator/compare/5.0.0...5.0.1
[5.0.0]: https://github.com/sebastianbergmann/comparator/compare/4.0.8...5.0.0
[4.0.8]: https://github.com/sebastianbergmann/comparator/compare/4.0.7...4.0.8
Expand Down
10 changes: 8 additions & 2 deletions src/ArrayComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
namespace SebastianBergmann\Comparator;

use function array_is_list;
use function array_key_exists;
use function assert;
use function is_array;
Expand Down Expand Up @@ -41,8 +42,13 @@ public function assertEquals(mixed $expected, mixed $actual, float $delta = 0.0,
assert(is_array($actual));

if ($canonicalize) {
sort($expected);
sort($actual);
if (array_is_list($expected)) {
sort($expected);
}

if (array_is_list($actual)) {
sort($actual);
}
}

$remaining = $actual;
Expand Down
42 changes: 42 additions & 0 deletions tests/unit/ArrayComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@ public static function assertEqualsSucceedsProvider(): array
['true'],
[true],
],
[
[1, [1, 2, 3]],
[[3, 1, 2], 1],
0,
true,
],
[
[1, [4, 7], [1, 2, 3], [0, 0, 0, 0]],
[[3, 1, 2], [0, 0, 0, 0], [4, 7], 1],
0,
true,
],
[
[1, [4, [4, 5, 6, 7, 8]], [1, 2, 3]],
[[3, 1, 2], [[4, 8, 6, 7, 5], 4], 1],
0,
true,
],
[
[null, null, 1, 1],
[1, null, 1, null],
0,
true,
],
];
}

Expand Down Expand Up @@ -121,6 +145,24 @@ public static function assertEqualsFailsProvider(): array
['false'],
[false],
],
[
['a' => '1', 'b' => '2'],
['c' => '1', 'd' => '2'],
0,
true,
],
[
['a' => '1', 'b' => '2'],
['a' => '2', 'b' => '1'],
0,
true,
],
[
['a' => '1', 'b' => '2'],
['a' => '1', 'b' => '2', 'c' => '2'],
0,
true,
],
];
}

Expand Down
Binary file modified tools/php-cs-fixer
Binary file not shown.
Binary file modified tools/phpstan
Binary file not shown.

0 comments on commit 9952ac3

Please sign in to comment.