[VarDumper] Add VarDumperTestCase and related trait
This commit is contained in:
parent
d23b38ae7f
commit
57da9aeadf
45
src/Symfony/Component/VarDumper/Test/VarDumperTestCase.php
Normal file
45
src/Symfony/Component/VarDumper/Test/VarDumperTestCase.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\VarDumper\Test;
|
||||
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
abstract class VarDumperTestCase extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function assertDumpEquals($dump, $data, $message = '')
|
||||
{
|
||||
$this->assertSame($dump, $this->getVarDumperDump($data), $message);
|
||||
}
|
||||
|
||||
public function assertDumpMatchesFormat($dump, $data, $message = '')
|
||||
{
|
||||
$this->assertStringMatchesFormat($dump, $this->getVarDumperDump($data), $message);
|
||||
}
|
||||
|
||||
private function getVarDumperDump($data)
|
||||
{
|
||||
$h = fopen('php://memory', 'r+b');
|
||||
$cloner = new VarCloner();
|
||||
$dumper = new CliDumper($h);
|
||||
$dumper->setColors(false);
|
||||
$dumper->dump($cloner->cloneVar($data)->withRefHandles(false));
|
||||
fseek($h, 0);
|
||||
$data = stream_get_contents($h);
|
||||
fclose($h);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
45
src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php
Normal file
45
src/Symfony/Component/VarDumper/Test/VarDumperTestTrait.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\VarDumper\Test;
|
||||
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
trait VarDumperTestTrait
|
||||
{
|
||||
public function assertDumpEquals($dump, $data, $message = '')
|
||||
{
|
||||
$this->assertSame($dump, $this->getVarDumperDump($data), $message);
|
||||
}
|
||||
|
||||
public function assertDumpMatchesFormat($dump, $data, $message = '')
|
||||
{
|
||||
$this->assertStringMatchesFormat($dump, $this->getVarDumperDump($data), $message);
|
||||
}
|
||||
|
||||
private function getVarDumperDump($data)
|
||||
{
|
||||
$h = fopen('php://memory', 'r+b');
|
||||
$cloner = new VarCloner();
|
||||
$dumper = new CliDumper($h);
|
||||
$dumper->setColors(false);
|
||||
$dumper->dump($cloner->cloneVar($data)->withRefHandles(false));
|
||||
fseek($h, 0);
|
||||
$data = stream_get_contents($h);
|
||||
fclose($h);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -13,11 +13,12 @@ namespace Symfony\Component\VarDumper\Tests;
|
||||
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
use Symfony\Component\VarDumper\Test\VarDumperTestCase;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class CliDumperTest extends \PHPUnit_Framework_TestCase
|
||||
class CliDumperTest extends VarDumperTestCase
|
||||
{
|
||||
public function testGet()
|
||||
{
|
||||
@ -115,21 +116,10 @@ EOTXT
|
||||
}
|
||||
|
||||
$var = xml_parser_create();
|
||||
$ref = (int) $var;
|
||||
|
||||
$dumper = new CliDumper();
|
||||
$dumper->setColors(false);
|
||||
$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->assertSame(
|
||||
$this->assertDumpEquals(
|
||||
<<<EOTXT
|
||||
:xml {@{$ref}
|
||||
:xml {
|
||||
current_byte_index: 0
|
||||
current_column_number: 1
|
||||
current_line_number: 1
|
||||
@ -138,7 +128,7 @@ EOTXT
|
||||
|
||||
EOTXT
|
||||
,
|
||||
$out
|
||||
$var
|
||||
);
|
||||
}
|
||||
|
||||
@ -190,7 +180,7 @@ EOTXT
|
||||
|
||||
EOTXT
|
||||
,
|
||||
$out
|
||||
$var
|
||||
);
|
||||
}
|
||||
|
||||
@ -206,17 +196,7 @@ EOTXT
|
||||
|
||||
$var = $this->getSpecialVars();
|
||||
|
||||
$dumper = new CliDumper();
|
||||
$dumper->setColors(false);
|
||||
$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->assertSame(
|
||||
$this->assertDumpEquals(
|
||||
<<<EOTXT
|
||||
array:3 [
|
||||
0 => array:1 [
|
||||
|
Reference in New Issue
Block a user