000e5feeb125aaa9667f2089477819f2ccb8f247
[yaffs-website] / vendor / symfony / var-dumper / Tests / Caster / PdoCasterTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
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\Caster;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\VarDumper\Caster\PdoCaster;
16 use Symfony\Component\VarDumper\Cloner\Stub;
17 use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
18
19 /**
20  * @author Nicolas Grekas <p@tchwork.com>
21  */
22 class PdoCasterTest extends TestCase
23 {
24     use VarDumperTestTrait;
25
26     /**
27      * @requires extension pdo_sqlite
28      */
29     public function testCastPdo()
30     {
31         $pdo = new \PDO('sqlite::memory:');
32         $pdo->setAttribute(\PDO::ATTR_STATEMENT_CLASS, array('PDOStatement', array($pdo)));
33
34         $cast = PdoCaster::castPdo($pdo, array(), new Stub(), false);
35
36         $this->assertInstanceOf('Symfony\Component\VarDumper\Caster\EnumStub', $cast["\0~\0attributes"]);
37
38         $attr = $cast["\0~\0attributes"] = $cast["\0~\0attributes"]->value;
39         $this->assertInstanceOf('Symfony\Component\VarDumper\Caster\ConstStub', $attr['CASE']);
40         $this->assertSame('NATURAL', $attr['CASE']->class);
41         $this->assertSame('BOTH', $attr['DEFAULT_FETCH_MODE']->class);
42
43         $xDump = <<<'EODUMP'
44 array:2 [
45   "\x00~\x00inTransaction" => false
46   "\x00~\x00attributes" => array:9 [
47     "CASE" => NATURAL
48     "ERRMODE" => SILENT
49     "PERSISTENT" => false
50     "DRIVER_NAME" => "sqlite"
51     "ORACLE_NULLS" => NATURAL
52     "CLIENT_VERSION" => "%s"
53     "SERVER_VERSION" => "%s"
54     "STATEMENT_CLASS" => array:%d [
55       0 => "PDOStatement"%A
56     ]
57     "DEFAULT_FETCH_MODE" => BOTH
58   ]
59 ]
60 EODUMP;
61
62         $this->assertDumpMatchesFormat($xDump, $cast);
63     }
64 }