Completed
Pull Request — master (#3)
by M
02:18
created

ClientsTest::testIsConnected()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 10
loc 10
rs 9.4285
c 0
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
     * testPingError.
91
     *
92
     * @expectedException        \RedisException
93
     * @expectedExceptionCode    0
94
     * @expectedExceptionMessage Connection closed
95
     */
96
    public function testPingError() //{{{
97
    {
98
        $config = $this->_defaultConfig;
99
        $config['persistent'] = true;
100
        $clients = new Clients($config);
101
        $clients->close();
102
        $clients->ping();
103
    } //}}}
104
105
    /**
106
     * testConnection.
107
     */
108 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...
109
    {
110
        $this->assertTrue($this->_clients->isConnected());
111
112
        $config = $this->_defaultConfig;
113
        $config['persistent'] = true;
114
        $clients = new Clients($config);
115
        $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

115
        $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...
116
        $clients->ping();
117
        $clients->close();
118
119
        unset($clients);
120
    } //}}}
121
122
    /**
123
     * testIsConnected.
124
     */
125 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...
126
    {
127
        $config = $this->_defaultConfig;
128
        $config['persistent'] = true;
129
        $clients = new Clients($config);
130
        $this->assertTrue($clients->isConnected());
131
        $clients->close();
132
133
        $this->assertFalse($clients->isConnected());
134
        $clients->close();
135
    } //}}}
136
137
    /**
138
     * testSave.
139
     */
140
    public function testSave() //{{{
141
    {
142
        $this->_clients->set('key', '1');
143
        $this->assertSame('1', $this->_clients->get('key'));
144
    } //}}}
145
} //}}}
146