*
* 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\VarCloner;
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->setDumpHeader('');
$dumper->setDumpBoundaries('', '');
$cloner = new VarCloner();
$cloner->addCasters(array(
':stream' => function ($res, $a) {
unset($a['uri'], $a['wrapper_data']);
return $a;
},
));
$data = $cloner->cloneVar($var);
ob_start();
$dumper->dump($data);
$out = ob_get_clean();
$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];
$res = (int) $var['res'];
$closure54 = '';
$r = defined('HHVM_VERSION') ? '' : '#%d';
if (PHP_VERSION_ID >= 50400) {
$closure54 = <<class: "Symfony\Component\VarDumper\Tests\HtmlDumperTest"
this: HtmlDumperTest {{$r} …}
EOTXT;
}
$this->assertStringMatchesFormat(
<<array:24 [
"number" => 1
0 => &1 null
"const" => 1.1
1 => true
2 => false
3 => NAN
4 => INF
5 => -INF
6 => {$intMax}
"str" => "déjà\\n"
7 => b"é\\x00"
"[]" => []
"res" => stream resource @{$res}
wrapper_type: "plainfile"
stream_type: "STDIO"
mode: "r"
unread_bytes: 0
seekable: true
timed_out: false
blocked: true
eof: false
options: []
}
"obj" => DumbFoo {#%d
+foo: "foo"
+"bar": "bar"
}
"closure" => Closure {{$r}{$closure54}
parameters: array:2 [
"\$a" => []
"&\$b" => array:2 [
"typeHint" => "PDO"
"default" => null
]
]
file: "{$var['file']}"
line: "{$var['line']} to {$var['line']}"
}
"line" => {$var['line']}
"nobj" => array:1 [
0 => &3 {#%d}
]
"recurs" => &4 array:1 [
0 => &4 array:1 [&4]
]
8 => &1 null
"sobj" => DumbFoo {#%d}
"snobj" => &3 {#%d}
"snobj2" => {#%d}
"file" => "{$var['file']}"
b"bin-key-é" => ""
]
EOTXT
,
$out
);
}
public function testCharset()
{
if (!extension_loaded('mbstring')) {
$this->markTestSkipped('This test requires mbstring.');
}
$var = mb_convert_encoding('Словарь', 'CP1251', 'UTF-8');
$dumper = new HtmlDumper('php://output', 'CP1251');
$dumper->setDumpHeader('');
$dumper->setDumpBoundaries('', '');
$cloner = new VarCloner();
$data = $cloner->cloneVar($var);
$out = fopen('php://memory', 'r+b');
$dumper->dump($data, $out);
rewind($out);
$out = stream_get_contents($out);
$this->assertStringMatchesFormat(
<<b"Словарь"
EOTXT
,
$out
);
}
}