Skip to content

Commit e0d367d

Browse files
[VarDumper] tests for CliDumper
1 parent 9aef65b commit e0d367d

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

Tests/CliDumperTest.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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\CliDumper;
16+
17+
/**
18+
* @author Nicolas Grekas <[email protected]>
19+
*/
20+
class CliDumperTest extends \PHPUnit_Framework_TestCase
21+
{
22+
public function testGet()
23+
{
24+
require __DIR__.'/Fixtures/dumb-var.php';
25+
26+
$dumper = new CliDumper('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+
37+
$this->assertSame(
38+
<<<EOTXT
39+
array:25 [
40+
"number" => 1
41+
0 => null #1
42+
"const" => 1.1
43+
1 => true
44+
2 => false
45+
3 => NAN
46+
4 => INF
47+
5 => -INF
48+
6 => 9223372036854775807
49+
"str" => "déjà"
50+
7 => b"é"
51+
"[]" => []
52+
"res" => resource:stream {
53+
wrapper_type: "plainfile"
54+
stream_type: "dir"
55+
mode: "r"
56+
unread_bytes: 0
57+
seekable: true
58+
timed_out: false
59+
blocked: true
60+
eof: false
61+
options: []
62+
}
63+
8 => resource:Unknown {}
64+
"obj" => Symfony\Component\VarDumper\Tests\Fixture\DumbFoo { #2
65+
foo: "foo"
66+
"bar": "bar"
67+
}
68+
"closure" => Closure {
69+
reflection: """
70+
Closure [ <user> {$closureLabel} Symfony\Component\VarDumper\Tests\Fixture\{closure} ] {
71+
@@ {$var['file']} {$var['line']} - {$var['line']}
72+
73+
- Parameters [2] {
74+
Parameter #0 [ <required> \$a ]
75+
Parameter #1 [ <optional> PDO or NULL &\$b = NULL ]
76+
}
77+
}
78+
"""
79+
}
80+
"line" => {$var['line']}
81+
"nobj" => array:1 [
82+
0 => {} #3
83+
]
84+
"recurs" => array:1 [ #4
85+
0 => array:1 [&4]
86+
]
87+
9 => null &1
88+
"sobj" => Symfony\Component\VarDumper\Tests\Fixture\DumbFoo {@2}
89+
"snobj" => {&3}
90+
"snobj2" => {@3}
91+
"file" => "{$var['file']}"
92+
b"bin-key-é" => ""
93+
]
94+
95+
EOTXT
96+
,
97+
98+
$out
99+
);
100+
}
101+
}

0 commit comments

Comments
 (0)