Navigation Menu

Skip to content

Commit

Permalink
bug #19623 [VarDumper] Fix dumping continuations (nicolas-grekas)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.7 branch.

Discussion
----------

[VarDumper] Fix dumping continuations

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Dumping twice on the same destination shouldn't dump headers again.

Commits
-------

da96719 [VarDumper] Fix dumping continuations
  • Loading branch information
fabpot committed Aug 16, 2016
2 parents d62ac4d + da96719 commit adb7033
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
Expand Up @@ -211,8 +211,7 @@ public function getDumps($format, $maxDepthLimit = -1, $maxItemsPerDepth = -1)
// getLimitedClone is @deprecated, to be removed in 3.0
$dumper->dump($dump['data']->getLimitedClone($maxDepthLimit, $maxItemsPerDepth));
}
rewind($data);
$dump['data'] = stream_get_contents($data);
$dump['data'] = stream_get_contents($data, -1, 0);
ftruncate($data, 0);
rewind($data);
$dumps[] = $dump;
Expand Down
16 changes: 2 additions & 14 deletions src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php
Expand Up @@ -54,18 +54,6 @@ public function __construct($output = null, $charset = null)
$this->dumpId = 'sf-dump-'.mt_rand();
}

/**
* {@inheritdoc}
*/
public function setOutput($output)
{
if ($output !== $prev = parent::setOutput($output)) {
$this->headerIsDumped = false;
}

return $prev;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -111,7 +99,7 @@ public function dump(Data $data, $output = null)
*/
protected function getDumpHeader()
{
$this->headerIsDumped = true;
$this->headerIsDumped = null !== $this->outputStream ? $this->outputStream : $this->lineDumper;

if (null !== $this->dumpHeader) {
return $this->dumpHeader;
Expand Down Expand Up @@ -433,7 +421,7 @@ protected function dumpLine($depth, $endOfValue = false)
if (-1 === $this->lastDepth) {
$this->line = sprintf($this->dumpPrefix, $this->dumpId, $this->indentPad).$this->line;
}
if (!$this->headerIsDumped) {
if ($this->headerIsDumped !== (null !== $this->outputStream ? $this->outputStream : $this->lineDumper)) {
$this->line = $this->getDumpHeader().$this->line;
}

Expand Down
28 changes: 26 additions & 2 deletions src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php
Expand Up @@ -132,8 +132,7 @@ public function testCharset()
$data = $cloner->cloneVar($var);
$out = fopen('php://memory', 'r+b');
$dumper->dump($data, $out);
rewind($out);
$out = stream_get_contents($out);
$out = stream_get_contents($out, -1, 0);

$this->assertStringMatchesFormat(
<<<EOTXT
Expand All @@ -142,7 +141,32 @@ public function testCharset()
EOTXT
,
$out
);
}

public function testAppend()
{
$out = fopen('php://memory', 'r+b');

$dumper = new HtmlDumper();
$dumper->setDumpHeader('<foo></foo>');
$dumper->setDumpBoundaries('<bar>', '</bar>');
$cloner = new VarCloner();

$dumper->dump($cloner->cloneVar(123), $out);
$dumper->dump($cloner->cloneVar(456), $out);

$out = stream_get_contents($out, -1, 0);

$this->assertSame(<<<'EOTXT'
<foo></foo><bar><span class=sf-dump-num>123</span>
</bar>
<bar><span class=sf-dump-num>456</span>
</bar>
EOTXT
,
$out
);
}
Expand Down

0 comments on commit adb7033

Please sign in to comment.