2
2
3
3
namespace Clue \Tests \React \Redis ;
4
4
5
+ use Clue \React \Redis \Client ;
5
6
use Clue \React \Redis \Factory ;
6
- use React \Promise ;
7
+ use React \EventLoop \LoopInterface ;
8
+ use React \Socket \ConnectionInterface ;
9
+ use React \Socket \ConnectorInterface ;
10
+ use function React \Promise \reject ;
11
+ use function React \Promise \resolve ;
7
12
8
13
class FactoryLazyClientTest extends TestCase
9
14
{
@@ -16,8 +21,8 @@ class FactoryLazyClientTest extends TestCase
16
21
*/
17
22
public function setUpFactory ()
18
23
{
19
- $ this ->loop = $ this ->getMockBuilder ( ' React\EventLoop\ LoopInterface' )-> getMock ( );
20
- $ this ->connector = $ this ->getMockBuilder ( ' React\Socket\ ConnectorInterface' )-> getMock ( );
24
+ $ this ->loop = $ this ->createMock ( LoopInterface::class );
25
+ $ this ->connector = $ this ->createMock ( ConnectorInterface::class );
21
26
$ this ->factory = new Factory ($ this ->loop , $ this ->connector );
22
27
}
23
28
@@ -29,134 +34,134 @@ public function testConstructWithoutLoopAssignsLoopAutomatically()
29
34
$ ref ->setAccessible (true );
30
35
$ loop = $ ref ->getValue ($ factory );
31
36
32
- $ this ->assertInstanceOf (' React\EventLoop\ LoopInterface' , $ loop );
37
+ $ this ->assertInstanceOf (LoopInterface::class , $ loop );
33
38
}
34
39
35
40
public function testWillConnectWithDefaultPort ()
36
41
{
37
- $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('redis.example.com:6379 ' )->willReturn (Promise \ reject (new \RuntimeException ()));
42
+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('redis.example.com:6379 ' )->willReturn (reject (new \RuntimeException ()));
38
43
$ this ->factory ->createLazyClient ('redis.example.com ' );
39
44
}
40
45
41
46
public function testWillConnectToLocalhost ()
42
47
{
43
- $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('localhost:1337 ' )->willReturn (Promise \ reject (new \RuntimeException ()));
48
+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('localhost:1337 ' )->willReturn (reject (new \RuntimeException ()));
44
49
$ this ->factory ->createLazyClient ('localhost:1337 ' );
45
50
}
46
51
47
52
public function testWillResolveIfConnectorResolves ()
48
53
{
49
- $ stream = $ this ->getMockBuilder ( ' React\Socket\ ConnectionInterface' )-> getMock ( );
54
+ $ stream = $ this ->createMock ( ConnectionInterface::class );
50
55
$ stream ->expects ($ this ->never ())->method ('write ' );
51
56
52
- $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->willReturn (Promise \ resolve ($ stream ));
57
+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->willReturn (resolve ($ stream ));
53
58
$ redis = $ this ->factory ->createLazyClient ('localhost ' );
54
59
55
- $ this ->assertInstanceOf (' Clue\React\Redis\ Client' , $ redis );
60
+ $ this ->assertInstanceOf (Client::class , $ redis );
56
61
}
57
62
58
63
public function testWillWriteSelectCommandIfTargetContainsPath ()
59
64
{
60
- $ stream = $ this ->getMockBuilder ( ' React\Socket\ ConnectionInterface' )-> getMock ( );
65
+ $ stream = $ this ->createMock ( ConnectionInterface::class );
61
66
$ stream ->expects ($ this ->never ())->method ('write ' )->with ("*2 \r\n$6 \r\nselect \r\n$4 \r\ndemo \r\n" );
62
67
63
- $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->willReturn (Promise \ resolve ($ stream ));
68
+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->willReturn (resolve ($ stream ));
64
69
$ this ->factory ->createLazyClient ('redis://127.0.0.1/demo ' );
65
70
}
66
71
67
72
public function testWillWriteSelectCommandIfTargetContainsDbQueryParameter ()
68
73
{
69
- $ stream = $ this ->getMockBuilder ( ' React\Socket\ ConnectionInterface' )-> getMock ( );
74
+ $ stream = $ this ->createMock ( ConnectionInterface::class );
70
75
$ stream ->expects ($ this ->never ())->method ('write ' )->with ("*2 \r\n$6 \r\nselect \r\n$1 \r\n4 \r\n" );
71
76
72
- $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->willReturn (Promise \ resolve ($ stream ));
77
+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->willReturn (resolve ($ stream ));
73
78
$ this ->factory ->createLazyClient ('redis://127.0.0.1?db=4 ' );
74
79
}
75
80
76
81
public function testWillWriteAuthCommandIfRedisUriContainsUserInfo ()
77
82
{
78
- $ stream = $ this ->getMockBuilder ( ' React\Socket\ ConnectionInterface' )-> getMock ( );
83
+ $ stream = $ this ->createMock ( ConnectionInterface::class );
79
84
$ stream ->expects ($ this ->never ())->method ('write ' )->with ("*2 \r\n$4 \r\nauth \r\n$5 \r\nworld \r\n" );
80
85
81
- $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('example.com:6379 ' )->willReturn (Promise \ resolve ($ stream ));
86
+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('example.com:6379 ' )->willReturn (resolve ($ stream ));
82
87
$ this ->
factory ->
createLazyClient (
'redis://hello:[email protected] ' );
83
88
}
84
89
85
90
public function testWillWriteAuthCommandIfRedisUriContainsEncodedUserInfo ()
86
91
{
87
- $ stream = $ this ->getMockBuilder ( ' React\Socket\ ConnectionInterface' )-> getMock ( );
92
+ $ stream = $ this ->createMock ( ConnectionInterface::class );
88
93
$ stream ->expects ($ this ->never ())->method ('write ' )->with ("*2 \r\n$4 \r\nauth \r\n$5 \r\nh@llo \r\n" );
89
94
90
- $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('example.com:6379 ' )->willReturn (Promise \ resolve ($ stream ));
95
+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('example.com:6379 ' )->willReturn (resolve ($ stream ));
91
96
$ this ->
factory ->
createLazyClient (
'redis://:h%[email protected] ' );
92
97
}
93
98
94
99
public function testWillWriteAuthCommandIfTargetContainsPasswordQueryParameter ()
95
100
{
96
- $ stream = $ this ->getMockBuilder ( ' React\Socket\ ConnectionInterface' )-> getMock ( );
101
+ $ stream = $ this ->createMock ( ConnectionInterface::class );
97
102
$ stream ->expects ($ this ->never ())->method ('write ' )->with ("*2 \r\n$4 \r\nauth \r\n$6 \r\nsecret \r\n" );
98
103
99
- $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('example.com:6379 ' )->willReturn (Promise \ resolve ($ stream ));
104
+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('example.com:6379 ' )->willReturn (resolve ($ stream ));
100
105
$ this ->factory ->createLazyClient ('redis://example.com?password=secret ' );
101
106
}
102
107
103
108
public function testWillWriteAuthCommandIfTargetContainsEncodedPasswordQueryParameter ()
104
109
{
105
- $ stream = $ this ->getMockBuilder ( ' React\Socket\ ConnectionInterface' )-> getMock ( );
110
+ $ stream = $ this ->createMock ( ConnectionInterface::class );
106
111
$ stream ->expects ($ this ->never ())->method ('write ' )->with ("*2 \r\n$4 \r\nauth \r\n$5 \r\nh@llo \r\n" );
107
112
108
- $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('example.com:6379 ' )->willReturn (Promise \ resolve ($ stream ));
113
+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('example.com:6379 ' )->willReturn (resolve ($ stream ));
109
114
$ this ->factory ->createLazyClient ('redis://example.com?password=h%40llo ' );
110
115
}
111
116
112
117
public function testWillWriteAuthCommandIfRedissUriContainsUserInfo ()
113
118
{
114
- $ stream = $ this ->getMockBuilder ( ' React\Socket\ ConnectionInterface' )-> getMock ( );
119
+ $ stream = $ this ->createMock ( ConnectionInterface::class );
115
120
$ stream ->expects ($ this ->never ())->method ('write ' )->with ("*2 \r\n$4 \r\nauth \r\n$5 \r\nworld \r\n" );
116
121
117
- $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('tls://example.com:6379 ' )->willReturn (Promise \ resolve ($ stream ));
122
+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('tls://example.com:6379 ' )->willReturn (resolve ($ stream ));
118
123
$ this ->
factory ->
createLazyClient (
'rediss://hello:[email protected] ' );
119
124
}
120
125
121
126
public function testWillWriteAuthCommandIfRedisUnixUriContainsPasswordQueryParameter ()
122
127
{
123
- $ stream = $ this ->getMockBuilder ( ' React\Socket\ ConnectionInterface' )-> getMock ( );
128
+ $ stream = $ this ->createMock ( ConnectionInterface::class );
124
129
$ stream ->expects ($ this ->never ())->method ('write ' )->with ("*2 \r\n$4 \r\nauth \r\n$5 \r\nworld \r\n" );
125
130
126
- $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('unix:///tmp/redis.sock ' )->willReturn (Promise \ resolve ($ stream ));
131
+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('unix:///tmp/redis.sock ' )->willReturn (resolve ($ stream ));
127
132
$ this ->factory ->createLazyClient ('redis+unix:///tmp/redis.sock?password=world ' );
128
133
}
129
134
130
135
public function testWillWriteAuthCommandIfRedisUnixUriContainsUserInfo ()
131
136
{
132
- $ stream = $ this ->getMockBuilder ( ' React\Socket\ ConnectionInterface' )-> getMock ( );
137
+ $ stream = $ this ->createMock ( ConnectionInterface::class );
133
138
$ stream ->expects ($ this ->never ())->method ('write ' )->with ("*2 \r\n$4 \r\nauth \r\n$5 \r\nworld \r\n" );
134
139
135
- $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('unix:///tmp/redis.sock ' )->willReturn (Promise \ resolve ($ stream ));
140
+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('unix:///tmp/redis.sock ' )->willReturn (resolve ($ stream ));
136
141
$ this ->factory ->createLazyClient ('redis+unix://hello:world@/tmp/redis.sock ' );
137
142
}
138
143
139
144
public function testWillWriteSelectCommandIfRedisUnixUriContainsDbQueryParameter ()
140
145
{
141
- $ stream = $ this ->getMockBuilder ( ' React\Socket\ ConnectionInterface' )-> getMock ( );
146
+ $ stream = $ this ->createMock ( ConnectionInterface::class );
142
147
$ stream ->expects ($ this ->never ())->method ('write ' )->with ("*2 \r\n$6 \r\nselect \r\n$4 \r\ndemo \r\n" );
143
148
144
- $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('unix:///tmp/redis.sock ' )->willReturn (Promise \ resolve ($ stream ));
149
+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('unix:///tmp/redis.sock ' )->willReturn (resolve ($ stream ));
145
150
$ this ->factory ->createLazyClient ('redis+unix:///tmp/redis.sock?db=demo ' );
146
151
}
147
152
148
153
public function testWillRejectIfConnectorRejects ()
149
154
{
150
- $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('127.0.0.1:2 ' )->willReturn (Promise \ reject (new \RuntimeException ()));
155
+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' )->with ('127.0.0.1:2 ' )->willReturn (reject (new \RuntimeException ()));
151
156
$ redis = $ this ->factory ->createLazyClient ('redis://127.0.0.1:2 ' );
152
157
153
- $ this ->assertInstanceOf (' Clue\React\Redis\ Client' , $ redis );
158
+ $ this ->assertInstanceOf (Client::class , $ redis );
154
159
}
155
160
156
161
public function testWillRejectIfTargetIsInvalid ()
157
162
{
158
163
$ redis = $ this ->factory ->createLazyClient ('http://invalid target ' );
159
164
160
- $ this ->assertInstanceOf (' Clue\React\Redis\ Client' , $ redis );
165
+ $ this ->assertInstanceOf (Client::class , $ redis );
161
166
}
162
167
}
0 commit comments