Update of var_dumper package 3.0 -> 3.2

This commit is contained in:
lmarcouiller
2021-07-29 10:20:01 +02:00
parent 7836651f84
commit b0133224d8
51 changed files with 2393 additions and 585 deletions

View File

@@ -11,14 +11,17 @@
namespace Symfony\Component\VarDumper\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
/**
* @author Nicolas Grekas <p@tchwork.com>
*/
class CliDumperTest extends \PHPUnit_Framework_TestCase
class CliDumperTest extends TestCase
{
use VarDumperTestTrait;
@@ -62,15 +65,12 @@ array:24 [
7 => b"é\\x00"
"[]" => []
"res" => stream resource {@{$res}
wrapper_type: "plainfile"
%A wrapper_type: "plainfile"
stream_type: "STDIO"
mode: "r"
unread_bytes: 0
seekable: true
timed_out: false
blocked: true
eof: false
options: []
%A options: []
}
"obj" => Symfony\Component\VarDumper\Tests\Fixture\DumbFoo {#%d
+foo: "foo"
@@ -118,7 +118,7 @@ EOTXT
$var = xml_parser_create();
$this->assertDumpMatchesFormat(
<<<EOTXT
<<<'EOTXT'
xml resource {
current_byte_index: %i
current_column_number: %i
@@ -131,6 +131,72 @@ EOTXT
);
}
public function testJsonCast()
{
$var = (array) json_decode('{"0":{},"1":null}');
foreach ($var as &$v) {
}
$var[] = &$v;
$var[''] = 2;
if (\PHP_VERSION_ID >= 70200) {
$this->assertDumpMatchesFormat(
<<<'EOTXT'
array:4 [
0 => {}
1 => &1 null
2 => &1 null
"" => 2
]
EOTXT
,
$var
);
} else {
$this->assertDumpMatchesFormat(
<<<'EOTXT'
array:4 [
"0" => {}
"1" => &1 null
0 => &1 null
"" => 2
]
EOTXT
,
$var
);
}
}
public function testObjectCast()
{
$var = (object) array(1 => 1);
$var->{1} = 2;
if (\PHP_VERSION_ID >= 70200) {
$this->assertDumpMatchesFormat(
<<<'EOTXT'
{
+"1": 2
}
EOTXT
,
$var
);
} else {
$this->assertDumpMatchesFormat(
<<<'EOTXT'
{
+1: 1
+"1": 2
}
EOTXT
,
$var
);
}
}
public function testClosedResource()
{
if (defined('HHVM_VERSION') && HHVM_VERSION_ID < 30600) {
@@ -152,7 +218,7 @@ EOTXT
$this->assertStringMatchesFormat(
<<<EOTXT
Unknown resource @{$res}
Closed resource @{$res}
EOTXT
,
@@ -160,12 +226,47 @@ EOTXT
);
}
public function testFlags()
{
putenv('DUMP_LIGHT_ARRAY=1');
putenv('DUMP_STRING_LENGTH=1');
$var = array(
range(1, 3),
array('foo', 2 => 'bar'),
);
$this->assertDumpEquals(
<<<EOTXT
[
[
1
2
3
]
[
0 => (3) "foo"
2 => (3) "bar"
]
]
EOTXT
,
$var
);
putenv('DUMP_LIGHT_ARRAY=');
putenv('DUMP_STRING_LENGTH=');
}
/**
* @requires function Twig\Template::getSourceContext
*/
public function testThrowingCaster()
{
$out = fopen('php://memory', 'r+b');
require_once __DIR__.'/Fixtures/Twig.php';
$twig = new \__TwigTemplate_VarDumperFixture_u75a09(new \Twig_Environment(new \Twig_Loader_Filesystem()));
$twig = new \__TwigTemplate_VarDumperFixture_u75a09(new Environment(new FilesystemLoader()));
$dumper = new CliDumper();
$dumper->setColors(false);
@@ -181,96 +282,56 @@ EOTXT
':stream' => eval('return function () use ($twig) {
try {
$twig->render(array());
} catch (\Twig_Error_Runtime $e) {
} catch (\Twig\Error\RuntimeError $e) {
throw $e->getPrevious();
}
};'),
));
$line = __LINE__ - 2;
$ref = (int) $out;
$data = $cloner->cloneVar($out);
$dumper->dump($data, $out);
rewind($out);
$out = stream_get_contents($out);
if (method_exists($twig, 'getSource')) {
$twig = <<<EOTXT
foo.twig:2: """
foo bar\\n
twig source\\n
\\n
"""
EOTXT;
} else {
$twig = '';
}
$out = stream_get_contents($out, -1, 0);
$r = defined('HHVM_VERSION') ? '' : '#%d';
$this->assertStringMatchesFormat(
<<<EOTXT
stream resource {@{$ref}
wrapper_type: "PHP"
⚠: Symfony\Component\VarDumper\Exception\ThrowingCasterException {{$r}
#message: "Unexpected Exception thrown from a caster: Foobar"
-trace: {
%sTwig.php:2: {
: foo bar
: twig source
:
}
%sTemplate.php:%d: {
: try {
: \$this->doDisplay(\$context, \$blocks);
: } catch (Twig%sError \$e) {
}
%sTemplate.php:%d: {
: {
: \$this->displayWithErrorHandling(\$this->env->mergeGlobals(\$context), array_merge(\$this->blocks, \$blocks));
: }
}
%sTemplate.php:%d: {
: try {
: \$this->display(\$context);
: } catch (%s \$e) {
}
%sCliDumperTest.php:%d: {
%A
}
}
}
%Awrapper_type: "PHP"
stream_type: "MEMORY"
mode: "%s+b"
unread_bytes: 0
seekable: true
uri: "php://memory"
timed_out: false
blocked: true
eof: false
options: []
⚠: Symfony\Component\VarDumper\Exception\ThrowingCasterException {{$r}
#message: "Unexpected Exception thrown from a caster: Foobar"
-trace: {
%d. __TwigTemplate_VarDumperFixture_u75a09->doDisplay() ==> new Exception(): {
src: {
%sTwig.php:19: """
// line 2\\n
throw new \Exception('Foobar');\\n
}\\n
"""
{$twig} }
}
%d. Twig_Template->displayWithErrorHandling() ==> __TwigTemplate_VarDumperFixture_u75a09->doDisplay(): {
src: {
%sTemplate.php:%d: """
try {\\n
\$this->doDisplay(\$context, \$blocks);\\n
} catch (Twig_Error \$e) {\\n
"""
}
}
%d. Twig_Template->display() ==> Twig_Template->displayWithErrorHandling(): {
src: {
%sTemplate.php:%d: """
{\\n
\$this->displayWithErrorHandling(\$this->env->mergeGlobals(\$context), array_merge(\$this->blocks, \$blocks));\\n
}\\n
"""
}
}
%d. Twig_Template->render() ==> Twig_Template->display(): {
src: {
%sTemplate.php:%d: """
try {\\n
\$this->display(\$context);\\n
} catch (Exception \$e) {\\n
"""
}
}
%d. %slosure%s() ==> Twig_Template->render(): {
src: {
%sCliDumperTest.php:{$line}: """
}\\n
};'),\\n
));\\n
"""
}
}
}
}
%Aoptions: []
}
EOTXT
@@ -288,11 +349,8 @@ EOTXT
$dumper->setColors(false);
$cloner = new VarCloner();
$out = fopen('php://memory', 'r+b');
$data = $cloner->cloneVar($var);
$dumper->dump($data, $out);
rewind($out);
$out = stream_get_contents($out);
$out = $dumper->dump($data, true);
$r = defined('HHVM_VERSION') ? '' : '#%d';
$this->assertStringMatchesFormat(
@@ -318,7 +376,7 @@ EOTXT
$var = $this->getSpecialVars();
$this->assertDumpEquals(
<<<EOTXT
<<<'EOTXT'
array:3 [
0 => array:1 [
0 => &1 array:1 [
@@ -364,7 +422,7 @@ EOTXT
$dumper->dump($data);
$this->assertSame(
<<<EOTXT
<<<'EOTXT'
array:2 [
1 => array:1 [
"GLOBALS" => &1 array:1 [
@@ -386,7 +444,7 @@ EOTXT
*/
public function testBuggyRefs()
{
if (PHP_VERSION_ID >= 50600) {
if (\PHP_VERSION_ID >= 50600) {
$this->markTestSkipped('PHP 5.6 fixed refs counting');
}
@@ -406,7 +464,7 @@ EOTXT
});
$this->assertSame(
<<<EOTXT
<<<'EOTXT'
array:1 [
0 => array:1 [
0 => array:1 [
@@ -421,6 +479,21 @@ EOTXT
);
}
public function testIncompleteClass()
{
$unserializeCallbackHandler = ini_set('unserialize_callback_func', null);
$var = unserialize('O:8:"Foo\Buzz":0:{}');
ini_set('unserialize_callback_func', $unserializeCallbackHandler);
$this->assertDumpMatchesFormat(
<<<EOTXT
__PHP_Incomplete_Class(Foo\Buzz) {}
EOTXT
,
$var
);
}
private function getSpecialVars()
{
foreach (array_keys($GLOBALS) as $var) {