PdoCasterTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. public function testCastPdo()
  19. {
  20. if (!extension_loaded('pdo_sqlite')) {
  21. $this->markTestSkipped('pdo_sqlite extension is required');
  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. $attr = $cast["\0~\0attributes"];
  27. $this->assertInstanceOf('Symfony\Component\VarDumper\Caster\ConstStub', $attr['CASE']);
  28. $this->assertSame('NATURAL', $attr['CASE']->class);
  29. $this->assertSame('BOTH', $attr['DEFAULT_FETCH_MODE']->class);
  30. $xCast = array(
  31. "\0~\0inTransaction" => $pdo->inTransaction(),
  32. "\0~\0attributes" => array(
  33. 'CASE' => $attr['CASE'],
  34. 'ERRMODE' => $attr['ERRMODE'],
  35. 'PERSISTENT' => false,
  36. 'DRIVER_NAME' => 'sqlite',
  37. 'ORACLE_NULLS' => $attr['ORACLE_NULLS'],
  38. 'CLIENT_VERSION' => $pdo->getAttribute(\PDO::ATTR_CLIENT_VERSION),
  39. 'SERVER_VERSION' => $pdo->getAttribute(\PDO::ATTR_SERVER_VERSION),
  40. 'STATEMENT_CLASS' => array('PDOStatement'),
  41. 'DEFAULT_FETCH_MODE' => $attr['DEFAULT_FETCH_MODE'],
  42. ),
  43. );
  44. unset($cast["\0~\0attributes"]['STATEMENT_CLASS'][1]);
  45. $this->assertSame($xCast, $cast);
  46. }
  47. }