diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php index 3de9a0e91e..35d51d3a4c 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php @@ -77,6 +77,7 @@ class DumpExtensionTest extends \PHPUnit_Framework_TestCase if ($debug) { $this->assertStringStartsWith('\n", - 'name' => 'DumpDataCollectorTest.php', - 'file' => __FILE__, - 'line' => $line, - 'fileExcerpt' => false, - ), - ); $dump = $collector->getDumps('html'); $this->assertTrue(isset($dump[0]['data'])); $dump[0]['data'] = preg_replace('/^.*?
 "
123\n
\n", + 'name' => 'DumpDataCollectorTest.php', + 'file' => __FILE__, + 'line' => $line, + 'fileExcerpt' => false, + ), + ); $this->assertSame($xDump, $dump); $this->assertStringStartsWith( diff --git a/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php b/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php index 6e740c9dcd..1f8d72892c 100644 --- a/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php +++ b/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php @@ -12,6 +12,7 @@ namespace Symfony\Component\VarDumper\Dumper; use Symfony\Component\VarDumper\Cloner\Cursor; +use Symfony\Component\VarDumper\Cloner\Data; /** * HtmlDumper dumps variables as HTML. @@ -23,8 +24,9 @@ class HtmlDumper extends CliDumper public static $defaultOutputStream = 'php://output'; protected $dumpHeader; - protected $dumpPrefix = '
';
+    protected $dumpPrefix = '
';
     protected $dumpSuffix = '
'; + protected $dumpId = 'sf-dump'; protected $colors = true; protected $headerIsDumped = false; protected $lastDepth = -1; @@ -82,6 +84,15 @@ class HtmlDumper extends CliDumper $this->dumpSuffix = $suffix; } + /** + * {@inheritdoc} + */ + public function dump(Data $data, $lineDumper = null) + { + $this->dumpId = 'sf-dump-'.mt_rand(); + parent::dump($data, $lineDumper); + } + /** * Dumps the HTML header. */ @@ -90,7 +101,7 @@ class HtmlDumper extends CliDumper $this->headerIsDumped = true; if (null !== $this->dumpHeader) { - return $this->dumpHeader; + return str_replace('%id%', $this->dumpId, $this->dumpHeader); } $line = <<<'EOHTML' @@ -129,7 +140,7 @@ Sfjs.dump.toggle = function(a) { }; '.$this->dumpHeader; + $this->dumpHeader = preg_replace('/\s+/', ' ', $line).''.$this->dumpHeader; + + return str_replace('%id%', $this->dumpId, $this->dumpHeader); } /** @@ -201,9 +214,9 @@ EOHTML; if ('ref' === $style) { $ref = substr($val, 1); if ('#' === $val[0]) { - return "$val"; + return "dumpId}-ref$ref\">$val"; } else { - return "$val"; + return "dumpId}-ref$ref\">$val"; } } @@ -236,14 +249,14 @@ EOHTML; } if (-1 === $this->lastDepth) { - $this->line = $this->dumpPrefix.$this->line; + $this->line = str_replace('%id%', $this->dumpId, $this->dumpPrefix).$this->line; } if (!$this->headerIsDumped) { $this->line = $this->getDumpHeader().$this->line; } if (-1 === $depth) { - $this->line .= $this->dumpSuffix; + $this->line .= str_replace('%id%', $this->dumpId, $this->dumpSuffix); parent::dumpLine(0); } $this->lastDepth = $depth; diff --git a/src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php b/src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php index e93ff236c2..82c41b4666 100644 --- a/src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php +++ b/src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php @@ -33,7 +33,7 @@ class HtmlDumperTest extends \PHPUnit_Framework_TestCase unset($a['uri']); return $a; - } + }, )); $data = $cloner->cloneVar($var); @@ -44,12 +44,14 @@ class HtmlDumperTest extends \PHPUnit_Framework_TestCase $out = preg_replace('/[ \t]+$/m', '', $out); $var['file'] = htmlspecialchars($var['file'], ENT_QUOTES, 'UTF-8'); $intMax = PHP_INT_MAX; + preg_match('/sf-dump-(\\d{2,})/', $out, $matches); + $dumpId = $matches[1]; $this->assertSame( <<array:25 [ "number" => 1 - 0 => null #1 + 0 => null #1 "const" => 1.1 1 => true 2 => false @@ -72,7 +74,7 @@ class HtmlDumperTest extends \PHPUnit_Framework_TestCase options: [] } 8 => resource:Unknown {} - "obj" => DumbFoo { #2 + "obj" => DumbFoo { #2 foo: "foo" "bar": "bar" } @@ -90,15 +92,15 @@ class HtmlDumperTest extends \PHPUnit_Framework_TestCase } "line" => {$var['line']} "nobj" => array:1 [ - 0 => {} #3 + 0 => {} #3 ] - "recurs" => array:1 [ #4 - 0 => &4 array:1 [@4] + "recurs" => array:1 [ #4 + 0 => &4 array:1 [@4] ] - 9 => &1 null - "sobj" => DumbFoo {@2} - "snobj" => &3 {@3} - "snobj2" => {@3} + 9 => &1 null + "sobj" => DumbFoo {@2} + "snobj" => &3 {@3} + "snobj2" => {@3} "file" => "{$var['file']}" b"bin-key-é" => "" ]