Skip to content
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

[5.7] Fix(tester): TestResponse assertExactJson does not work for empty JSON objects #26353

Merged
merged 8 commits into from
Nov 12, 2018

Conversation

alberthuang24
Copy link

Solved the problems mentioned in #25960 and #25769.

After the old decodeResponseJson directly operates on the response content json_decode($content, true), it is impossible to tell the difference between empty object and empty array.

$data = [
    'a' => new class {}
];

var_dump(json_encode($data)); 
var_dump(json_decode(json_encode($data), true)); 
var_dump(json_decode(json_encode($data)));


result: 

string(8) "{"a":{}}"
array(1) {
  ["a"]=>
  array(0) {
  }
}
object(stdClass)#4313 (1) {
  ["a"]=>
  object(stdClass)#4315 (0) {
  }
}

Therefore, if we want to distinguish between empty object and empty array, we need to change the second parameter $assoc to false.
But that's not compatible with the logic that preceded it. The assoc array is resolved to stdclass.
So. for compatibility, I have json_decode($data, true) and json_decode($data, false); Only get json_decode($data, false); The empty object inside is thus compatible with the previous logic, and the bug is fixed.

@taylorotwell
Copy link
Member

I still have no idea what your method is doing. Give it a descriptive name and docblock.

@alberthuang24
Copy link
Author

I still have no idea what your method is doing. Give it a descriptive name and docblock.

Hey, I re-implementation and Added detailed docblock.

@alberthuang24
Copy link
Author

@taylorotwell

@alberthuang24
Copy link
Author

poke @taylorotwell

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.

2 participants