RedisPluginConfigurationTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 17
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 27
rs 9.7
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Plugin\Cache\Test\Unit;
15
16
use Micro\Framework\Kernel\Configuration\DefaultApplicationConfiguration;
17
use Micro\Framework\Kernel\Configuration\Exception\InvalidConfigurationException;
18
use Micro\Plugin\Redis\RedisPluginConfiguration;
19
use PHPUnit\Framework\TestCase;
20
21
class RedisPluginConfigurationTest extends TestCase
22
{
23
    private RedisPluginConfiguration $cfg;
24
25
    protected function setUp(): void
26
    {
27
        /*
28
         * protected const CFG_CONNECTION_HOST = 'REDIS_%s_HOST';
29
    protected const CFG_CONNECTION_PORT = 'REDIS_%s_PORT';
30
    protected const CFG_CONNECTION_TIMEOUT = 'REDIS_%s_TIMEOUT';
31
    protected const CFG_CONNECTION_RETRY_INTERVAL = 'REDIS_%s_RETRY_INTERVAL';
32
    protected const CFG_READ_TIMEOUT = 'REDIS_%s_READ_TIMEOUT';
33
         */
34
        $appCfg = new DefaultApplicationConfiguration([
35
            'REDIS_INVALID_CONNECTION_TYPE' => 'invalid',
36
            'REDIS_TEST_CONNECTION_TYPE' => 'unix',
37
            'REDIS_TEST_CONNECTION_REUSE' => true,
38
            'REDIS_TEST_HOST' => '1',
39
            'REDIS_TEST_PORT' => 2,
40
            'REDIS_TEST_TIMEOUT' => 3,
41
            'REDIS_TEST_RETRY_INTERVAL' => 4,
42
            'REDIS_TEST_READ_TIMEOUT' => 5,
43
            'REDIS_TEST_AUTH_USERNAME' => 'user',
44
            'REDIS_TEST_AUTH_PASSWORD' => 'password',
45
            'REDIS_TEST_SSL_ENABLED' => 'On',
46
            'REDIS_TEST_SSL_VERIFY' => 'On',
47
            'REDIS_TEST_OPT_SERIALIZER' => 'none',
48
            'REDIS_TEST_OPT_PREFIX' => 'prefix',
49
            'REDIS_TEST_OPT_SCAN' => 'scan',
50
        ]);
51
        $this->cfg = new RedisPluginConfiguration($appCfg);
52
    }
53
54
    public function testInvalidConnectionType(): void
55
    {
56
        $this->expectException(InvalidConfigurationException::class);
57
58
        $clientCfg = $this->cfg->getClientConfiguration('invalid');
59
        $clientCfg->connectionType();
60
    }
61
62
    public function testConfiguration(): void
63
    {
64
        $clientCfg = $this->cfg->getClientConfiguration('test');
65
66
        $this->assertEquals('test', $clientCfg->name());
67
        $this->assertEquals(2, $clientCfg->port());
68
        $this->assertEquals('1', $clientCfg->host());
69
        $this->assertEquals(3., $clientCfg->connectionTimeout());
70
        $this->assertEquals(5, $clientCfg->readTimeout());
71
        $this->assertEquals(4, $clientCfg->retryInterval());
72
        $this->assertTrue($clientCfg->reuseConnection());
73
74
        $opts = $clientCfg->clientOptionsConfiguration();
75
        $this->assertEquals('prefix', $opts->prefix());
76
        $this->assertEquals('scan', $opts->scan());
77
        $this->assertEquals('none', $opts->serializer());
78
79
        $auth = $clientCfg->authorizationConfiguration();
80
        $this->assertEquals('password', $auth->password());
81
        $this->assertEquals('user', $auth->username());
82
83
        $ssl = $clientCfg->sslConfiguration();
84
        $this->assertTrue($ssl->enabled());
85
        $this->assertTrue($ssl->verify());
86
    }
87
88
    public function testDefaultConfiguration()
89
    {
90
        $clientCfg = $this->cfg->getClientConfiguration('default');
91
92
        $this->assertEquals('default', $clientCfg->name());
93
        $this->assertEquals(6379, $clientCfg->port());
94
        $this->assertEquals('localhost', $clientCfg->host());
95
        $this->assertEquals(0.0, $clientCfg->connectionTimeout());
96
        $this->assertEquals(0, $clientCfg->readTimeout());
97
        $this->assertEquals(0, $clientCfg->retryInterval());
98
        $this->assertFalse($clientCfg->reuseConnection());
99
        $this->assertEquals('network', $clientCfg->connectionType());
100
101
        $opts = $clientCfg->clientOptionsConfiguration();
102
        $this->assertEquals('', $opts->prefix());
103
        $this->assertEquals('', $opts->scan());
104
        $this->assertEquals('SERIALIZER_NONE', $opts->serializer());
105
106
        $auth = $clientCfg->authorizationConfiguration();
107
        $this->assertNull($auth->password());
108
        $this->assertNull($auth->username());
109
110
        $ssl = $clientCfg->sslConfiguration();
111
        $this->assertFalse($ssl->enabled());
112
        $this->assertFalse($ssl->verify());
113
    }
114
}
115