From 0b0684ac0c68db229764d73bea6fd4fcb0d88c4d Mon Sep 17 00:00:00 2001 From: soyuka Date: Sun, 16 Aug 2026 12:18:25 +0200 Subject: [PATCH] test: adapt json-streamer and object-mapper fixtures to Symfony 8.1.4 json-streamer 8.1.4 encodes with JSON_PRESERVE_ZERO_FRACTION, so the float $rating property is now emitted as 5.0 rather than 5; assert a float. object-mapper 8.1.4 honours the target property's #[Map] for the same-name copy, so the untransformed string id reached a ?int setter. Declare the inverse transform the fixture was missing; verified on both 8.1.1 and 8.1.4. --- .../TestBundle/ApiResource/MappedResourceWithRelation.php | 1 + tests/Functional/JsonStreamerTest.php | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/Fixtures/TestBundle/ApiResource/MappedResourceWithRelation.php b/tests/Fixtures/TestBundle/ApiResource/MappedResourceWithRelation.php index b8c55dc4de6..4e2de6c7bc3 100644 --- a/tests/Fixtures/TestBundle/ApiResource/MappedResourceWithRelation.php +++ b/tests/Fixtures/TestBundle/ApiResource/MappedResourceWithRelation.php @@ -35,6 +35,7 @@ #[Map(target: MappedResourceWithRelationEntity::class)] class MappedResourceWithRelation { + #[Map(transform: 'intval')] public ?string $id = null; #[Map(if: false)] public ?string $relationName = null; diff --git a/tests/Functional/JsonStreamerTest.php b/tests/Functional/JsonStreamerTest.php index 92749003e82..b362015423f 100644 --- a/tests/Functional/JsonStreamerTest.php +++ b/tests/Functional/JsonStreamerTest.php @@ -113,7 +113,7 @@ public function testJsonStreamerJsonLd(): void $r = self::createClient()->request('GET', '/json_stream_resources/1', ['headers' => ['accept' => 'application/ld+json']]); $res = json_decode($r->getBrowserKitResponse()->getContent(), true); $this->assertIsInt($res['views']); - $this->assertIsInt($res['rating']); + $this->assertIsFloat($res['rating']); $this->assertIsBool($res['isFeatured']); $this->assertIsString($res['price']); $this->assertEquals('/json_stream_resources/1', $res['@id']); @@ -170,7 +170,7 @@ public function testJsonStreamerJson(): void $r = self::createClient()->request('GET', '/json_stream_resources/1', ['headers' => ['accept' => 'application/json']]); $res = json_decode($r->getBrowserKitResponse()->getContent(), true); $this->assertIsInt($res['views']); - $this->assertIsInt($res['rating']); + $this->assertIsFloat($res['rating']); $this->assertIsBool($res['isFeatured']); $this->assertIsString($res['price']); $this->assertArrayNotHasKey('@id', $res); @@ -227,7 +227,7 @@ public function testJsonStreamerWriteJsonLd(): void $this->assertResponseIsSuccessful(); $this->assertSame('asd', $res['title']); $this->assertSame(0, $res['views']); - $this->assertSame(0, $res['rating']); + $this->assertSame(0.0, $res['rating']); $this->assertFalse($res['isFeatured']); $this->assertContains($res['price'], ['0', '0.00']); // Depends on DB $this->assertStringStartsWith('/json_stream_resources/', $res['@id']); @@ -276,7 +276,7 @@ public function testJsonStreamerWriteJson(): void $this->assertResponseIsSuccessful(); $this->assertSame('asd', $res['title']); $this->assertSame(0, $res['views']); - $this->assertSame(0, $res['rating']); + $this->assertSame(0.0, $res['rating']); $this->assertFalse($res['isFeatured']); $this->assertContains($res['price'], ['0', '0.00']); // Depends on DB $this->assertArrayNotHasKey('@id', $res);