Yaffs site version 1.1
[yaffs-website] / vendor / symfony / http-kernel / Tests / DataCollector / DumpDataCollectorTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\HttpKernel\Tests\DataCollector;
13
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;
19
20 /**
21  * @author Nicolas Grekas <p@tchwork.com>
22  */
23 class DumpDataCollectorTest extends TestCase
24 {
25     public function testDump()
26     {
27         $data = new Data(array(array(123)));
28
29         $collector = new DumpDataCollector();
30
31         $this->assertSame('dump', $collector->getName());
32
33         $collector->dump($data);
34         $line = __LINE__ - 1;
35         $this->assertSame(1, $collector->getDumpsCount());
36
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']);
41
42         $xDump = array(
43             array(
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',
46                 'file' => __FILE__,
47                 'line' => $line,
48                 'fileExcerpt' => false,
49             ),
50         );
51         $this->assertSame($xDump, $dump);
52
53         $this->assertStringMatchesFormat('a:3:{i:0;a:5:{s:4:"data";O: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());
56     }
57
58     public function testCollectDefault()
59     {
60         $data = new Data(array(array(123)));
61
62         $collector = new DumpDataCollector();
63
64         $collector->dump($data);
65         $line = __LINE__ - 1;
66
67         ob_start();
68         $collector->collect(new Request(), new Response());
69         $output = ob_get_clean();
70
71         if (\PHP_VERSION_ID >= 50400) {
72             $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output);
73         } else {
74             $this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n123\n", $output);
75         }
76         $this->assertSame(1, $collector->getDumpsCount());
77         $collector->serialize();
78     }
79
80     public function testCollectHtml()
81     {
82         $data = new Data(array(array(123)));
83
84         $collector = new DumpDataCollector(null, 'test://%f:%l');
85
86         $collector->dump($data);
87         $line = __LINE__ - 1;
88         $file = __FILE__;
89         if (\PHP_VERSION_ID >= 50400) {
90             $xOutput = <<<EOTXT
91 <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>:
92 <span class=sf-dump-num>123</span>
93 </pre>
94 EOTXT;
95         } else {
96             $len = strlen("DumpDataCollectorTest.php on line {$line}:");
97             $xOutput = <<<EOTXT
98 <pre class=sf-dump id=sf-dump data-indent-pad="  ">"<span class=sf-dump-str title="{$len} characters">DumpDataCollectorTest.php on line {$line}:</span>"
99 </pre>
100 <pre class=sf-dump id=sf-dump data-indent-pad="  "><span class=sf-dump-num>123</span>
101 </pre>
102 EOTXT;
103         }
104
105         ob_start();
106         $response = new Response();
107         $response->headers->set('Content-Type', 'text/html');
108         $collector->collect(new Request(), $response);
109         $output = ob_get_clean();
110         $output = preg_replace('#<(script|style).*?</\1>#s', '', $output);
111         $output = preg_replace('/sf-dump-\d+/', 'sf-dump', $output);
112
113         $this->assertSame($xOutput, trim($output));
114         $this->assertSame(1, $collector->getDumpsCount());
115         $collector->serialize();
116     }
117
118     public function testFlush()
119     {
120         $data = new Data(array(array(456)));
121         $collector = new DumpDataCollector();
122         $collector->dump($data);
123         $line = __LINE__ - 1;
124
125         ob_start();
126         $collector->__destruct();
127         if (\PHP_VERSION_ID >= 50400) {
128             $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean());
129         } else {
130             $this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", ob_get_clean());
131         }
132     }
133 }