PdoCasterTest.php 1.9 KB

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