[VarDumper] replace VarDumperTestCase by trait

This commit is contained in:
Tobias Schultze 2015-11-04 18:48:20 +01:00
parent 24ff770679
commit 230990188d
7 changed files with 44 additions and 99 deletions

View File

@ -1,46 +0,0 @@
<?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>
*
* @deprecated since version 2.8, to be removed in 3.0. Use the VarDumperTestTrait instead.
*/
abstract class VarDumperTestCase extends \PHPUnit_Framework_TestCase
{
public function assertDumpEquals($dump, $data, $message = '')
{
$this->assertSame(rtrim($dump), $this->getDump($data), $message);
}
public function assertDumpMatchesFormat($dump, $data, $message = '')
{
$this->assertStringMatchesFormat(rtrim($dump), $this->getDump($data), $message);
}
protected function getDump($data)
{
$h = fopen('php://memory', 'r+b');
$cloner = new VarCloner();
$dumper = new CliDumper($h);
$dumper->setColors(false);
$dumper->dump($cloner->cloneVar($data)->withRefHandles(false));
$data = stream_get_contents($h, -1, 0);
fclose($h);
return rtrim($data);
}
}

View File

@ -12,13 +12,15 @@
namespace Symfony\Component\VarDumper\Tests\Caster;
use Symfony\Component\VarDumper\Caster\Caster;
use Symfony\Component\VarDumper\Test\VarDumperTestCase;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
/**
* @author Nicolas Grekas <p@tchwork.com>
*/
class CasterTest extends VarDumperTestCase
class CasterTest extends \PHPUnit_Framework_TestCase
{
use VarDumperTestTrait;
private $referenceArray = array(
'null' => null,
'empty' => false,

View File

@ -11,14 +11,16 @@
namespace Symfony\Component\VarDumper\Tests\Caster;
use Symfony\Component\VarDumper\Test\VarDumperTestCase;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
use Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo;
/**
* @author Nicolas Grekas <p@tchwork.com>
*/
class ReflectionCasterTest extends VarDumperTestCase
class ReflectionCasterTest extends \PHPUnit_Framework_TestCase
{
use VarDumperTestTrait;
public function testReflectionCaster()
{
$var = new \ReflectionClass('ReflectionClass');

View File

@ -11,13 +11,15 @@
namespace Symfony\Component\VarDumper\Tests\Caster;
use Symfony\Component\VarDumper\Test\VarDumperTestCase;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
/**
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*/
class SplCasterTest extends VarDumperTestCase
class SplCasterTest extends \PHPUnit_Framework_TestCase
{
use VarDumperTestTrait;
public function getCastFileInfoTests()
{
return array(

View File

@ -13,13 +13,15 @@ namespace Symfony\Component\VarDumper\Tests;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\Test\VarDumperTestCase;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
/**
* @author Nicolas Grekas <p@tchwork.com>
*/
class CliDumperTest extends VarDumperTestCase
class CliDumperTest extends \PHPUnit_Framework_TestCase
{
use VarDumperTestTrait;
public function testGet()
{
require __DIR__.'/Fixtures/dumb-var.php';

View File

@ -1,41 +0,0 @@
<?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\Tests\Test;
use Symfony\Component\VarDumper\Test\VarDumperTestCase;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
class VarDumperTestTraitTest extends VarDumperTestCase
{
use VarDumperTestTrait;
public function testItComparesLargeData()
{
$howMany = 700;
$data = array_fill_keys(range(0, $howMany), array('a', 'b', 'c', 'd'));
$expected = sprintf("array:%d [\n", $howMany + 1);
for ($i = 0; $i <= $howMany; ++$i) {
$expected .= <<<EODUMP
$i => array:4 [
0 => "a"
1 => "b"
2 => "c"
3 => "d"
]\n
EODUMP;
}
$expected .= "]\n";
$this->assertDumpEquals($expected, $data);
}
}

View File

@ -9,8 +9,32 @@
* file that was distributed with this source code.
*/
// Skipping trait tests for PHP < 5.4
if (version_compare(PHP_VERSION, '5.4.0-dev', '>=')) {
require 'VarDumpTestTraitRequire54.php';
}
namespace Symfony\Component\VarDumper\Tests\Test;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
class VarDumperTestTraitTest extends \PHPUnit_Framework_TestCase
{
use VarDumperTestTrait;
public function testItComparesLargeData()
{
$howMany = 700;
$data = array_fill_keys(range(0, $howMany), array('a', 'b', 'c', 'd'));
$expected = sprintf("array:%d [\n", $howMany + 1);
for ($i = 0; $i <= $howMany; ++$i) {
$expected .= <<<EODUMP
$i => array:4 [
0 => "a"
1 => "b"
2 => "c"
3 => "d"
]\n
EODUMP;
}
$expected .= "]\n";
$this->assertDumpEquals($expected, $data);
}
}