4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\VarDumper\Tests\Caster;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\VarDumper\Caster\PdoCaster;
16 use Symfony\Component\VarDumper\Cloner\Stub;
19 * @author Nicolas Grekas <p@tchwork.com>
21 class PdoCasterTest extends TestCase
24 * @requires extension pdo_sqlite
26 public function testCastPdo()
28 $pdo = new \PDO('sqlite::memory:');
29 $pdo->setAttribute(\PDO::ATTR_STATEMENT_CLASS, array('PDOStatement', array($pdo)));
31 $cast = PdoCaster::castPdo($pdo, array(), new Stub(), false);
33 $this->assertInstanceOf('Symfony\Component\VarDumper\Caster\EnumStub', $cast["\0~\0attributes"]);
35 $attr = $cast["\0~\0attributes"] = $cast["\0~\0attributes"]->value;
36 $this->assertInstanceOf('Symfony\Component\VarDumper\Caster\ConstStub', $attr['CASE']);
37 $this->assertSame('NATURAL', $attr['CASE']->class);
38 $this->assertSame('BOTH', $attr['DEFAULT_FETCH_MODE']->class);
41 "\0~\0inTransaction" => $pdo->inTransaction(),
42 "\0~\0attributes" => array(
43 'CASE' => $attr['CASE'],
44 'ERRMODE' => $attr['ERRMODE'],
45 'PERSISTENT' => false,
46 'DRIVER_NAME' => 'sqlite',
47 'ORACLE_NULLS' => $attr['ORACLE_NULLS'],
48 'CLIENT_VERSION' => $pdo->getAttribute(\PDO::ATTR_CLIENT_VERSION),
49 'SERVER_VERSION' => $pdo->getAttribute(\PDO::ATTR_SERVER_VERSION),
50 'STATEMENT_CLASS' => array('PDOStatement'),
51 'DEFAULT_FETCH_MODE' => $attr['DEFAULT_FETCH_MODE'],
54 unset($cast["\0~\0attributes"]['STATEMENT_CLASS'][1]);
56 $this->assertSame($xCast, $cast);