1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\VarDumper\Tests\Caster;
13
14use PHPUnit\Framework\TestCase;
15use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
16
17/**
18 * @author Nicolas Grekas <p@tchwork.com>
19 * @requires extension redis
20 */
21class RedisCasterTest extends TestCase
22{
23    use VarDumperTestTrait;
24
25    public function testNotConnected()
26    {
27        $redis = new \Redis();
28
29        $xCast = <<<'EODUMP'
30Redis {
31  isConnected: false
32}
33EODUMP;
34
35        $this->assertDumpMatchesFormat($xCast, $redis);
36    }
37
38    public function testConnected()
39    {
40        $redis = new \Redis();
41        if (!@$redis->connect('127.0.0.1')) {
42            $e = error_get_last();
43            self::markTestSkipped($e['message']);
44        }
45
46        $xCast = <<<'EODUMP'
47Redis {%A
48  isConnected: true
49  host: "127.0.0.1"
50  port: 6379
51  auth: null
52  mode: ATOMIC
53  dbNum: 0
54  timeout: 0.0
55  lastError: null
56  persistentId: null
57  options: {
58    TCP_KEEPALIVE: 0
59    READ_TIMEOUT: 0.0
60    COMPRESSION: NONE
61    SERIALIZER: NONE
62    PREFIX: null
63    SCAN: NORETRY
64  }
65}
66EODUMP;
67
68        $this->assertDumpMatchesFormat($xCast, $redis);
69    }
70}
71