Skip to content

test: assert rating as a json number across json-streamer versions - #8463

Merged
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/jsonstreamer-rating-version-tolerant
Aug 16, 2026
Merged

test: assert rating as a json number across json-streamer versions#8463
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/jsonstreamer-rating-version-tolerant

Conversation

@soyuka

@soyuka soyuka commented Aug 16, 2026

Copy link
Copy Markdown
Member

Fixes the PHPUnit (PHP 8.3) (Symfony lowest) job, which #8461 broke.

What broke

#8461 adapted the rating assertions to json-streamer 8.1.4, which encodes with JSON_PRESERVE_ZERO_FRACTION:

$this->assertIsFloat($res['rating']);
$this->assertSame(0.0, $res['rating']);

That pins the test to >= 8.1.4. The Symfony lowest job runs composer update --prefer-lowest, which resolves an earlier json-streamer that encodes an integral float as 5:

1) JsonStreamerTest::testJsonStreamerJsonLd
Failed asserting that 5 is of type float.
2) JsonStreamerTest::testJsonStreamerJson
Failed asserting that 4 is of type float.

Symfony lowest was green on e22463fdb and red from e3cb2da6c (#8461), so this is a clean regression rather than a pre-existing condition.

Fix

The PHP type of a decoded JSON number is an encoder detail that varies by version; the assertion should not depend on it. Assert that it is a JSON number of either type:

// 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']));

and compare the write-path value loosely (assertEquals(0, ...)) so 0 and 0.0 both satisfy it. views (a real int) and price (a string) keep their strict assertions.

Verification

Reproduced the failure locally by downgrading to json-streamer 8.1.2 — the assertions on 4.3 fail exactly as CI reports:

Failed asserting that 4 is of type float.
Failed asserting that 3 is of type float.
Failed asserting that 0 is identical to 0.0.

With this change, phpunit tests/Functional --filter JsonStreamer passes under both json-streamer 8.1.2 and 8.1.4 (7 tests, 41 assertions, 1 skipped). composer.json restored afterwards; only the test file changes.

api-platform#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.
@soyuka
soyuka merged commit fd8cd2c into api-platform:4.3 Aug 16, 2026
110 of 112 checks passed
@soyuka
soyuka deleted the fix/jsonstreamer-rating-version-tolerant branch August 16, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant