8000 bug #20265 [VarDumper] Fix ArgsStub (nicolas-grekas) · symfony/symfony@030ddcf · GitHub
[go: up one dir, main page]

Skip to content

Commit 030ddcf

Browse files
committed
bug #20265 [VarDumper] Fix ArgsStub (nicolas-grekas)
This PR was merged into the 3.2-dev branch. Discussion ---------- [VarDumper] Fix ArgsStub | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Two bugs fixed here: - ArgsStub changing the value of arguments passed by reference - `class::function` used with off-by-one `args` Commits ------- 808c25e [VarDumper] Fix ArgsStub
2 parents 4eeb1f0 + 808c25e commit 030ddcf

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

src/Symfony/Component/VarDumper/Caster/ArgsStub.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ class ArgsStub extends EnumStub
2222
{
2323
private static $parameters = array();
2424

25-
public function __construct(array $values, $function, $class)
25+
public function __construct(array $args, $function, $class)
2626
{
2727
list($variadic, $params) = self::getParameters($function, $class);
2828

29-
foreach ($values as $k => $v) {
30-
if (!is_scalar($v) && !$v instanceof Stub) {
31-
$values[$k] = new CutStub($v);
32-
}
29+
$values = array();
30+
foreach ($args as $k => $v) {
31+
$values[$k] = !is_scalar($v) && !$v instanceof Stub ? new CutStub($v) : $v;
3332
}
3433
if (null === $params) {
3534
parent::__construct($values, false);

src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,17 @@ public static function castTraceStub(TraceStub $trace, array $a, Stub $stub, $is
109109
'type' => isset($f['type']) ? $f['type'] : null,
110110
'function' => isset($f['function']) ? $f['function'] : null,
111111
) + $frames[$i - 1],
112-
$trace->keepArgs,
112+
false,
113113
true
114114
);
115115
$f = self::castFrameStub($frame, array(), $frame, true);
116116
if (isset($f[$prefix.'src'])) {
117117
foreach ($f[$prefix.'src']->value as $label => $frame) {
118118
$label = substr_replace($label, "title=Stack level $j.&", 2, 0);
119119
}
120-
if (isset($f[$prefix.'arguments']) && $frame instanceof EnumStub) {
121-
$frame->value['arguments'] = $f[$prefix.'arguments'];
120+
$f = $frames[$i - 1];
121+
if ($trace->keepArgs && !empty($f['args']) && $frame instanceof EnumStub) {
122+
$frame->value['arguments'] = new ArgsStub($f['args'], isset($f['function']) ? $f['function'] : null, isset($f['class']) ? $f['class'] : null);
122123
}
123124
}
124125
$a[$label] = $frame;

src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class ExceptionCasterTest extends \PHPUnit_Framework_TestCase
2121
{
2222
use VarDumperTestTrait;
2323

24-
private function getTestException()
24+
private function getTestException($msg, &$ref = null)
2525
{
26-
return new \Exception('foo');
26+
return new \Exception(''.$msg);
2727
}
2828

2929
protected function tearDown()
@@ -34,7 +34,8 @@ protected function tearDown()
3434

3535
public function testDefaultSettings()
3636
{
37-
$e = $this->getTestException($this);
37+
$ref = array('foo');
38+
$e = $this->getTestException('foo', $ref);
3839

3940
$expectedDump = <<<'EODUMP'
4041
Exception {
@@ -45,21 +46,23 @@ public function testDefaultSettings()
4546
-trace: {
4647
%sExceptionCasterTest.php:26: {
4748
: {
48-
: return new \Exception('foo');
49+
: return new \Exception(''.$msg);
4950
: }
5051
}
5152
%sExceptionCasterTest.php:%d: {
52-
: {
53-
: $e = $this->getTestException($this);
53+
: $ref = array('foo');
54+
: $e = $this->getTestException('foo', $ref);
5455
:
5556
arguments: {
56-
Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest {#1 …}
57+
$msg: "foo"
58+
&$ref: array:1 [ …1]
5759
}
5860
}
5961
%A
6062
EODUMP;
6163

6264
$this->assertDumpMatchesFormat($expectedDump, $e);
65+
$this->assertSame(array('foo'), $ref);
6366
}
6467

6568
public function testSeek()
@@ -70,15 +73,15 @@ public function testSeek()
7073
{
7174
%sExceptionCasterTest.php:26: {
7275
: {
73-
: return new \Exception('foo');
76+
: return new \Exception(''.$msg);
7477
: }
7578
}
7679
%sExceptionCasterTest.php:%d: {
7780
: {
7881
: $e = $this->getTestException(2);
7982
:
8083
arguments: {
81-
2
84+
$msg: 2
8285
}
8386
}
8487
%A
@@ -94,14 +97,14 @@ public function testNoArgs()
9497

9598
$expectedDump = <<<'EODUMP'
9699
Exception {
97-
#message: "foo"
< DA37 /td>
100+
#message: "1"
98101
#code: 0
99102
#file: "%sExceptionCasterTest.php"
100103
#line: 26
101104
-trace: {
102105
%sExceptionCasterTest.php:26: {
103106
: {
104-
: return new \Exception('foo');
107+
: return new \Exception(''.$msg);
105108
: }
106109
}
107110
%sExceptionCasterTest.php:%d: {
@@ -122,7 +125,7 @@ public function testNoSrcContext()
122125

123126
$expectedDump = <<<'EODUMP'
124127
Exception {
125-
#message: "foo"
128+
#message: "1"
126129
#code: 0
127130
#file: "%sExceptionCasterTest.php"
128131
#line: 26
@@ -149,7 +152,7 @@ public function testHtmlDump()
149152

150153
$expectedDump = <<<'EODUMP'
151154
<foo></foo><bar><span class=sf-dump-note>Exception</span> {<samp>
152-
#<span class=sf-dump-protected title="Protected property">message</span>: "<span class=sf-dump-str title="3 characters">foo</span>"
155+
#<span class=sf-dump-protected title="Protected property">message</span>: "<span class=sf-dump-str>1</span>"
153156
#<span class=sf-dump-protected title="Protected property">code</span>: <span class=sf-dump-num>0</span>
154157
#<span class=sf-dump-protected title="Protected property">file</span>: "<span class=sf-dump-str title="%sExceptionCasterTest.php
155158
%d characters"><span class=sf-dump-ellipsis>%sTests</span>%eCaster%eExceptionCasterTest.php</span>"

0 commit comments

Comments
 (0)
0