-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[VarDumper] Fix dumping jsons casted as arrays #19368
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
8000
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[VarDumper] Fix dumping jsons casted as arrays
- Loading branch information
commit 56549e7a704f38cc73538096f907655b19f457af
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,6 +135,72 @@ public function testClone() | |
$this->assertStringMatchesFormat($expected, print_r($clone, true)); | ||
} | ||
|
||
public function testJsonCast() | ||
{ | ||
$data = (array) json_decode('{"1":{}}'); | ||
|
||
$cloner = new VarCloner(); | ||
$clone = $cloner->cloneVar($data); | ||
|
||
$expected = <<<'EOTXT' | ||
object(Symfony\Component\VarDumper\Cloner\Data)#%i (4) { | ||
["data":"Symfony\Component\VarDumper\Cloner\Data":private]=> | ||
array(2) { | ||
[0]=> | ||
array(1) { | ||
[0]=> | ||
object(Symfony\Component\VarDumper\Cloner\Stub)#%i (7) { | ||
["type"]=> | ||
string(5) "array" | ||
["class"]=> | ||
string(5) "assoc" | ||
["value"]=> | ||
int(1) | ||
["cut"]=> | ||
int(0) | ||
["handle"]=> | ||
int(0) | ||
["refCount"]=> | ||
int(0) | ||
["position"]=> | ||
int(1) | ||
} | ||
} | ||
[1]=> | ||
array(1) { | ||
["1"]=> | ||
object(Symfony\Component\VarDumper\Cloner\Stub)#%i (7) { | ||
["type"]=> | ||
string(6) "object" | ||
["class"]=> | ||
string(8) "stdClass" | ||
["value"]=> | ||
NULL | ||
["cut"]=> | ||
int(0) | ||
["handle"]=> | ||
int(%i) | ||
["refCount"]=> | ||
int(0) | ||
["position"]=> | ||
int(0) | ||
} | ||
} | ||
} | ||
["maxDepth":"Symfony\Component\VarDumper\Cloner\Data":private]=> | ||
int(20) | ||
["maxItemsPerDepth":"Symfony\Component\VarDumper\Cloner\Data":private]=> | ||
int(-1) | ||
["useRefHandles":"Symfony\Component\VarDumper\Cloner\Data":private]=> | ||
int(-1) | ||
} | ||
|
||
EOTXT; | ||
ob_start(); | ||
var_dump($clone); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why making a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. VarClonerTest uses only native primitives. |
||
$this->assertStringMatchesFormat($expected, ob_get_clean()); | ||
} | ||
|
||
public function testCaster() | ||
{ | ||
$cloner = new VarCloner(array( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the important line:
"1"
instead of a plain1
. Onlyjson_decode()
can create these.