Updating Media dependent modules to versions compatible with core Media.
[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 use Symfony\Component\VarDumper\Dumper\CliDumper;
20
21 /**
22  * @author Nicolas Grekas <p@tchwork.com>
23  */
24 class DumpDataCollectorTest extends TestCase
25 {
26     public function testDump()
27     {
28         $data = new Data(array(array(123)));
29
30         $collector = new DumpDataCollector();
31
32         $this->assertSame('dump', $collector->getName());
33
34         $collector->dump($data);
35         $line = __LINE__ - 1;
36         $this->assertSame(1, $collector->getDumpsCount());
37
38         $dump = $collector->getDumps('html');
39         $this->assertArrayHasKey('data', $dump[0]);
40         $dump[0]['data'] = preg_replace('/^.*?<pre/', '<pre', $dump[0]['data']);
41         $dump[0]['data'] = preg_replace('/sf-dump-\d+/', 'sf-dump', $dump[0]['data']);
42
43         $xDump = array(
44             array(
45                 '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",
46                 'name' => 'DumpDataCollectorTest.php',
47                 'file' => __FILE__,
48                 'line' => $line,
49                 'fileExcerpt' => false,
50             ),
51         );
52         $this->assertEquals($xDump, $dump);
53
54         $this->assertStringMatchesFormat('a:3:{i:0;a:5:{s:4:"data";%c:39:"Symfony\Component\VarDumper\Cloner\Data":%a', $collector->serialize());
55         $this->assertSame(0, $collector->getDumpsCount());
56         $this->assertSame('a:2:{i:0;b:0;i:1;s:5:"UTF-8";}', $collector->serialize());
57     }
58
59     public function testCollectDefault()
60     {
61         $data = new Data(array(array(123)));
62
63         $collector = new DumpDataCollector();
64
65         $collector->dump($data);
66         $line = __LINE__ - 1;
67
68         ob_start();
69         $collector->collect(new Request(), new Response());
70         $output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean());
71
72         $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output);
73         $this->assertSame(1, $collector->getDumpsCount());
74         $collector->serialize();
75     }
76
77     public function testCollectHtml()
78     {
79         $data = new Data(array(array(123)));
80
81         $collector = new DumpDataCollector(null, 'test://%f:%l');
82
83         $collector->dump($data);
84         $line = __LINE__ - 1;
85         $file = __FILE__;
86         $xOutput = <<<EOTXT
87 <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>:
88 <span class=sf-dump-num>123</span>
89 </pre>
90 EOTXT;
91
92         ob_start();
93         $response = new Response();
94         $response->headers->set('Content-Type', 'text/html');
95         $collector->collect(new Request(), $response);
96         $output = ob_get_clean();
97         $output = preg_replace('#<(script|style).*?</\1>#s', '', $output);
98         $output = preg_replace('/sf-dump-\d+/', 'sf-dump', $output);
99
100         $this->assertSame($xOutput, trim($output));
101         $this->assertSame(1, $collector->getDumpsCount());
102         $collector->serialize();
103     }
104
105     public function testFlush()
106     {
107         $data = new Data(array(array(456)));
108         $collector = new DumpDataCollector();
109         $collector->dump($data);
110         $line = __LINE__ - 1;
111
112         ob_start();
113         $collector->__destruct();
114         $output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean());
115         $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output);
116     }
117
118     public function testFlushNothingWhenDataDumperIsProvided()
119     {
120         $data = new Data(array(array(456)));
121         $dumper = new CliDumper('php://output');
122         $collector = new DumpDataCollector(null, null, null, null, $dumper);
123
124         ob_start();
125         $collector->dump($data);
126         $line = __LINE__ - 1;
127         $output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean());
128         if (\PHP_VERSION_ID >= 50400) {
129             $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output);
130         } else {
131             $this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", $output);
132         }
133
134         ob_start();
135         $collector->__destruct();
136         $this->assertEmpty(ob_get_clean());
137     }
138 }