From 7f0e10a0b22c4c8a1dc7b91d0fcdf321a490d177 Mon Sep 17 00:00:00 2001 From: soyuka Date: Sun, 16 Aug 2026 20:28:15 +0200 Subject: [PATCH] test: assert rating as a json number across json-streamer versions #8461 changed the rating assertions to assertIsFloat/assertSame(0.0), which pins them to json-streamer >= 8.1.4 where JSON_PRESERVE_ZERO_FRACTION is set. The Symfony lowest job resolves an earlier release that encodes an integral float as 5, so the assertions failed there. Assert that the decoded value is a JSON number of either PHP type instead. Verified on json-streamer 8.1.2 and 8.1.4. --- tests/Functional/JsonStreamerTest.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/Functional/JsonStreamerTest.php b/tests/Functional/JsonStreamerTest.php index b362015423..7b0aedbe3a 100644 --- a/tests/Functional/JsonStreamerTest.php +++ b/tests/Functional/JsonStreamerTest.php @@ -113,7 +113,9 @@ 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->assertIsFloat($res['rating']); + // json-streamer only encodes with JSON_PRESERVE_ZERO_FRACTION since 8.1.4, so an integral + // float decodes as int on lower versions + $this->assertTrue(\is_int($res['rating']) || \is_float($res['rating'])); $this->assertIsBool($res['isFeatured']); $this->assertIsString($res['price']); $this->assertEquals('/json_stream_resources/1', $res['@id']); @@ -170,7 +172,9 @@ 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->assertIsFloat($res['rating']); + // json-streamer only encodes with JSON_PRESERVE_ZERO_FRACTION since 8.1.4, so an integral + // float decodes as int on lower versions + $this->assertTrue(\is_int($res['rating']) || \is_float($res['rating'])); $this->assertIsBool($res['isFeatured']); $this->assertIsString($res['price']); $this->assertArrayNotHasKey('@id', $res); @@ -227,7 +231,7 @@ public function testJsonStreamerWriteJsonLd(): void $this->assertResponseIsSuccessful(); $this->assertSame('asd', $res['title']); $this->assertSame(0, $res['views']); - $this->assertSame(0.0, $res['rating']); + $this->assertEquals(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 +280,7 @@ public function testJsonStreamerWriteJson(): void $this->assertResponseIsSuccessful(); $this->assertSame('asd', $res['title']); $this->assertSame(0, $res['views']); - $this->assertSame(0.0, $res['rating']); + $this->assertEquals(0, $res['rating']); $this->assertFalse($res['isFeatured']); $this->assertContains($res['price'], ['0', '0.00']); // Depends on DB $this->assertArrayNotHasKey('@id', $res);