Passed
Push — master ( 68b04b...f7f8f7 )
by Eugene
02:12
created

OptionsProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 64
dl 0
loc 102
rs 10
c 1
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A provideClientDsnOptionsOfInvalidTypes() 0 10 1
A provideConnectionArrayOptionsOfInvalidTypes() 0 9 1
A provideClientArrayOptionsOfInvalidTypes() 0 12 1
A provideTcpExtraConnectionArrayOptionsOfInvalidTypes() 0 5 1
A provideConnectionArrayOptionsOfValidTypes() 0 8 1
A provideClientDsnOptionsOfValidTypes() 0 24 1
A provideTcpExtraConnectionArrayOptionsOfValidTypes() 0 4 1
A provideClientArrayOptionsOfValidTypes() 0 7 1
1
<?php
2
3
/**
4
 * This file is part of the tarantool/client package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Tarantool\Client\Tests\Unit;
15
16
final class OptionsProvider
17
{
18
    public static function provideConnectionArrayOptionsOfValidTypes() : array
19
    {
20
        return [
21
            ['connect_timeout', 42],
22
            ['connect_timeout', 42.3],
23
            ['socket_timeout', 42],
24
            ['socket_timeout', 42.3],
25
            ['persistent', false],
26
        ];
27
    }
28
29
    public static function provideConnectionArrayOptionsOfInvalidTypes() : array
30
    {
31
        return [
32
            ['connect_timeout', '42.1', 'float'],
33
            ['connect_timeout', false, 'float'],
34
            ['socket_timeout', '42.2', 'float'],
35
            ['socket_timeout', false, 'float'],
36
            ['persistent', 0, 'bool'],
37
            ['persistent', 'false', 'bool'],
38
        ];
39
    }
40
41
    public function provideTcpExtraConnectionArrayOptionsOfValidTypes() : array
42
    {
43
        return [
44
            ['tcp_nodelay', false],
45
        ];
46
    }
47
48
    public static function provideTcpExtraConnectionArrayOptionsOfInvalidTypes() : array
49
    {
50
        return [
51
            ['tcp_nodelay', 0, 'bool'],
52
            ['tcp_nodelay', 'false', 'bool'],
53
        ];
54
    }
55
56
    public static function provideClientArrayOptionsOfValidTypes() : array
57
    {
58
        return array_merge(self::provideConnectionArrayOptionsOfValidTypes(), [
59
            ['uri', 'foo'],
60
            ['username', 'foo'],
61
            ['password', 'bar', ['username' => 'foo']],
62
            ['max_retries', 42],
63
        ]);
64
    }
65
66
    public static function provideClientArrayOptionsOfInvalidTypes() : array
67
    {
68
        return array_merge(self::provideConnectionArrayOptionsOfInvalidTypes(), [
69
            ['uri', 0, 'string'],
70
            ['uri', false, 'string'],
71
            ['username', 0, 'string'],
72
            ['username', false, 'string'],
73
            ['password', 0, 'string', ['username' => 'foobar']],
74
            ['password', false, 'string', ['username' => 'foobar']],
75
            ['max_retries', 4.2, 'int'],
76
            ['max_retries', '42', 'int'],
77
            ['max_retries', false, 'int'],
78
        ]);
79
    }
80
81
    public static function provideClientDsnOptionsOfValidTypes() : array
82
    {
83
        return [
84
            ['connect_timeout=42.4'],
85
            ['socket_timeout=42.5'],
86
            ['persistent=1'],
87
            ['persistent=0'],
88
            ['persistent=on'],
89
            ['persistent=off'],
90
            ['persistent=true'],
91
            ['persistent=false'],
92
            ['persistent=yes'],
93
            ['persistent=no'],
94
            ['tcp_nodelay=1'],
95
            ['tcp_nodelay=0'],
96
            ['tcp_nodelay=on'],
97
            ['tcp_nodelay=off'],
98
            ['tcp_nodelay=true'],
99
            ['tcp_nodelay=false'],
100
            ['tcp_nodelay=yes'],
101
            ['tcp_nodelay=no'],
102
            ['username=foo'],
103
            ['username=foo&password=bar'],
104
            ['max_retries=42'],
105
        ];
106
    }
107
108
    public static function provideClientDsnOptionsOfInvalidTypes() : array
109
    {
110
        return [
111
            ['connect_timeout=foo', 'connect_timeout', 'float'],
112
            ['socket_timeout=foo', 'socket_timeout', 'float'],
113
            ['persistent=42.5', 'persistent', 'bool'],
114
            ['persistent=foo', 'persistent', 'bool'],
115
            ['tcp_nodelay=42.6', 'tcp_nodelay', 'bool'],
116
            ['max_retries=foo', 'max_retries', 'int'],
117
            ['max_retries=42.7', 'max_retries', 'int'],
118
        ];
119
    }
120
}
121