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 {{{ |
|
|
|
|
20
|
|
|
private $_defaultConfig = [ |
21
|
|
|
'host' => '127.0.0.1', |
22
|
|
|
'port' => 6379, |
23
|
|
|
'timeout' => 1.0, |
24
|
|
|
'password' => null, |
25
|
|
|
'serializer' => \Redis::SERIALIZER_NONE, |
26
|
|
|
'persistent' => false, |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
private $_clients; |
30
|
|
|
//}}} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* setUp. |
34
|
|
|
*/ |
35
|
|
|
protected function setUp() //{{{ |
36
|
|
|
{ |
37
|
|
|
$this->_clients = new Clients($this->_defaultConfig); |
38
|
|
|
} //}}} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* tearDown. |
42
|
|
|
*/ |
43
|
|
|
protected function tearDown() //{{{ |
44
|
|
|
{ |
45
|
|
|
unset($this->_clients); |
46
|
|
|
} //}}} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* testConnectionPersistentError. |
50
|
|
|
* |
51
|
|
|
* @expectedException \RedisException |
52
|
|
|
* @expectedExceptionCode 0 |
53
|
|
|
* @expectedExceptionMessage connect errored. |
54
|
|
|
*/ |
55
|
|
View Code Duplication |
public function testConnectionPersistentError() //{{{ |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$config = $this->_defaultConfig; |
58
|
|
|
$config['host'] = '127.0.0.2'; |
59
|
|
|
$clients = new Clients($config); |
60
|
|
|
unset($clients); |
61
|
|
|
} //}}} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* testConnectionError. |
65
|
|
|
* |
66
|
|
|
* @expectedException \RedisException |
67
|
|
|
* @expectedExceptionCode 0 |
68
|
|
|
* @expectedExceptionMessage pconnect errored. |
69
|
|
|
*/ |
70
|
|
View Code Duplication |
public function testConnectionError() //{{{ |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$config = $this->_defaultConfig; |
73
|
|
|
$config['host'] = '127.0.0.2'; |
74
|
|
|
$config['persistent'] = true; |
75
|
|
|
$clients = new Clients($config); |
76
|
|
|
unset($clients); |
77
|
|
|
} //}}} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* testAuthError. |
81
|
|
|
* |
82
|
|
|
* @expectedException \RedisException |
83
|
|
|
* @expectedExceptionCode 0 |
84
|
|
|
* @expectedExceptionMessage auth errored. |
85
|
|
|
*/ |
86
|
|
|
public function testAuthError() //{{{ |
87
|
|
|
{ |
88
|
|
|
$config = $this->_defaultConfig; |
89
|
|
|
$config['password'] = 'dummy'; |
90
|
|
|
$clients = new Clients($config); |
91
|
|
|
unset($clients); |
92
|
|
|
} //}}} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* testPingError. |
96
|
|
|
* |
97
|
|
|
* @expectedException \RedisException |
98
|
|
|
* @expectedExceptionCode 0 |
99
|
|
|
* @expectedExceptionMessage Connection closed |
100
|
|
|
*/ |
101
|
|
|
public function testPingError() //{{{ |
102
|
|
|
{ |
103
|
|
|
$config = $this->_defaultConfig; |
104
|
|
|
$config['persistent'] = true; |
105
|
|
|
$clients = new Clients($config); |
106
|
|
|
$clients->close(); |
107
|
|
|
$clients->ping(); |
108
|
|
|
} //}}} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* testConnection. |
112
|
|
|
*/ |
113
|
|
|
public function testConnection() //{{{ |
114
|
|
|
{ |
115
|
|
|
$config = $this->_defaultConfig; |
116
|
|
|
$config['persistent'] = true; |
117
|
|
|
$clients = new Clients($config); |
118
|
|
|
$this->assertTrue($clients-> /* @scrutinizer ignore-call */ isConnected()); |
119
|
|
|
$clients->ping(); |
120
|
|
|
$clients->close(); |
121
|
|
|
|
122
|
|
|
$this->assertFalse($clients-> /* @scrutinizer ignore-call */ isConnected()); |
123
|
|
|
$clients->close(); |
124
|
|
|
} //}}} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* testSave. |
128
|
|
|
*/ |
129
|
|
|
public function testSave() //{{{ |
130
|
|
|
{ |
131
|
|
|
$this->_clients->set('key', '1'); |
132
|
|
|
$this->assertSame('1', $this->_clients->get('key')); |
133
|
|
|
} //}}} |
134
|
|
|
} //}}} |
135
|
|
|
|
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.