菜谱项目

RedisCasterTest.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 {%A
  56. isConnected: true
  57. host: "127.0.0.1"
  58. port: 6379
  59. auth: null
  60. dbNum: 0
  61. timeout: 0.0
  62. persistentId: null
  63. options: {
  64. READ_TIMEOUT: 0.0
  65. SERIALIZER: NONE
  66. PREFIX: null
  67. SCAN: NORETRY
  68. }
  69. }
  70. EODUMP;
  71. }
  72. $this->assertDumpMatchesFormat($xCast, $redis);
  73. }
  74. }