core
core copied to clipboard
feat(testing): Improve ApiTestAssertionsTrait::assertJsonEquals
Q | A |
---|---|
Branch | main |
Tickets | Closes #5751, closes #5751 |
License | MIT |
Improve ApiTestAssertionsTrait::assertJsonEquals by replacing assertEqualsCanonicalizing
with assertEquals
.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
just came across this.
It is madness that assertJsonEquals
currently ignores keys.
I've found a few ignored errors in my testsuite down to this.
We should look to get this merged.
Should we target another branch then main though? @dunglas any opinion?
it seems we should be using https://github.com/sebastianbergmann/phpunit/blob/main/src/Framework/Constraint/JsonMatches.php in some way which does the canonicalizing
this seems to do the trick
public static function assertJsonEquals(array|string $json, string $message = ''): void
{
if (\is_array($json)) {
$json = json_encode(
$json,
JSON_UNESCAPED_UNICODE
| JSON_UNESCAPED_SLASHES
| JSON_PRESERVE_ZERO_FRACTION
| JSON_THROW_ON_ERROR);
}
$constraint = new JsonMatches($json);
static::assertThat(self::getHttpResponse()->getContent(false), $constraint, $message);
}
thanks @DaedalusDev @bendavies !