Passed
Push — master ( 87bd55...eebb79 )
by M
02:12
created

ClientsTest::testConnectionError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Kazuakim\Reddish;
4
5
/**
6
 * ClientsTest.
7
 *
8
 * @copyright KazuakiM <[email protected]>
9
 * @author    KazuakiM <[email protected]>
10
 * @license   http://www.opensource.org/licenses/mit-license.php  MIT License
11
 *
12
 * @link      https://github.com/KazuakiM/reddish
13
 */
14
class ClientsTest extends \PHPUnit\Framework\TestCase //{{{
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
{
16
    // 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...
17
    private static $_defaultConfig = [
18
        // 'connect' paramater
19
        'host' => '127.0.0.1',    //can be a host, or the path to a unix domain socket
20
        'port' => 6379,
21
        'timeout' => 1.0,         //value in seconds (optional, default is 0 meaning unlimited)
22
        'reserved' => null,       //should be NULL if retry_interval is specified
23
        'retry_interval' => null, //value in milliseconds
24
        'read_timeout' => 1.0,    //value in seconds (optional, default is 0 meaning unlimited)
25
26
        // 'pconnect' paramater
27
        'persistent_id' => '',    //identity for the requested persistent connection
28
29
        // 'auth' paramater
30
        'password' => null,
31
32
        // serializer
33
        'serializer' => \Redis::SERIALIZER_NONE,
34
35
        // '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...
36
        'persistent' => false,    //default is connect
37
    ];
38
    //}}}
39
40
    protected function setUp() //{{{
41
    {
42
    } //}}}
43
44
    /**
45
     * @expectedException        \Kazuakim\Reddish\ReddishException
46
     * @expectedExceptionCode    0
47
     * @expectedExceptionMessage connect errored.
48
     */
49
    public function testConnectionPersistentError() //{{{
50
    {
51
        $config = self::$_defaultConfig;
52
        $config['host'] = '127.0.0.2';
53
        $clients = new Clients($config);
0 ignored issues
show
Unused Code introduced by
The assignment to $clients is dead and can be removed.
Loading history...
54
    } //}}}
55
56
    /**
57
     * @expectedException        \Kazuakim\Reddish\ReddishException
58
     * @expectedExceptionCode    0
59
     * @expectedExceptionMessage pconnect errored.
60
     */
61
    public function testConnectionError() //{{{
62
    {
63
        $config = self::$_defaultConfig;
64
        $config['host'] = '127.0.0.2';
65
        $config['persistent'] = true;
66
        $clients = new Clients($config);
0 ignored issues
show
Unused Code introduced by
The assignment to $clients is dead and can be removed.
Loading history...
67
    } //}}}
68
69
    /**
70
     * @expectedException        \Kazuakim\Reddish\ReddishException
71
     * @expectedExceptionCode    0
72
     * @expectedExceptionMessage Connection closed
73
     */
74
    public function testPingError() //{{{
75
    {
76
        $config = self::$_defaultConfig;
77
        $config['persistent'] = true;
78
        $clients = new Clients($config);
79
        $clients->close();
80
        $clients->ping();
81
    } //}}}
82
83
    public function testConnection() //{{{
84
    {
85
        $config = self::$_defaultConfig;
86
        $clients = new Clients($config);
87
        $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

87
        $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...
88
        unset($clients);
89
90
        $config['persistent'] = true;
91
        $clients = new Clients($config);
92
        $this->assertTrue($clients->isConnected());
93
        $clients->ping();
94
        $clients->close();
95
        unset($clients);
96
    } //}}}
97
98
    public function testSave() //{{{
99
    {
100
        $config = self::$_defaultConfig;
101
        $clients = new Clients($config);
102
        $clients->set('key', 1);
103
        $this->assertSame('1', $clients->get('key'));
104
    } //}}}
105
} //}}}
106