RedisCasterTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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\Test\VarDumperTestTrait;
  13. /**
  14. * @author Nicolas Grekas <p@tchwork.com>
  15. * @requires extension redis
  16. */
  17. class RedisCasterTest extends TestCase
  18. {
  19. use VarDumperTestTrait;
  20. public function testNotConnected()
  21. {
  22. $redis = new \Redis();
  23. if (defined('HHVM_VERSION_ID')) {
  24. $xCast = <<<'EODUMP'
  25. Redis {
  26. #host: ""
  27. %A
  28. }
  29. EODUMP;
  30. } else {
  31. $xCast = <<<'EODUMP'
  32. Redis {
  33. isConnected: false
  34. }
  35. EODUMP;
  36. }
  37. $this->assertDumpMatchesFormat($xCast, $redis);
  38. }
  39. public function testConnected()
  40. {
  41. $redis = new \Redis();
  42. if (!@$redis->connect('127.0.0.1')) {
  43. $e = error_get_last();
  44. self::markTestSkipped($e['message']);
  45. }
  46. if (defined('HHVM_VERSION_ID')) {
  47. $xCast = <<<'EODUMP'
  48. Redis {
  49. #host: "127.0.0.1"
  50. %A
  51. }
  52. EODUMP;
  53. } else {
  54. $xCast = <<<'EODUMP'
  55. Redis {
  56. +"socket": Redis Socket Buffer resource
  57. isConnected: true
  58. host: "127.0.0.1"
  59. port: 6379
  60. auth: null
  61. dbNum: 0
  62. timeout: 0.0
  63. persistentId: null
  64. options: {
  65. READ_TIMEOUT: 0.0
  66. SERIALIZER: NONE
  67. PREFIX: null
  68. SCAN: NORETRY
  69. }
  70. }
  71. EODUMP;
  72. }
  73. $this->assertDumpMatchesFormat($xCast, $redis);
  74. }
  75. }