1010 */
1111namespace Test \Unit \Client ;
1212
13- include_once (__DIR__ . '/../GlobalFunctionMock.php ' );
14-
13+ use ExtraMocks \Mocks ;
1514use RedisClient \Client \AbstractRedisClient ;
1615use RedisClient \Exception \MovedResponseException ;
1716use RedisClient \RedisClient ;
18- use Test \Unit \GlobalFunctionMock ;
1917
2018/**
2119 * @see AbstractRedisClient
2220 * @runTestsInSeparateProcesses
21+ * @runInSeparateProcess
2322 */
2423class AbstractRedisClientIsolatedTest extends \PHPUnit_Framework_TestCase {
2524
@@ -28,38 +27,38 @@ public function setUp() {
2827 }
2928
3029 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 ;});
3736 }
3837
3938 public function test_mockStream () {
40- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fgets ' , function () {
39+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fgets ' , function () {
4140 return "+TEST \r\n" ;
4241 });
4342
4443 $ Redis = new RedisClient ();
4544 $ this ->assertSame ('TEST ' , $ Redis ->ping ());
4645 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 ' ));
5352 }
5453
5554 public function test_MovedErrorResponse () {
56- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fwrite ' , function ($ h , $ m , $ c ) {
55+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fwrite ' , function ($ h , $ m , $ c ) {
5756 $ this ->assertSame ('tcp://127.0.0.1:6379 ' , $ h );
5857 $ this ->assertSame ("*2 \r\n\$3 \r\nGET \r\n\$3 \r\nkey \r\n" , $ m );
5958 $ this ->assertSame (22 , $ c );
6059 return $ c ;
6160 });
62- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fgets ' , function () {
61+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fgets ' , function () {
6362 return "-MOVED 42 server \r\n" ;
6463 });
6564
@@ -74,15 +73,15 @@ public function test_MovedErrorResponse() {
7473 $ this ->assertSame ('server ' , $ Ex ->getServer ());
7574 }
7675
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 ' ));
8281 }
8382
8483 public function test_ClusterEmptyMovedErrorResponse () {
85- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fwrite ' , function ($ h , $ m , $ c ) {
84+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fwrite ' , function ($ h , $ m , $ c ) {
8685 static $ data = [
8786 ['tcp://127.0.0.1:7001 ' , "*2 \r\n\$3 \r\nGET \r\n\$3 \r\nfoo \r\n" ],
8887 ['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() {
9796 return $ c ;
9897 });
9998
100- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fgets ' , function () {
99+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fgets ' , function () {
101100 static $ data = [
102101 "-MOVED 12182 127.0.0.3:7003 \r\n" ,
103102 "\$3 \r\n" ,
@@ -110,7 +109,7 @@ public function test_ClusterEmptyMovedErrorResponse() {
110109 return $ datum ;
111110 });
112111
113- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fread ' , function () {
112+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fread ' , function () {
114113 static $ data = [
115114 "bar \r\n" ,
116115 "bar1 \r\n" ,
@@ -134,26 +133,26 @@ public function test_ClusterEmptyMovedErrorResponse() {
134133 $ this ->assertSame ('bar2 ' , $ Redis ->get ('foo2 ' ));
135134 $ this ->assertSame ('bar3 ' , $ Redis ->get ('foo2 ' ));
136135
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 ' ));
142141 }
143142
144143 public function test_ClusterFullMovedErrorResponse () {
145- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fwrite ' , function ($ h , $ m , $ c ) {
144+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fwrite ' , function ($ h , $ m , $ c ) {
146145 $ this ->assertSame ('tcp://127.0.0.3:7003 ' , $ h );
147146 $ this ->assertSame ("*2 \r\n\$3 \r\nGET \r\n\$3 \r\nfoo \r\n" , $ m );
148147 $ this ->assertSame (22 , $ c );
149148 return $ c ;
150149 });
151150
152- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fgets ' , function () {
151+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fgets ' , function () {
153152 return "\$3 \r\n" ;
154153 });
155154
156- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fread ' , function () {
155+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fread ' , function () {
157156 return "bar \r\n" ;
158157 });
159158
@@ -171,15 +170,15 @@ public function test_ClusterFullMovedErrorResponse() {
171170
172171 $ this ->assertSame ('bar ' , $ Redis ->get ('foo ' ));
173172
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 ' ));
179178 }
180179
181180 public function test_ClusterFullAskErrorResponse () {
182- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fwrite ' , function ($ h , $ m , $ c ) {
181+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fwrite ' , function ($ h , $ m , $ c ) {
183182 static $ data = [
184183 [
185184 'tcp://127.0.0.3:7003 ' ,
@@ -204,7 +203,7 @@ public function test_ClusterFullAskErrorResponse() {
204203 return $ c ;
205204 });
206205
207- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fgets ' , function () {
206+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fgets ' , function () {
208207 static $ data = [
209208 "-ASK 12182 127.0.0.2:7002 \r\n" ,
210209 "+OK \r\n" ,
@@ -214,7 +213,7 @@ public function test_ClusterFullAskErrorResponse() {
214213 return array_shift ($ data );
215214 });
216215
217- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fread ' , function () {
216+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fread ' , function () {
218217 static $ data = [
219218 "bar \r\n" ,
220219 "bar-bar \r\n"
@@ -237,15 +236,15 @@ public function test_ClusterFullAskErrorResponse() {
237236 $ this ->assertSame ('bar ' , $ Redis ->get ('foo ' ));
238237 $ this ->assertSame ('bar-bar ' , $ Redis ->get ('foo ' ));
239238
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 ' ));
245244 }
246245
247246 public function test_ClusterEmptyMixResponse () {
248- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fwrite ' , function ($ h , $ m , $ c ) {
247+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fwrite ' , function ($ h , $ m , $ c ) {
249248 static $ data = [
250249 ['tcp://127.0.0.1:7001 ' , "*2 \r\n\$3 \r\nGET \r\n\$3 \r\nfoo \r\n" ],
251250 ['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() {
264263 return $ c ;
265264 });
266265
267- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fgets ' , function () {
266+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fgets ' , function () {
268267 static $ data = [
269268 "-MOVED 12182 127.0.0.3:7003 \r\n" ,
270269 "-ASK 12182 127.0.0.2:7002 \r\n" ,
@@ -281,7 +280,7 @@ public function test_ClusterEmptyMixResponse() {
281280 return $ datum ;
282281 });
283282
284- GlobalFunctionMock:: mockFunction ( ' RedisClient\Connection:: fread ' , function () {
283+ Mocks:: mockGlobalFunction ( ' \ RedisClient\Connection\ fread ' , function () {
285284 static $ data = [
286285 "bar \r\n" ,
287286 "bar1 \r\n" ,
@@ -309,10 +308,10 @@ public function test_ClusterEmptyMixResponse() {
309308 $ this ->assertSame ('bar4 ' , $ Redis ->get ('foo2 ' ));
310309 $ this ->assertSame ('bar5 ' , $ Redis ->get ('foo1 ' ));
311310
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 ' ));
317316 }
318317}
0 commit comments