diff --git a/CHANGELOG.md b/CHANGELOG.md index 561119b4..81444761 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), For a full diff see [`1.0.0...main`][1.0.0...main]. +### Fixed + +- Decoded JSON `string` to an object, not an associative array, when constructing `Json` from file name ([#3]), by [@localheinz] + ## [`1.0.0`][1.0.0] For a full diff see [`c020e6f...1.0.0`][c020e6f...1.0.0]. @@ -24,5 +28,6 @@ For a full diff see [`c020e6f...1.0.0`][c020e6f...1.0.0]. [#1]: https://github.com/ergebnis/json/pull/1 [#2]: https://github.com/ergebnis/json/pull/2 +[#3]: https://github.com/ergebnis/json/pull/3 [@localheinz]: https://github.com/localheinz diff --git a/infection.json b/infection.json index 4e433d13..8eddeaf4 100644 --- a/infection.json +++ b/infection.json @@ -4,7 +4,7 @@ "text": ".build/infection/infection-log.txt" }, "minCoveredMsi": 100, - "minMsi": 70, + "minMsi": 66, "phpUnit": { "configDir": "test\/Unit" }, diff --git a/psalm-baseline.xml b/psalm-baseline.xml index f06648e1..914c7f67 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -16,4 +16,10 @@ \Generator<string, array{0: string}> + + + $decoded + $decoded + + diff --git a/src/Json.php b/src/Json.php index 07b5adca..29aea6d6 100644 --- a/src/Json.php +++ b/src/Json.php @@ -69,7 +69,7 @@ public static function fromFile(string $file): self try { $decoded = \json_decode( $encoded, - true, + false, 512, \JSON_THROW_ON_ERROR, ); diff --git a/test/Unit/JsonTest.php b/test/Unit/JsonTest.php index 6ec9cd49..282bc6d2 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()); } }