Skip to content

Commit 47572a0

Browse files
committed
Support null json
1 parent ee07023 commit 47572a0

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Configuration in services.yml:
119119

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

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

src/Testing/UnicodeIgnoreOrderJsonDriver.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* This driver is responsible for 3 main things:
1313
*
14-
* 1) Show unicode characters unescaped in json, so you'll see Привет instead of \u041F\u0440\u0438\u0432\u0435\u0442
14+
* 1) Show unicode characters unescaped in json, so you'll see "£" instead of "\u00a3"
1515
* 2) Ignore property order. Example equal json {a: 1, b: 2} and {b: 2, a: 1}
1616
* 3) Ignore order of array elements in json. Example equal json arrays [{a: 1}, {b: 2}] and [{b: 2}, {a: 1}]
1717
*/
@@ -37,6 +37,10 @@ public function extension(): string
3737

3838
public static function sortJsonRecursively(mixed $array): mixed
3939
{
40+
if ($array === null) {
41+
return null;
42+
}
43+
4044
if (array_is_list($array) && count($array) > 0 && isset($array[0]) && is_array($array[0])) {
4145
foreach ($array as &$v) {
4246
$v = self::sortJsonRecursively($v);

0 commit comments

Comments
 (0)