@@ -23,6 +23,47 @@ public function testCtor()
2323 $ this ->factory = new Factory ($ this ->loop );
2424 }
2525
26+ public function testWillConnectWithDefaultPort ()
27+ {
28+ $ this ->connector ->expects ($ this ->once ())->method ('create ' )->with ('redis.example.com ' , 6379 )->willReturn (Promise \reject (new \RuntimeException ()));
29+ $ promise = $ this ->factory ->createClient ('redis.example.com ' );
30+ }
31+
32+ public function testWillConnectToLocalIpWhenTargetIsLocalhost ()
33+ {
34+ $ this ->connector ->expects ($ this ->once ())->method ('create ' )->with ('127.0.0.1 ' , 1337 )->willReturn (Promise \reject (new \RuntimeException ()));
35+ $ promise = $ this ->factory ->createClient ('tcp://localhost:1337 ' );
36+ }
37+
38+ public function testWillResolveIfConnectorResolves ()
39+ {
40+ $ stream = $ this ->getMockBuilder ('React\Stream\Stream ' )->disableOriginalConstructor ()->getMock ();
41+ $ stream ->expects ($ this ->never ())->method ('write ' );
42+
43+ $ this ->connector ->expects ($ this ->once ())->method ('create ' )->with ('127.0.0.1 ' , 2 )->willReturn (Promise \resolve ($ stream ));
44+ $ promise = $ this ->factory ->createClient ('tcp://127.0.0.1:2 ' );
45+
46+ $ this ->expectPromiseResolve ($ promise );
47+ }
48+
49+ public function testWillWriteSelectCommandIfTargetContainsPath ()
50+ {
51+ $ stream = $ this ->getMockBuilder ('React\Stream\Stream ' )->disableOriginalConstructor ()->getMock ();
52+ $ stream ->expects ($ this ->once ())->method ('write ' )->with ("*2 \r\n$6 \r\nselect \r\n$4 \r\ndemo \r\n" );
53+
54+ $ this ->connector ->expects ($ this ->once ())->method ('create ' )->willReturn (Promise \resolve ($ stream ));
55+ $ this ->factory ->createClient ('tcp://127.0.0.1/demo ' );
56+ }
57+
58+ public function testWillWriteAuthCommandIfTargetContainsUserInfo ()
59+ {
60+ $ stream = $ this ->getMockBuilder ('React\Stream\Stream ' )->disableOriginalConstructor ()->getMock ();
61+ $ stream ->expects ($ this ->once ())->method ('write ' )->with ("*2 \r\n$4 \r\nauth \r\n$11 \r\nhello:world \r\n" );
62+
63+ $ this ->connector ->expects ($ this ->once ())->method ('create ' )->willReturn (Promise \resolve ($ stream ));
64+ $ this ->factory ->createClient ('tcp://hello:world@127.0.0.1 ' );
65+ }
66+
2667 public function testWillRejectIfConnectorRejects ()
2768 {
2869 $ this ->connector ->expects ($ this ->once ())->method ('create ' )->with ('127.0.0.1 ' , 2 )->willReturn (Promise \reject (new \RuntimeException ()));
0 commit comments