File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33use React \Datagram \Socket ;
44use React \Datagram \Factory ;
55use Clue \React \Block ;
6+ use React \Promise ;
67
78class FactoryTest extends TestCase
89{
@@ -69,6 +70,38 @@ public function testCreateServerRandomPort()
6970 $ capturedServer ->close ();
7071 }
7172
73+ public function testCreateClientWithIpWillNotUseResolver ()
74+ {
75+ $ this ->resolver ->expects ($ this ->never ())->method ('resolve ' );
76+
77+ $ client = Block \await ($ this ->factory ->createClient ('127.0.0.1:0 ' ), $ this ->loop );
78+ $ client ->close ();
79+ }
80+
81+ public function testCreateClientWithHostnameWillUseResolver ()
82+ {
83+ $ this ->resolver ->expects ($ this ->once ())->method ('resolve ' )->with ('example.com ' )->willReturn (Promise \resolve ('127.0.0.1 ' ));
84+
85+ $ client = Block \await ($ this ->factory ->createClient ('example.com:0 ' ), $ this ->loop );
86+ $ client ->close ();
87+ }
88+
89+ public function testCreateClientWithHostnameWillRejectIfResolverRejects ()
90+ {
91+ $ this ->resolver ->expects ($ this ->once ())->method ('resolve ' )->with ('example.com ' )->willReturn (Promise \reject (new \RuntimeException ('test ' )));
92+
93+ $ this ->setExpectedException ('RuntimeException ' );
94+ Block \await ($ this ->factory ->createClient ('example.com:0 ' ), $ this ->loop );
95+ }
96+
97+ public function testCreateClientWithHostnameWillRejectIfNoResolverIsGiven ()
98+ {
99+ $ this ->factory = new Factory ($ this ->loop );
100+
101+ $ this ->setExpectedException ('Exception ' );
102+ Block \await ($ this ->factory ->createClient ('example.com:0 ' ), $ this ->loop );
103+ }
104+
72105 /**
73106 * @expectedException Exception
74107 * @expectedExceptionMessage Unable to create client socket
You can’t perform that action at this time.
0 commit comments