1
1
<?php
2
2
3
+ namespace Clue \Tests \React \Redis ;
4
+
3
5
use Clue \React \Block ;
6
+ use Clue \React \Redis \Client ;
4
7
use Clue \React \Redis \Factory ;
5
8
use Clue \React \Redis \StreamingClient ;
9
+ use React \EventLoop \StreamSelectLoop ;
6
10
use React \Promise \Deferred ;
7
- use React \Stream \Stream ;
8
11
use React \Stream \DuplexResourceStream ;
9
12
10
13
class FunctionalTest extends TestCase
@@ -20,7 +23,7 @@ public function setUp()
20
23
$ this ->markTestSkipped ('No REDIS_URI environment variable given ' );
21
24
}
22
25
23
- $ this ->loop = new React \ EventLoop \ StreamSelectLoop ();
26
+ $ this ->loop = new StreamSelectLoop ();
24
27
$ this ->factory = new Factory ($ this ->loop );
25
28
$ this ->client = $ this ->createClient ($ uri );
26
29
}
@@ -55,10 +58,10 @@ public function testPipeline()
55
58
{
56
59
$ client = $ this ->client ;
57
60
58
- $ client ->set ('a ' , 1 )->then ($ this ->expectCallableOnce ('OK ' ));
59
- $ client ->incr ('a ' )->then ($ this ->expectCallableOnce (2 ));
60
- $ client ->incr ('a ' )->then ($ this ->expectCallableOnce (3 ));
61
- $ promise = $ client ->get ('a ' )->then ($ this ->expectCallableOnce ('3 ' ));
61
+ $ client ->set ('a ' , 1 )->then ($ this ->expectCallableOnceWith ('OK ' ));
62
+ $ client ->incr ('a ' )->then ($ this ->expectCallableOnceWith (2 ));
63
+ $ client ->incr ('a ' )->then ($ this ->expectCallableOnceWith (3 ));
64
+ $ promise = $ client ->get ('a ' )->then ($ this ->expectCallableOnceWith ('3 ' ));
62
65
63
66
Block \await ($ promise , $ this ->loop );
64
67
}
@@ -73,8 +76,8 @@ public function testInvalidCommand()
73
76
74
77
public function testMultiExecEmpty ()
75
78
{
76
- $ this ->client ->multi ()->then ($ this ->expectCallableOnce ('OK ' ));
77
- $ promise = $ this ->client ->exec ()->then ($ this ->expectCallableOnce (array ()));
79
+ $ this ->client ->multi ()->then ($ this ->expectCallableOnceWith ('OK ' ));
80
+ $ promise = $ this ->client ->exec ()->then ($ this ->expectCallableOnceWith (array ()));
78
81
79
82
Block \await ($ promise , $ this ->loop );
80
83
}
@@ -83,12 +86,12 @@ public function testMultiExecQueuedExecHasValues()
83
86
{
84
87
$ client = $ this ->client ;
85
88
86
- $ client ->multi ()->then ($ this ->expectCallableOnce ('OK ' ));
87
- $ client ->set ('b ' , 10 )->then ($ this ->expectCallableOnce ('QUEUED ' ));
88
- $ client ->expire ('b ' , 20 )->then ($ this ->expectCallableOnce ('QUEUED ' ));
89
- $ client ->incrBy ('b ' , 2 )->then ($ this ->expectCallableOnce ('QUEUED ' ));
90
- $ client ->ttl ('b ' )->then ($ this ->expectCallableOnce ('QUEUED ' ));
91
- $ promise = $ client ->exec ()->then ($ this ->expectCallableOnce (array ('OK ' , 1 , 12 , 20 )));
89
+ $ client ->multi ()->then ($ this ->expectCallableOnceWith ('OK ' ));
90
+ $ client ->set ('b ' , 10 )->then ($ this ->expectCallableOnceWith ('QUEUED ' ));
91
+ $ client ->expire ('b ' , 20 )->then ($ this ->expectCallableOnceWith ('QUEUED ' ));
92
+ $ client ->incrBy ('b ' , 2 )->then ($ this ->expectCallableOnceWith ('QUEUED ' ));
93
+ $ client ->ttl ('b ' )->then ($ this ->expectCallableOnceWith ('QUEUED ' ));
94
+ $ promise = $ client ->exec ()->then ($ this ->expectCallableOnceWith (array ('OK ' , 1 , 12 , 20 )));
92
95
93
96
Block \await ($ promise , $ this ->loop );
94
97
}
@@ -107,19 +110,19 @@ public function testPubSub()
107
110
$ consumer ->subscribe ($ channel )->then ($ this ->expectCallableOnce ());
108
111
109
112
// producer sends a single message
110
- $ producer ->publish ($ channel , 'hello world ' )->then ($ this ->expectCallableOnce (1 ));
113
+ $ producer ->publish ($ channel , 'hello world ' )->then ($ this ->expectCallableOnceWith (1 ));
111
114
112
115
// expect "message" event to take no longer than 0.1s
113
116
Block \await ($ deferred ->promise (), $ this ->loop , 0.1 );
114
117
}
115
118
116
119
public function testClose ()
117
120
{
118
- $ this ->client ->get ('willBeCanceledAnyway ' )->then (null , $ this ->expectCallableOnce ());
121
+ $ this ->client ->get ('willBeCanceledAnyway ' )->then (null , $ this ->expectCallableOnceWith ());
119
122
120
123
$ this ->client ->close ();
121
124
122
- $ this ->client ->get ('willBeRejectedRightAway ' )->then (null , $ this ->expectCallableOnce ());
125
+ $ this ->client ->get ('willBeRejectedRightAway ' )->then (null , $ this ->expectCallableOnceWith ());
123
126
}
124
127
125
128
public function testInvalidProtocol ()
@@ -142,7 +145,7 @@ public function testInvalidServerRepliesWithDuplicateMessages()
142
145
$ client ->on ('error ' , $ this ->expectCallableOnce ());
143
146
$ client ->on ('close ' , $ this ->expectCallableOnce ());
144
147
145
- $ promise = $ client ->set ('a ' , 0 )->then ($ this ->expectCallableOnce ('OK ' ));
148
+ $ promise = $ client ->set ('a ' , 0 )->then ($ this ->expectCallableOnceWith ('OK ' ));
146
149
147
150
Block \await ($ promise , $ this ->loop );
148
151
}
@@ -162,15 +165,8 @@ protected function createClientResponse($response)
162
165
fwrite ($ fp , $ response );
163
166
fseek ($ fp , 0 );
164
167
165
- $ stream = class_exists ( ' React\Stream\DuplexResourceStream ' ) ? new DuplexResourceStream ( $ fp , $ this -> loop ) : new Stream ($ fp , $ this ->loop );
168
+ $ stream = new DuplexResourceStream ($ fp , $ this ->loop );
166
169
167
170
return new StreamingClient ($ stream );
168
171
}
169
-
170
- protected function createServer ($ response )
171
- {
172
- $ port = 1337 ;
173
- $ cmd = 'echo -e " ' . str_replace ("\r\n" , '\r\n ' , $ response ) . '" | nc -lC ' . $ port ;
174
-
175
- }
176
172
}
0 commit comments