New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JsonMatches for [] and {} #2938

Merged
merged 1 commit into from Feb 1, 2018

Conversation

3 participants
@mkasberg
Contributor

mkasberg commented Dec 23, 2017

This commit fixes #2919 (assertJsonStringEqualsJsonString empty object
matches empty array).

We had a problem where JsonMatches would report that the JSON string
'{}' matches the JSON string '[]'. This bug was due to the fact that
Json::canonicalize() was converting JSON strings to PHP arrays. In a PHP
array, there is no difference between an empty associative array and an
empty indexed array, so Json::canonicalize() did not distinguish between
them either. The solution we apply here is to deserialize JSON into
objects (rather than associative arrays) so that PHP can distinguish
between an empty object and an empty array. If the object is not empty,
we still ultimately convert it to an associative array so we can sort
its keys.

Fix JsonMatches for [] and {}
This commit fixes #2919 (assertJsonStringEqualsJsonString empty object
matches empty array).

We had a problem where JsonMatches would report that the JSON string
'{}' matches the JSON string '[]'. This bug was due to the fact that
Json::canonicalize() was converting JSON strings to PHP arrays. In a PHP
array, there is no difference between an empty associative array and an
empty indexed array, so Json::canonicalize() did not distinguish between
them either. The solution we apply here is to deserialize JSON into
objects (rather than associative arrays) so that PHP _can_ distinguish
between an empty object and an empty array. If the object is not empty,
we still ultimately convert it to an associative array so we can sort
its keys.
@codecov-io

This comment has been minimized.

codecov-io commented Dec 23, 2017

Codecov Report

Merging #2938 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2938      +/-   ##
============================================
+ Coverage     79.86%   79.86%   +<.01%     
- Complexity     2822     2824       +2     
============================================
  Files           107      107              
  Lines          7438     7440       +2     
============================================
+ Hits           5940     5942       +2     
  Misses         1498     1498
Impacted Files Coverage Δ Complexity Δ
src/Util/Json.php 100% <100%> (ø) 9 <0> (+2) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 92a2617...9664d70. Read the comment docs.

@sebastianbergmann sebastianbergmann merged commit 8e06f3f into sebastianbergmann:master Feb 1, 2018

5 checks passed

codecov/patch 100% of diff hit (target 79.86%)
Details
codecov/project 79.86% (+<.01%) compared to 92a2617
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
stickler-ci No lint errors found.

@mkasberg mkasberg deleted the mkasberg:issue-2919 branch Feb 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment