PdoCasterTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
  15. /**
  16. * @author Nicolas Grekas <p@tchwork.com>
  17. */
  18. class PdoCasterTest extends TestCase
  19. {
  20. use VarDumperTestTrait;
  21. /**
  22. * @requires extension pdo_sqlite
  23. */
  24. public function testCastPdo()
  25. {
  26. $pdo = new \PDO('sqlite::memory:');
  27. $pdo->setAttribute(\PDO::ATTR_STATEMENT_CLASS, ['PDOStatement', [$pdo]]);
  28. $cast = PdoCaster::castPdo($pdo, [], new Stub(), false);
  29. $this->assertInstanceOf('Symfony\Component\VarDumper\Caster\EnumStub', $cast["\0~\0attributes"]);
  30. $attr = $cast["\0~\0attributes"] = $cast["\0~\0attributes"]->value;
  31. $this->assertInstanceOf('Symfony\Component\VarDumper\Caster\ConstStub', $attr['CASE']);
  32. $this->assertSame('NATURAL', $attr['CASE']->class);
  33. $this->assertSame('BOTH', $attr['DEFAULT_FETCH_MODE']->class);
  34. $xDump = <<<'EODUMP'
  35. array:2 [
  36. "\x00~\x00inTransaction" => false
  37. "\x00~\x00attributes" => array:9 [
  38. "CASE" => NATURAL
  39. "ERRMODE" => SILENT
  40. "PERSISTENT" => false
  41. "DRIVER_NAME" => "sqlite"
  42. "ORACLE_NULLS" => NATURAL
  43. "CLIENT_VERSION" => "%s"
  44. "SERVER_VERSION" => "%s"
  45. "STATEMENT_CLASS" => array:%d [
  46. 0 => "PDOStatement"%A
  47. ]
  48. "DEFAULT_FETCH_MODE" => BOTH
  49. ]
  50. ]
  51. EODUMP;
  52. $this->assertDumpMatchesFormat($xDump, $cast);
  53. }
  54. }