Completed
Push — master ( 8fe011...a16b04 )
by Kevin
02:06
created

RedisCollectionTest::provideDsnWithAut()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Liip\MonitorBundle\Tests\Check;
4
5
use Liip\MonitorBundle\Check\RedisCollection;
6
use PHPUnit\Framework\TestCase;
7
use ReflectionClass;
8
use ReflectionException;
9
use ZendDiagnostics\Check\Redis;
10
11
final class RedisCollectionTest extends TestCase
12
{
13
    const AUTH = 'my-super-secret-password';
14
15
    /**
16
     * @test
17
     * @dataProvider provideDsnWithAut
18
     */
19
    public function handleDsnWithAuth(string $dsn)
20
    {
21
        $config = [
22
          'dsn'      => $dsn,
23
          'host'     => 'localhost',
24
          'port'     => 6379,
25
          'password' => null,
26
        ];
27
28
        $collection = new RedisCollection(['default' => $config]);
29
        $checks     = $collection->getChecks();
30
31
        /** @var \ZendDiagnostics\Check\Redis $check */
32
        $check = $checks['redis_default'];
33
34
        $this->assertAuthPropertyValue($check, self::AUTH);
35
    }
36
37
    /**
38
     * @param \ZendDiagnostics\Check\Redis $check
39
     * @param string                       $auth
40
     */
41
    private function assertAuthPropertyValue(Redis $check, string $auth)
42
    {
43
        try {
44
            $refClass = new ReflectionClass($check);
45
            $authProp = $refClass->getProperty('auth');
46
            $authProp->setAccessible(true);
47
            self::assertSame($auth, $authProp->getValue($check));
48
49
        } catch (ReflectionException $e) {
50
            self::fail($e->getMessage());
51
        }
52
    }
53
54
    public function provideDsnWithAut(): array
55
    {
56
        return [
57
          'incompatible with parse_url' => [sprintf('redis://%[email protected]:6379', static::AUTH)],
58
          'compatible with parse_url'   => [sprintf('redis://irrelevant-user:%[email protected]:6379', static::AUTH)],
59
        ];
60
    }
61
}
62