[VarDumper] Fix dumping continuations

This commit is contained in:
Nicolas Grekas 2016-08-16 10:16:14 +02:00
parent 2345ec1210
commit da96719b94
3 changed files with 29 additions and 18 deletions

View File

@ -211,8 +211,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
// getLimitedClone is @deprecated, to be removed in 3.0 // getLimitedClone is @deprecated, to be removed in 3.0
$dumper->dump($dump['data']->getLimitedClone($maxDepthLimit, $maxItemsPerDepth)); $dumper->dump($dump['data']->getLimitedClone($maxDepthLimit, $maxItemsPerDepth));
} }
rewind($data); $dump['data'] = stream_get_contents($data, -1, 0);
$dump['data'] = stream_get_contents($data);
ftruncate($data, 0); ftruncate($data, 0);
rewind($data); rewind($data);
$dumps[] = $dump; $dumps[] = $dump;

View File

@ -54,18 +54,6 @@ class HtmlDumper extends CliDumper
$this->dumpId = 'sf-dump-'.mt_rand(); $this->dumpId = 'sf-dump-'.mt_rand();
} }
/**
* {@inheritdoc}
*/
public function setOutput($output)
{
if ($output !== $prev = parent::setOutput($output)) {
$this->headerIsDumped = false;
}
return $prev;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -111,7 +99,7 @@ class HtmlDumper extends CliDumper
*/ */
protected function getDumpHeader() protected function getDumpHeader()
{ {
$this->headerIsDumped = true; $this->headerIsDumped = null !== $this->outputStream ? $this->outputStream : $this->lineDumper;
if (null !== $this->dumpHeader) { if (null !== $this->dumpHeader) {
return $this->dumpHeader; return $this->dumpHeader;
@ -433,7 +421,7 @@ EOHTML;
if (-1 === $this->lastDepth) { if (-1 === $this->lastDepth) {
$this->line = sprintf($this->dumpPrefix, $this->dumpId, $this->indentPad).$this->line; $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; $this->line = $this->getDumpHeader().$this->line;
} }

View File

@ -132,8 +132,7 @@ EOTXT
$data = $cloner->cloneVar($var); $data = $cloner->cloneVar($var);
$out = fopen('php://memory', 'r+b'); $out = fopen('php://memory', 'r+b');
$dumper->dump($data, $out); $dumper->dump($data, $out);
rewind($out); $out = stream_get_contents($out, -1, 0);
$out = stream_get_contents($out);
$this->assertStringMatchesFormat( $this->assertStringMatchesFormat(
<<<EOTXT <<<EOTXT
@ -142,7 +141,32 @@ EOTXT
EOTXT 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 $out
); );
} }