Drupal investigation

PdoCasterTest.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 PHPUnit\Framework\TestCase;
  12. use Symfony\Component\VarDumper\Caster\PdoCaster;
  13. use Symfony\Component\VarDumper\Cloner\Stub;
  14. /**
  15. * @author Nicolas Grekas <p@tchwork.com>
  16. */
  17. class PdoCasterTest extends TestCase
  18. {
  19. /**
  20. * @requires extension pdo_sqlite
  21. */
  22. public function testCastPdo()
  23. {
  24. $pdo = new \PDO('sqlite::memory:');
  25. $pdo->setAttribute(\PDO::ATTR_STATEMENT_CLASS, array('PDOStatement', array($pdo)));
  26. $cast = PdoCaster::castPdo($pdo, array(), new Stub(), false);
  27. $this->assertInstanceOf('Symfony\Component\VarDumper\Caster\EnumStub', $cast["\0~\0attributes"]);
  28. $attr = $cast["\0~\0attributes"] = $cast["\0~\0attributes"]->value;
  29. $this->assertInstanceOf('Symfony\Component\VarDumper\Caster\ConstStub', $attr['CASE']);
  30. $this->assertSame('NATURAL', $attr['CASE']->class);
  31. $this->assertSame('BOTH', $attr['DEFAULT_FETCH_MODE']->class);
  32. $xCast = array(
  33. "\0~\0inTransaction" => $pdo->inTransaction(),
  34. "\0~\0attributes" => array(
  35. 'CASE' => $attr['CASE'],
  36. 'ERRMODE' => $attr['ERRMODE'],
  37. 'PERSISTENT' => false,
  38. 'DRIVER_NAME' => 'sqlite',
  39. 'ORACLE_NULLS' => $attr['ORACLE_NULLS'],
  40. 'CLIENT_VERSION' => $pdo->getAttribute(\PDO::ATTR_CLIENT_VERSION),
  41. 'SERVER_VERSION' => $pdo->getAttribute(\PDO::ATTR_SERVER_VERSION),
  42. 'STATEMENT_CLASS' => array('PDOStatement'),
  43. 'DEFAULT_FETCH_MODE' => $attr['DEFAULT_FETCH_MODE'],
  44. ),
  45. );
  46. unset($cast["\0~\0attributes"]['STATEMENT_CLASS'][1]);
  47. $this->assertSame($xCast, $cast);
  48. }
  49. }