Skip to content

Commit faa3ff8

Browse files
[VarDumper] tests for HtmlDumper
1 parent e0d367d commit faa3ff8

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

Tests/HtmlDumperTest.php

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\VarDumper\Tests;
13+
14+
use Symfony\Component\VarDumper\Cloner\PhpCloner;
15+
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
16+
17+
/**
18+
* @author Nicolas Grekas <[email protected]>
19+
*/
20+
class HtmlDumperTest extends \PHPUnit_Framework_TestCase
21+
{
22+
public function testGet()
23+
{
24+
require __DIR__.'/Fixtures/dumb-var.php';
25+
26+
$dumper = new HtmlDumper('php://output');
27+
$dumper->setColors(false);
28+
$cloner = new PhpCloner();
29+
$data = $cloner->cloneVar($var);
30+
31+
ob_start();
32+
$dumper->dump($data);
33+
$out = ob_get_clean();
34+
$closureLabel = PHP_VERSION_ID >= 50400 ? 'public method' : 'function';
35+
$out = preg_replace('/[ \t]+$/m', '', $out);
36+
$var['file'] = htmlspecialchars($var['file'], ENT_QUOTES, 'UTF-8');
37+
38+
$this->assertSame(
39+
<<<EOTXT
40+
<!DOCTYPE html><style>
41+
a.sf-var-debug-ref {color:#444444}
42+
span.sf-var-debug-num {font-weight:bold;color:#0087FF}
43+
span.sf-var-debug-const {font-weight:bold;color:#0087FF}
44+
span.sf-var-debug-str {font-weight:bold;color:#00D7FF}
45+
span.sf-var-debug-cchr {font-style: italic}
46+
span.sf-var-debug-note {color:#D7AF00}
47+
span.sf-var-debug-ref {color:#444444}
48+
span.sf-var-debug-public {color:#008700}
49+
span.sf-var-debug-protected {color:#D75F00}
50+
span.sf-var-debug-private {color:#D70000}
51+
span.sf-var-debug-meta {color:#005FFF}
52+
</style>
53+
54+
<pre class=sf-var-debug style=white-space:pre><span class=sf-var-debug-0><span class=sf-var-debug-note>array:25</span> [
55+
<span class=sf-var-debug-1>"<span class=sf-var-debug-meta>number</span>" => <span class=sf-var-debug-const>1</span>
56+
<span class=sf-var-debug-meta>0</span> => <span class=sf-var-debug-const>null</span> <a class=sf-var-debug-ref name="sf-var-debug-ref1">#1</a>
57+
"<span class=sf-var-debug-meta>const</span>" => <span class=sf-var-debug-num>1.1</span>
58+
<span class=sf-var-debug-meta>1</span> => <span class=sf-var-debug-const>true</span>
59+
<span class=sf-var-debug-meta>2</span> => <span class=sf-var-debug-const>false</span>
60+
<span class=sf-var-debug-meta>3</span> => <span class=sf-var-debug-num>NAN</span>
61+
<span class=sf-var-debug-meta>4</span> => <span class=sf-var-debug-num>INF</span>
62+
<span class=sf-var-debug-meta>5</span> => <span class=sf-var-debug-num>-INF</span>
63+
<span class=sf-var-debug-meta>6</span> => <span class=sf-var-debug-const>9223372036854775807</span>
64+
"<span class=sf-var-debug-meta>str</span>" => "<span class=sf-var-debug-str>déjà</span>"
65+
<span class=sf-var-debug-meta>7</span> => b"<span class=sf-var-debug-str>é</span>"
66+
"<span class=sf-var-debug-meta>[]</span>" => []
67+
"<span class=sf-var-debug-meta>res</span>" => resource:<span class=sf-var-debug-note>stream</span> {
68+
<span class=sf-var-debug-2><span class=sf-var-debug-meta>wrapper_type</span>: "<span class=sf-var-debug-str>plainfile</span>"
69+
<span class=sf-var-debug-meta>stream_type</span>: "<span class=sf-var-debug-str>dir</span>"
70+
<span class=sf-var-debug-meta>mode</span>: "<span class=sf-var-debug-str>r</span>"
71+
<span class=sf-var-debug-meta>unread_bytes</span>: <span class=sf-var-debug-const>0</span>
72+
<span class=sf-var-debug-meta>seekable</span>: <span class=sf-var-debug-const>true</span>
73+
<span class=sf-var-debug-meta>timed_out</span>: <span class=sf-var-debug-const>false</span>
74+
<span class=sf-var-debug-meta>blocked</span>: <span class=sf-var-debug-const>true</span>
75+
<span class=sf-var-debug-meta>eof</span>: <span class=sf-var-debug-const>false</span>
76+
<span class=sf-var-debug-meta>options</span>: []
77+
</span>}
78+
<span class=sf-var-debug-meta>8</span> => resource:<span class=sf-var-debug-note>Unknown</span> {}
79+
"<span class=sf-var-debug-meta>obj</span>" => <span class=sf-var-debug-note>Symfony\Component\VarDumper\Tests\Fixture\DumbFoo</span> { <a class=sf-var-debug-ref name="sf-var-debug-ref2">#2</a>
80+
<span class=sf-var-debug-2><span class=sf-var-debug-public>foo</span>: "<span class=sf-var-debug-str>foo</span>"
81+
"<span class=sf-var-debug-public>bar</span>": "<span class=sf-var-debug-str>bar</span>"
82+
</span>}
83+
"<span class=sf-var-debug-meta>closure</span>" => <span class=sf-var-debug-note>Closure</span> {
84+
<span class=sf-var-debug-2><span class=sf-var-debug-meta>reflection</span>: """
85+
<span class=sf-var-debug-str>Closure [ &lt;user&gt; {$closureLabel} Symfony\Component\VarDumper\Tests\Fixture\{closure} ] {</span>
86+
<span class=sf-var-debug-str> @@ {$var['file']} {$var['line']} - {$var['line']}</span>
87+
88+
<span class=sf-var-debug-str> - Parameters [2] {</span>
89+
<span class=sf-var-debug-str> Parameter #0 [ &lt;required&gt; \$a ]</span>
90+
<span class=sf-var-debug-str> Parameter #1 [ &lt;optional&gt; PDO or NULL &amp;\$b = NULL ]</span>
91+
<span class=sf-var-debug-str> }</span>
92+
<span class=sf-var-debug-str>}</span>
93+
"""
94+
</span>}
95+
"<span class=sf-var-debug-meta>line</span>" => <span class=sf-var-debug-const>{$var['line']}</span>
96+
"<span class=sf-var-debug-meta>nobj</span>" => <span class=sf-var-debug-note>array:1</span> [
97+
<span class=sf-var-debug-2><span class=sf-var-debug-meta>0</span> => {} <a class=sf-var-debug-ref name="sf-var-debug-ref3">#3</a>
98+
</span>]
99+
"<span class=sf-var-debug-meta>recurs</span>" => <span class=sf-var-debug-note>array:1</span> [ <a class=sf-var-debug-ref name="sf-var-debug-ref4">#4</a>
100+
<span class=sf-var-debug-2><span class=sf-var-debug-meta>0</span> => <span class=sf-var-debug-note>array:1</span> [<a class=sf-var-debug-ref href="#sf-var-debug-ref4">&4</a>]
101+
</span>]
102+
<span class=sf-var-debug-meta>9</span> => <span class=sf-var-debug-const>null</span> <a class=sf-var-debug-ref href="#sf-var-debug-ref1">&1</a>
103+
"<span class=sf-var-debug-meta>sobj</span>" => <span class=sf-var-debug-note>Symfony\Component\VarDumper\Tests\Fixture\DumbFoo</span> {<a class=sf-var-debug-ref href="#sf-var-debug-ref2">@2</a>}
104+
"<span class=sf-var-debug-meta>snobj</span>" => {<a class=sf-var-debug-ref href="#sf-var-debug-ref3">&3</a>}
105+
"<span class=sf-var-debug-meta>snobj2</span>" => {<a class=sf-var-debug-ref href="#sf-var-debug-ref3">@3</a>}
106+
"<span class=sf-var-debug-meta>file</span>" => "<span class=sf-var-debug-str>{$var['file']}</span>"
107+
b"<span class=sf-var-debug-meta>bin-key-é</span>" => ""
108+
</span>]
109+
</pre>
110+
111+
EOTXT
112+
,
113+
114+
$out
115+
);
116+
}
117+
}

0 commit comments

Comments
 (0)