Skip to content

Commit

Permalink
Improve readability of generated JSON snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky committed Nov 19, 2024
1 parent 4d99b6d commit 1a2fb51
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Drivers/JsonDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function serialize($data): string
throw new CantBeSerialized('Resources can not be serialized to json');
}

return json_encode($data, JSON_PRETTY_PRINT)."\n";
return json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)."\n";
}

public function extension(): string
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/Drivers/JsonDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public function it_can_serialize_a_json_string_to_pretty_json()

$expected = implode("\n", [
'{',
' "foo": "bar"',
' "foo": "bar/baz 😊"',
'}',
'',
]);

$this->assertEquals($expected, $driver->serialize('{"foo":"bar"}'));
$this->assertEquals($expected, $driver->serialize('{"foo":"bar\/baz \ud83d\ude0a"}'));
}

#[Test]
Expand Down Expand Up @@ -135,6 +135,7 @@ public function it_can_not_serialize_resources()
#[TestWith(['1', '1', true])]
#[TestWith(['1.1', '1.1', true])]
#[TestWith(['{"empty": []}', '{"empty":{}}', false])]
#[TestWith(['{"url": "foo\/bar😊"}', '{"url":"foo/bar\ud83d\ude0a"}', true])]
public function it_can_match_json_strings(string $expected, string $actual, bool $assertion)
{
$driver = new JsonDriver;
Expand Down

0 comments on commit 1a2fb51

Please sign in to comment.