10
10
*/
11
11
namespace Test \Unit \Client ;
12
12
13
- include_once (__DIR__ . '/../GlobalFunctionMock.php ' );
14
-
13
+ use ExtraMocks \Mocks ;
15
14
use RedisClient \Client \AbstractRedisClient ;
16
15
use RedisClient \Exception \MovedResponseException ;
17
16
use RedisClient \RedisClient ;
18
- use Test \Unit \GlobalFunctionMock ;
19
17
20
18
/**
21
19
* @see AbstractRedisClient
22
20
* @runTestsInSeparateProcesses
21
+ * @runInSeparateProcess
23
22
*/
24
23
class AbstractRedisClientIsolatedTest extends \PHPUnit_Framework_TestCase {
25
24
@@ -28,38 +27,38 @@ public function setUp() {
28
27
}
29
28
30
29
protected function mockStream () {
31
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: stream_socket_client ' , function ($ s ) {return $ s ;});
32
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: stream_set_timeout ' , function () {return true ;});
33
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fwrite ' , function ($ h , $ m , $ c ) {return $ c ;});
34
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fgets ' , function () {return '' ;});
35
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fread ' , function () {return '' ;});
36
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fclose ' , function () {return true ;});
30
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ stream_socket_client ' , function ($ s ) {return $ s ;});
31
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ stream_set_timeout ' , function () {return true ;});
32
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fwrite ' , function ($ h , $ m , $ c ) {return $ c ;});
33
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fgets ' , function () {return '' ;});
34
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fread ' , function () {return '' ;});
35
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fclose ' , function () {return true ;});
37
36
}
38
37
39
38
public function test_mockStream () {
40
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fgets ' , function () {
39
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fgets ' , function () {
41
40
return "+TEST \r\n" ;
42
41
});
43
42
44
43
$ Redis = new RedisClient ();
45
44
$ this ->assertSame ('TEST ' , $ Redis ->ping ());
46
45
unset($ Redis );
47
- $ this ->assertSame (1 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: stream_socket_client ' ));
48
- $ this ->assertSame (1 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: stream_set_timeout ' ));
49
- $ this ->assertSame (1 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fwrite ' ));
50
- $ this ->assertSame (1 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fgets ' ));
51
- $ this ->assertSame (0 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fread ' ));
52
- $ this ->assertSame (0 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fclose ' ));
46
+ $ this ->assertSame (1 , Mocks ::getCountCalls ('\ RedisClient\Connection\ stream_socket_client ' ));
47
+ $ this ->assertSame (1 , Mocks ::getCountCalls ('\ RedisClient\Connection\ stream_set_timeout ' ));
48
+ $ this ->assertSame (1 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fwrite ' ));
49
+ $ this ->assertSame (1 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fgets ' ));
50
+ $ this ->assertSame (0 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fread ' ));
51
+ $ this ->assertSame (0 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fclose ' ));
53
52
}
54
53
55
54
public function test_MovedErrorResponse () {
56
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fwrite ' , function ($ h , $ m , $ c ) {
55
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fwrite ' , function ($ h , $ m , $ c ) {
57
56
$ this ->assertSame ('tcp://127.0.0.1:6379 ' , $ h );
58
57
$ this ->assertSame ("*2 \r\n\$3 \r\nGET \r\n\$3 \r\nkey \r\n" , $ m );
59
58
$ this ->assertSame (22 , $ c );
60
59
return $ c ;
61
60
});
62
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fgets ' , function () {
61
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fgets ' , function () {
63
62
return "-MOVED 42 server \r\n" ;
64
63
});
65
64
@@ -74,15 +73,15 @@ public function test_MovedErrorResponse() {
74
73
$ this ->assertSame ('server ' , $ Ex ->getServer ());
75
74
}
76
75
77
- $ this ->assertSame (1 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: stream_socket_client ' ));
78
- $ this ->assertSame (1 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: stream_set_timeout ' ));
79
- $ this ->assertSame (1 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fwrite ' ));
80
- $ this ->assertSame (1 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fgets ' ));
81
- $ this ->assertSame (0 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fread ' ));
76
+ $ this ->assertSame (1 , Mocks ::getCountCalls ('\ RedisClient\Connection\ stream_socket_client ' ));
77
+ $ this ->assertSame (1 , Mocks ::getCountCalls ('\ RedisClient\Connection\ stream_set_timeout ' ));
78
+ $ this ->assertSame (1 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fwrite ' ));
79
+ $ this ->assertSame (1 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fgets ' ));
80
+ $ this ->assertSame (0 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fread ' ));
82
81
}
83
82
84
83
public function test_ClusterEmptyMovedErrorResponse () {
85
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fwrite ' , function ($ h , $ m , $ c ) {
84
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fwrite ' , function ($ h , $ m , $ c ) {
86
85
static $ data = [
87
86
['tcp://127.0.0.1:7001 ' , "*2 \r\n\$3 \r\nGET \r\n\$3 \r\nfoo \r\n" ],
88
87
['tcp://127.0.0.3:7003 ' , "*2 \r\n\$3 \r\nGET \r\n\$3 \r\nfoo \r\n" ],
@@ -97,7 +96,7 @@ public function test_ClusterEmptyMovedErrorResponse() {
97
96
return $ c ;
98
97
});
99
98
100
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fgets ' , function () {
99
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fgets ' , function () {
101
100
static $ data = [
102
101
"-MOVED 12182 127.0.0.3:7003 \r\n" ,
103
102
"\$3 \r\n" ,
@@ -110,7 +109,7 @@ public function test_ClusterEmptyMovedErrorResponse() {
110
109
return $ datum ;
111
110
});
112
111
113
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fread ' , function () {
112
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fread ' , function () {
114
113
static $ data = [
115
114
"bar \r\n" ,
116
115
"bar1 \r\n" ,
@@ -134,26 +133,26 @@ public function test_ClusterEmptyMovedErrorResponse() {
134
133
$ this ->assertSame ('bar2 ' , $ Redis ->get ('foo2 ' ));
135
134
$ this ->assertSame ('bar3 ' , $ Redis ->get ('foo2 ' ));
136
135
137
- $ this ->assertSame (2 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: stream_socket_client ' ));
138
- $ this ->assertSame (2 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: stream_set_timeout ' ));
139
- $ this ->assertSame (6 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fwrite ' ));
140
- $ this ->assertSame (6 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fgets ' ));
141
- $ this ->assertSame (4 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fread ' ));
136
+ $ this ->assertSame (2 , Mocks ::getCountCalls ('\ RedisClient\Connection\ stream_socket_client ' ));
137
+ $ this ->assertSame (2 , Mocks ::getCountCalls ('\ RedisClient\Connection\ stream_set_timeout ' ));
138
+ $ this ->assertSame (6 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fwrite ' ));
139
+ $ this ->assertSame (6 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fgets ' ));
140
+ $ this ->assertSame (4 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fread ' ));
142
141
}
143
142
144
143
public function test_ClusterFullMovedErrorResponse () {
145
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fwrite ' , function ($ h , $ m , $ c ) {
144
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fwrite ' , function ($ h , $ m , $ c ) {
146
145
$ this ->assertSame ('tcp://127.0.0.3:7003 ' , $ h );
147
146
$ this ->assertSame ("*2 \r\n\$3 \r\nGET \r\n\$3 \r\nfoo \r\n" , $ m );
148
147
$ this ->assertSame (22 , $ c );
149
148
return $ c ;
150
149
});
151
150
152
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fgets ' , function () {
151
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fgets ' , function () {
153
152
return "\$3 \r\n" ;
154
153
});
155
154
156
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fread ' , function () {
155
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fread ' , function () {
157
156
return "bar \r\n" ;
158
157
});
159
158
@@ -171,15 +170,15 @@ public function test_ClusterFullMovedErrorResponse() {
171
170
172
171
$ this ->assertSame ('bar ' , $ Redis ->get ('foo ' ));
173
172
174
- $ this ->assertSame (1 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: stream_socket_client ' ));
175
- $ this ->assertSame (1 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: stream_set_timeout ' ));
176
- $ this ->assertSame (1 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fwrite ' ));
177
- $ this ->assertSame (1 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fgets ' ));
178
- $ this ->assertSame (1 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fread ' ));
173
+ $ this ->assertSame (1 , Mocks ::getCountCalls ('\ RedisClient\Connection\ stream_socket_client ' ));
174
+ $ this ->assertSame (1 , Mocks ::getCountCalls ('\ RedisClient\Connection\ stream_set_timeout ' ));
175
+ $ this ->assertSame (1 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fwrite ' ));
176
+ $ this ->assertSame (1 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fgets ' ));
177
+ $ this ->assertSame (1 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fread ' ));
179
178
}
180
179
181
180
public function test_ClusterFullAskErrorResponse () {
182
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fwrite ' , function ($ h , $ m , $ c ) {
181
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fwrite ' , function ($ h , $ m , $ c ) {
183
182
static $ data = [
184
183
[
185
184
'tcp://127.0.0.3:7003 ' ,
@@ -204,7 +203,7 @@ public function test_ClusterFullAskErrorResponse() {
204
203
return $ c ;
205
204
});
206
205
207
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fgets ' , function () {
206
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fgets ' , function () {
208
207
static $ data = [
209
208
"-ASK 12182 127.0.0.2:7002 \r\n" ,
210
209
"+OK \r\n" ,
@@ -214,7 +213,7 @@ public function test_ClusterFullAskErrorResponse() {
214
213
return array_shift ($ data );
215
214
});
216
215
217
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fread ' , function () {
216
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fread ' , function () {
218
217
static $ data = [
219
218
"bar \r\n" ,
220
219
"bar-bar \r\n"
@@ -237,15 +236,15 @@ public function test_ClusterFullAskErrorResponse() {
237
236
$ this ->assertSame ('bar ' , $ Redis ->get ('foo ' ));
238
237
$ this ->assertSame ('bar-bar ' , $ Redis ->get ('foo ' ));
239
238
240
- $ this ->assertSame (2 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: stream_socket_client ' ));
241
- $ this ->assertSame (2 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: stream_set_timeout ' ));
242
- $ this ->assertSame (4 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fwrite ' ));
243
- $ this ->assertSame (4 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fgets ' ));
244
- $ this ->assertSame (2 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fread ' ));
239
+ $ this ->assertSame (2 , Mocks ::getCountCalls ('\ RedisClient\Connection\ stream_socket_client ' ));
240
+ $ this ->assertSame (2 , Mocks ::getCountCalls ('\ RedisClient\Connection\ stream_set_timeout ' ));
241
+ $ this ->assertSame (4 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fwrite ' ));
242
+ $ this ->assertSame (4 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fgets ' ));
243
+ $ this ->assertSame (2 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fread ' ));
245
244
}
246
245
247
246
public function test_ClusterEmptyMixResponse () {
248
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fwrite ' , function ($ h , $ m , $ c ) {
247
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fwrite ' , function ($ h , $ m , $ c ) {
249
248
static $ data = [
250
249
['tcp://127.0.0.1:7001 ' , "*2 \r\n\$3 \r\nGET \r\n\$3 \r\nfoo \r\n" ],
251
250
['tcp://127.0.0.3:7003 ' , "*2 \r\n\$3 \r\nGET \r\n\$3 \r\nfoo \r\n" ],
@@ -264,7 +263,7 @@ public function test_ClusterEmptyMixResponse() {
264
263
return $ c ;
265
264
});
266
265
267
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fgets ' , function () {
266
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fgets ' , function () {
268
267
static $ data = [
269
268
"-MOVED 12182 127.0.0.3:7003 \r\n" ,
270
269
"-ASK 12182 127.0.0.2:7002 \r\n" ,
@@ -281,7 +280,7 @@ public function test_ClusterEmptyMixResponse() {
281
280
return $ datum ;
282
281
});
283
282
284
- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fread ' , function () {
283
+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fread ' , function () {
285
284
static $ data = [
286
285
"bar \r\n" ,
287
286
"bar1 \r\n" ,
@@ -309,10 +308,10 @@ public function test_ClusterEmptyMixResponse() {
309
308
$ this ->assertSame ('bar4 ' , $ Redis ->get ('foo2 ' ));
310
309
$ this ->assertSame ('bar5 ' , $ Redis ->get ('foo1 ' ));
311
310
312
- $ this ->assertSame (3 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: stream_socket_client ' ));
313
- $ this ->assertSame (3 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: stream_set_timeout ' ));
314
- $ this ->assertSame (10 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fwrite ' ));
315
- $ this ->assertSame (10 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fgets ' ));
316
- $ this ->assertSame (6 , GlobalFunctionMock ::getCountCalls ('RedisClient\Connection:: fread ' ));
311
+ $ this ->assertSame (3 , Mocks ::getCountCalls ('\ RedisClient\Connection\ stream_socket_client ' ));
312
+ $ this ->assertSame (3 , Mocks ::getCountCalls ('\ RedisClient\Connection\ stream_set_timeout ' ));
313
+ $ this ->assertSame (10 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fwrite ' ));
314
+ $ this ->assertSame (10 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fgets ' ));
315
+ $ this ->assertSame (6 , Mocks ::getCountCalls ('\ RedisClient\Connection\ fread ' ));
317
316
}
318
317
}
0 commit comments