Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3402fff

Browse files
committed
bug #13073 [VarDumper] fix and test PdoCaster (nicolas-grekas)
This PR was merged into the 2.6 branch. Discussion ---------- [VarDumper] fix and test PdoCaster | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #13042 | License | MIT | Doc PR | - Commits ------- 0b1be13 [VarDumper] fix and test PdoCaster
2 parents 72c169e + 0b1be13 commit 3402fff

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

src/Symfony/Component/VarDumper/Caster/PdoCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static function castPdo(\PDO $c, array $a, Stub $stub, $isNested)
7171

7272
try {
7373
$a[$attr] = 'ERRMODE' === $attr ? $errmode : $c->getAttribute(constant("PDO::ATTR_{$attr}"));
74-
if (isset($values[$a[$attr]])) {
74+
if ($values && isset($values[$a[$attr]])) {
7575
$a[$attr] = new ConstStub($values[$a[$attr]], $a[$attr]);
7676
}
7777
} catch (\Exception $m) {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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 Symfony\Component\VarDumper\Caster\PdoCaster;
15+
use Symfony\Component\VarDumper\Cloner\Stub;
16+
17+
/**
18+
* @author Nicolas Grekas <[email protected]>
19+
*/
20+
class PdoCasterTest extends \PHPUnit_Framework_TestCase
21+
{
22+
public function testCastPdo()
23+
{
24+
if (!extension_loaded('pdo_sqlite')) {
25+
$this->markTestSkipped('pdo_sqlite extension is required');
26+
}
27+
28+
$pdo = new \PDO('sqlite::memory:');
29+
$pdo->setAttribute(\PDO::ATTR_STATEMENT_CLASS, array('PDOStatement', array($pdo)));
30+
31+
$cast = PdoCaster::castPdo($pdo, array(), new Stub(), false);
32+
$attr = $cast["\0~\0attributes"];
33+
34+
$this->assertInstanceOf('Symfony\Component\VarDumper\Caster\ConstStub', $attr['CASE']);
35+
$this->assertSame('NATURAL', $attr['CASE']->class);
36+
$this->assertSame('BOTH', $attr['DEFAULT_FETCH_MODE']->class);
37+
38+
$xCast = array(
39+
"\0~\0inTransaction" => false,
40+
"\0~\0attributes" => array(
41+
'CASE' => $attr['CASE'],
42+
'ERRMODE' => $attr['ERRMODE'],
43+
'PERSISTENT' => false,
44+
'DRIVER_NAME' => 'sqlite',
45+
'ORACLE_NULLS' => $attr['ORACLE_NULLS'],
46+
'CLIENT_VERSION' => $pdo->getAttribute(\PDO::ATTR_CLIENT_VERSION),
47+
'SERVER_VERSION' => $pdo->getAttribute(\PDO::ATTR_SERVER_VERSION),
48+
'STATEMENT_CLASS' => array(
49+
'PDOStatement',
50+
array($pdo),
51+
),
52+
'DEFAULT_FETCH_MODE' => $attr['DEFAULT_FETCH_MODE'],
53+
),
54+
);
55+
56+
$this->assertSame($xCast, $cast);
57+
}
58+
}

0 commit comments

Comments
 (0)