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
}
@@ -77,8 +80,8 @@ public function testInvalidCommand()
77
80
78
81
public function testMultiExecEmpty ()
79
82
{
80
- $ this ->client ->multi ()->then ($ this ->expectCallableOnce ('OK ' ));
81
- $ promise = $ this ->client ->exec ()->then ($ this ->expectCallableOnce (array ()));
83
+ $ this ->client ->multi ()->then ($ this ->expectCallableOnceWith ('OK ' ));
84
+ $ promise = $ this ->client ->exec ()->then ($ this ->expectCallableOnceWith (array ()));
82
85
83
86
Block \await ($ promise , $ this ->loop );
84
87
}
@@ -87,12 +90,12 @@ public function testMultiExecQueuedExecHasValues()
87
90
{
88
91
$ client = $ this ->client ;
89
92
90
- $ client ->multi ()->then ($ this ->expectCallableOnce ('OK ' ));
91
- $ client ->set ('b ' , 10 )->then ($ this ->expectCallableOnce ('QUEUED ' ));
92
- $ client ->expire ('b ' , 20 )->then ($ this ->expectCallableOnce ('QUEUED ' ));
93
- $ client ->incrBy ('b ' , 2 )->then ($ this ->expectCallableOnce ('QUEUED ' ));
94
- $ client ->ttl ('b ' )->then ($ this ->expectCallableOnce ('QUEUED ' ));
95
- $ promise = $ client ->exec ()->then ($ this ->expectCallableOnce (array ('OK ' , 1 , 12 , 20 )));
93
+ $ client ->multi ()->then ($ this ->expectCallableOnceWith ('OK ' ));
94
+ $ client ->set ('b ' , 10 )->then ($ this ->expectCallableOnceWith ('QUEUED ' ));
95
+ $ client ->expire ('b ' , 20 )->then ($ this ->expectCallableOnceWith ('QUEUED ' ));
96
+ $ client ->incrBy ('b ' , 2 )->then ($ this ->expectCallableOnceWith ('QUEUED ' ));
97
+ $ client ->ttl ('b ' )->then ($ this ->expectCallableOnceWith ('QUEUED ' ));
98
+ $ promise = $ client ->exec ()->then ($ this ->expectCallableOnceWith (array ('OK ' , 1 , 12 , 20 )));
96
99
97
100
Block \await ($ promise , $ this ->loop );
98
101
}
@@ -111,7 +114,7 @@ public function testPubSub()
111
114
$ consumer ->subscribe ($ channel )->then ($ this ->expectCallableOnce ());
112
115
113
116
// producer sends a single message
114
- $ producer ->publish ($ channel , 'hello world ' )->then ($ this ->expectCallableOnce (1 ));
117
+ $ producer ->publish ($ channel , 'hello world ' )->then ($ this ->expectCallableOnceWith (1 ));
115
118
116
119
// expect "message" event to take no longer than 0.1s
117
120
Block \await ($ deferred ->promise (), $ this ->loop , 0.1 );
@@ -150,7 +153,7 @@ public function testInvalidServerRepliesWithDuplicateMessages()
150
153
$ client ->on ('error ' , $ this ->expectCallableOnce ());
151
154
$ client ->on ('close ' , $ this ->expectCallableOnce ());
152
155
153
- $ promise = $ client ->set ('a ' , 0 )->then ($ this ->expectCallableOnce ('OK ' ));
156
+ $ promise = $ client ->set ('a ' , 0 )->then ($ this ->expectCallableOnceWith ('OK ' ));
154
157
155
158
Block \await ($ promise , $ this ->loop );
156
159
}
@@ -170,15 +173,8 @@ protected function createClientResponse($response)
170
173
fwrite ($ fp , $ response );
171
174
fseek ($ fp , 0 );
172
175
173
- $ stream = class_exists ( ' React\Stream\DuplexResourceStream ' ) ? new DuplexResourceStream ( $ fp , $ this -> loop ) : new Stream ($ fp , $ this ->loop );
176
+ $ stream = new DuplexResourceStream ($ fp , $ this ->loop );
174
177
175
178
return new StreamingClient ($ stream );
176
179
}
177
-
178
- protected function createServer ($ response )
179
- {
180
- $ port = 1337 ;
181
- $ cmd = 'echo -e " ' . str_replace ("\r\n" , '\r\n ' , $ response ) . '" | nc -lC ' . $ port ;
182
-
183
- }
184
180
}
0 commit comments