*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\VarDumper\Tests;
use Symfony\Component\VarDumper\Cloner\PhpCloner;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
/**
* @author Nicolas Grekas
*/
class HtmlDumperTest extends \PHPUnit_Framework_TestCase
{
public function testGet()
{
require __DIR__.'/Fixtures/dumb-var.php';
$dumper = new HtmlDumper('php://output');
$dumper->setColors(false);
$dumper->setDumpHeader('');
$dumper->setDumpBoundaries('', '');
$cloner = new PhpCloner();
$cloner->addCasters(array(
':stream' => function ($res, $a) {
unset($a['uri']);
return $a;
},
));
$data = $cloner->cloneVar($var);
ob_start();
$dumper->dump($data);
$out = ob_get_clean();
$closureLabel = PHP_VERSION_ID >= 50400 ? 'public method' : 'function';
$out = preg_replace('/[ \t]+$/m', '', $out);
$var['file'] = htmlspecialchars($var['file'], ENT_QUOTES, 'UTF-8');
$intMax = PHP_INT_MAX;
preg_match('/sf-dump-\d+/', $out, $dumpId);
$dumpId = $dumpId[0];
$this->assertSame(
<<array:25 [
"number" => 1
0 => null #1
"const" => 1.1
1 => true
2 => false
3 => NAN
4 => INF
5 => -INF
6 => {$intMax}
"str" => "déjà"
7 => b"é"
"[]" => []
"res" => :stream {
wrapper_type: "plainfile"
stream_type: "STDIO"
mode: "r"
unread_bytes: 0
seekable: true
timed_out: false
blocked: true
eof: false
options: []
}
8 => :Unknown {}
"obj" => DumbFoo { #2
foo: "foo"
"bar": "bar"
}
"closure" => Closure {
reflection: """
Closure [ <user> {$closureLabel} Symfony\Component\VarDumper\Tests\Fixture\{closure} ] {
@@ {$var['file']} {$var['line']} - {$var['line']}
- Parameters [2] {
Parameter #0 [ <required> \$a ]
Parameter #1 [ <optional> PDO or NULL &\$b = NULL ]
}
}
"""
}
"line" => {$var['line']}
"nobj" => array:1 [
0 => {} #3
]
"recurs" => array:1 [ #4
0 => &4 array:1 [@4]
]
9 => &1 null
"sobj" => DumbFoo {@2}
"snobj" => &3 {@3}
"snobj2" => {@3}
"file" => "{$var['file']}"
b"bin-key-é" => ""
]
EOTXT
,
$out
);
}
}