4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Tests\DataCollector;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
16 use Symfony\Component\HttpFoundation\Request;
17 use Symfony\Component\HttpFoundation\Response;
18 use Symfony\Component\VarDumper\Cloner\Data;
21 * @author Nicolas Grekas <p@tchwork.com>
23 class DumpDataCollectorTest extends TestCase
25 public function testDump()
27 $data = new Data(array(array(123)));
29 $collector = new DumpDataCollector();
31 $this->assertSame('dump', $collector->getName());
33 $collector->dump($data);
35 $this->assertSame(1, $collector->getDumpsCount());
37 $dump = $collector->getDumps('html');
38 $this->assertTrue(isset($dump[0]['data']));
39 $dump[0]['data'] = preg_replace('/^.*?<pre/', '<pre', $dump[0]['data']);
40 $dump[0]['data'] = preg_replace('/sf-dump-\d+/', 'sf-dump', $dump[0]['data']);
44 'data' => "<pre class=sf-dump id=sf-dump data-indent-pad=\" \"><span class=sf-dump-num>123</span>\n</pre><script>Sfdump(\"sf-dump\")</script>\n",
45 'name' => 'DumpDataCollectorTest.php',
48 'fileExcerpt' => false,
51 $this->assertEquals($xDump, $dump);
53 $this->assertStringMatchesFormat('a:3:{i:0;a:5:{s:4:"data";%c:39:"Symfony\Component\VarDumper\Cloner\Data":%a', $collector->serialize());
54 $this->assertSame(0, $collector->getDumpsCount());
55 $this->assertSame('a:2:{i:0;b:0;i:1;s:5:"UTF-8";}', $collector->serialize());
58 public function testCollectDefault()
60 $data = new Data(array(array(123)));
62 $collector = new DumpDataCollector();
64 $collector->dump($data);
68 $collector->collect(new Request(), new Response());
69 $output = ob_get_clean();
71 $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output);
72 $this->assertSame(1, $collector->getDumpsCount());
73 $collector->serialize();
76 public function testCollectHtml()
78 $data = new Data(array(array(123)));
80 $collector = new DumpDataCollector(null, 'test://%f:%l');
82 $collector->dump($data);
86 <pre class=sf-dump id=sf-dump data-indent-pad=" "><a href="test://{$file}:{$line}" title="{$file}"><span class=sf-dump-meta>DumpDataCollectorTest.php</span></a> on line <span class=sf-dump-meta>{$line}</span>:
87 <span class=sf-dump-num>123</span>
92 $response = new Response();
93 $response->headers->set('Content-Type', 'text/html');
94 $collector->collect(new Request(), $response);
95 $output = ob_get_clean();
96 $output = preg_replace('#<(script|style).*?</\1>#s', '', $output);
97 $output = preg_replace('/sf-dump-\d+/', 'sf-dump', $output);
99 $this->assertSame($xOutput, trim($output));
100 $this->assertSame(1, $collector->getDumpsCount());
101 $collector->serialize();
104 public function testFlush()
106 $data = new Data(array(array(456)));
107 $collector = new DumpDataCollector();
108 $collector->dump($data);
109 $line = __LINE__ - 1;
112 $collector->__destruct();
113 $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean());