Skip to content

Commit

Permalink
Support null json
Browse files Browse the repository at this point in the history
  • Loading branch information
kubk committed Aug 22, 2023
1 parent ee07023 commit 47572a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Configuration in services.yml:

A driver for the [phpunit-snapshot-assertions](https://github.com/spatie/phpunit-snapshot-assertions) library. This driver is responsible for 3 main things:

1) Show unicode characters unescaped in json, so you'll see `Привет` instead of `\u041F\u0440\u0438\u0432\u0435\u0442`
1) Show unicode characters unescaped in json, so you'll see "£" instead of "\u00a3"
2) Ignore property order. Example equal json `{a: 1, b: 2}` and `{b: 2, a: 1}`
3) Ignore order of array elements in json. Example equal json arrays `[{a: 1}, {b: 2}]` and `[{b: 2}, {a: 1}]`

Expand Down
6 changes: 5 additions & 1 deletion src/Testing/UnicodeIgnoreOrderJsonDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* This driver is responsible for 3 main things:
*
* 1) Show unicode characters unescaped in json, so you'll see Привет instead of \u041F\u0440\u0438\u0432\u0435\u0442
* 1) Show unicode characters unescaped in json, so you'll see "£" instead of "\u00a3"
* 2) Ignore property order. Example equal json {a: 1, b: 2} and {b: 2, a: 1}
* 3) Ignore order of array elements in json. Example equal json arrays [{a: 1}, {b: 2}] and [{b: 2}, {a: 1}]
*/
Expand All @@ -37,6 +37,10 @@ public function extension(): string

public static function sortJsonRecursively(mixed $array): mixed
{
if ($array === null) {
return null;
}

if (array_is_list($array) && count($array) > 0 && isset($array[0]) && is_array($array[0])) {
foreach ($array as &$v) {
$v = self::sortJsonRecursively($v);
Expand Down

0 comments on commit 47572a0

Please sign in to comment.