Completed
Push — master ( 1d8aab...11adb6 )
by M
04:36
created

ClientsTest::testConnectionPersistentError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace Kazuakim\Reddish;
4
5
/**
6
 * ClientsTest.
7
 *
8
 * @property array  $_defaultConfig
9
 * @property object $_clients;
10
 *
11
 * @copyright KazuakiM <[email protected]>
12
 * @author    KazuakiM <[email protected]>
13
 * @license   http://www.opensource.org/licenses/mit-license.php  MIT License
14
 *
15
 * @link      https://github.com/KazuakiM/reddish
16
 */
17
class ClientsTest extends \PHPUnit\Framework\TestCase //{{{
18
{
19
    // Class variable {{{
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
20
    private $_defaultConfig = [
21
        // 'connect' paramater
22
        'host' => '127.0.0.1', //can be a host, or the path to a unix domain socket
23
        'port' => 6379,
24
        'timeout' => 1.0,      //value in seconds (optional, default is 0 meaning unlimited)
25
        'reserved' => null,    //should be NULL if retry_interval is specified
26
        'read_timeout' => 1.0, //value in seconds (optional, default is 0 meaning unlimited)
27
28
        // 'pconnect' paramater
29
        'persistent_id' => '', //identity for the requested persistent connection
30
31
        // 'auth' paramater
32
        'password' => null,
33
34
        // serializer
35
        'serializer' => \Redis::SERIALIZER_NONE,
36
37
        // 'connect' or 'pconnect'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
38
        'persistent' => false, //default is connect
39
    ];
40
41
    private $_clients;
42
    //}}}
43
44
    /**
45
     * setUp.
46
     */
47
    protected function setUp() //{{{
48
    {
49
        $this->_clients = new Clients($this->_defaultConfig);
50
    } //}}}
51
52
    /**
53
     * tearDown.
54
     */
55
    protected function tearDown() //{{{
56
    {
57
        unset($this->_clients);
58
    } //}}}
59
60
    /**
61
     * testConnectionPersistentError.
62
     *
63
     * @expectedException        \RedisException
64
     * @expectedExceptionCode    0
65
     * @expectedExceptionMessage connect errored.
66
     */
67
    public function testConnectionPersistentError() //{{{
68
    {
69
        $config = $this->_defaultConfig;
70
        $config['host'] = '127.0.0.2';
71
        $clients = new Clients($config);
0 ignored issues
show
Unused Code introduced by
The assignment to $clients is dead and can be removed.
Loading history...
72
    } //}}}
73
74
    /**
75
     * testConnectionError.
76
     *
77
     * @expectedException        \RedisException
78
     * @expectedExceptionCode    0
79
     * @expectedExceptionMessage pconnect errored.
80
     */
81
    public function testConnectionError() //{{{
82
    {
83
        $config = $this->_defaultConfig;
84
        $config['host'] = '127.0.0.2';
85
        $config['persistent'] = true;
86
        $clients = new Clients($config);
0 ignored issues
show
Unused Code introduced by
The assignment to $clients is dead and can be removed.
Loading history...
87
    } //}}}
88
89
    /**
90
     * testAuthError.
91
     *
92
     * @expectedException        \RedisException
93
     * @expectedExceptionCode    0
94
     * @expectedExceptionMessage auth errored.
95
     */
96
    public function testAuthError() //{{{
97
    {
98
        $config = $this->_defaultConfig;
99
        $config['password'] = 'dummy';
100
        $clients = new Clients($config);
0 ignored issues
show
Unused Code introduced by
The assignment to $clients is dead and can be removed.
Loading history...
101
    } //}}}
102
103
    /**
104
     * testPingError.
105
     *
106
     * @expectedException        \RedisException
107
     * @expectedExceptionCode    0
108
     * @expectedExceptionMessage Connection closed
109
     */
110
    public function testPingError() //{{{
111
    {
112
        $config = $this->_defaultConfig;
113
        $config['persistent'] = true;
114
        $clients = new Clients($config);
115
        $clients->close();
116
        $clients->ping();
117
    } //}}}
118
119
    /**
120
     * testConnection.
121
     */
122 View Code Duplication
    public function testConnection() //{{{
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
123
    {
124
        $this->assertTrue($this->_clients->isConnected());
125
126
        $config = $this->_defaultConfig;
127
        $config['persistent'] = true;
128
        $clients = new Clients($config);
129
        $this->assertTrue($clients->isConnected());
0 ignored issues
show
Bug introduced by
The method isConnected() does not exist on Kazuakim\Reddish\Clients. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

129
        $this->assertTrue($clients->/** @scrutinizer ignore-call */ isConnected());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
130
        $clients->ping();
131
        $clients->close();
132
133
        unset($clients);
134
    } //}}}
135
136
    /**
137
     * testIsConnected.
138
     */
139 View Code Duplication
    public function testIsConnected() //{{{
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
140
    {
141
        $config = $this->_defaultConfig;
142
        $config['persistent'] = true;
143
        $clients = new Clients($config);
144
        $this->assertTrue($clients->isConnected());
145
        $clients->close();
146
147
        $this->assertFalse($clients->isConnected());
148
        $clients->close();
149
    } //}}}
150
151
    /**
152
     * testSave.
153
     */
154
    public function testSave() //{{{
155
    {
156
        $this->_clients->set('key', '1');
157
        $this->assertSame('1', $this->_clients->get('key'));
158
    } //}}}
159
} //}}}
160