From 5aa53a97db14d352f10c225713e4318b3eabbdd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sat, 10 Dec 2022 23:29:38 +0100 Subject: [PATCH] Enhancement: Assert that JSON is consistently decoded to an object --- psalm-baseline.xml | 6 ++++++ test/Unit/JsonTest.php | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index f06648e..914c7f6 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -16,4 +16,10 @@ \Generator<string, array{0: string}> + + + $decoded + $decoded + + diff --git a/test/Unit/JsonTest.php b/test/Unit/JsonTest.php index 6ec9cd4..282bc6d 100644 --- a/test/Unit/JsonTest.php +++ b/test/Unit/JsonTest.php @@ -52,7 +52,15 @@ public function testFromStringReturnsJsonWhenValueIsValidJson(string $encoded): self::assertSame($encoded, $json->toString()); self::assertSame($encoded, $json->encoded()); - self::assertJsonStringEqualsJsonString($encoded, \json_encode($json->decoded())); + + $decoded = \json_decode( + $encoded, + false, + 512, + \JSON_THROW_ON_ERROR, + ); + + self::assertEquals($decoded, $json->decoded()); } public function testFromFileThrowsWhenFileDoesNotExist(): void @@ -90,5 +98,15 @@ public function testFromFileReturnsJsonWhenFileContainsValidJson(string $file): $json = Json::fromFile($file); self::assertStringEqualsFile($file, $json->toString()); + self::assertStringEqualsFile($file, $json->encoded()); + + $decoded = \json_decode( + \file_get_contents($file), + false, + 512, + \JSON_THROW_ON_ERROR, + ); + + self::assertEquals($decoded, $json->decoded()); } }