@@ -81,29 +81,55 @@ public function testRejectsImmediatelyIfUriIsInvalid()
8181 $ promise ->then ($ this ->expectCallableNever (), $ this ->expectCallableOnce ());
8282 }
8383
84- public function testRejectsWithTcpConnectorRejectionIfGivenIp ()
84+ public function testConnectRejectsIfGivenIpAndTcpConnectorRejectsWithRuntimeException ()
8585 {
86- $ promise = Promise \reject (new \RuntimeException ('Connection failed ' ));
86+ $ promise = Promise \reject (new \RuntimeException ('Connection to tcp://1.2.3.4:80 failed: Connection failed ' , 42 ));
8787 $ this ->resolver ->expects ($ this ->never ())->method ('resolve ' );
88- $ this ->tcp ->expects ($ this ->once ())->method ('connect ' )->with ($ this -> equalTo ( '1.2.3.4:80 ' ) )->willReturn ($ promise );
88+ $ this ->tcp ->expects ($ this ->once ())->method ('connect ' )->with ('1.2.3.4:80 ' )->willReturn ($ promise );
8989
9090 $ promise = $ this ->connector ->connect ('1.2.3.4:80 ' );
9191 $ promise ->cancel ();
9292
93- $ this ->setExpectedException ('RuntimeException ' , 'Connection failed ' );
93+ $ this ->setExpectedException ('RuntimeException ' , 'Connection to tcp://1.2.3.4:80 failed: Connection failed ' , 42 );
9494 $ this ->throwRejection ($ promise );
9595 }
9696
97- public function testRejectsWithTcpConnectorRejectionAfterDnsIsResolved ()
97+ public function testConnectRejectsIfGivenIpAndTcpConnectorRejectsWithInvalidArgumentException ()
9898 {
99- $ promise = Promise \reject (new \RuntimeException ('Connection failed ' ));
100- $ this ->resolver ->expects ($ this ->once ())->method ('resolve ' )->with ($ this ->equalTo ('example.com ' ))->willReturn (Promise \resolve ('1.2.3.4 ' ));
101- $ this ->tcp ->expects ($ this ->once ())->method ('connect ' )->with ($ this ->equalTo ('1.2.3.4:80?hostname=example.com ' ))->willReturn ($ promise );
99+ $ promise = Promise \reject (new \InvalidArgumentException ('Invalid ' , 42 ));
100+ $ this ->resolver ->expects ($ this ->never ())->method ('resolve ' );
101+ $ this ->tcp ->expects ($ this ->once ())->method ('connect ' )->with ('1.2.3.4:80 ' )->willReturn ($ promise );
102+
103+ $ promise = $ this ->connector ->connect ('1.2.3.4:80 ' );
104+ $ promise ->cancel ();
105+
106+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Invalid ' , 42 );
107+ $ this ->throwRejection ($ promise );
108+ }
109+
110+ public function testConnectRejectsWithOriginalHostnameInMessageAfterResolvingIfTcpConnectorRejectsWithRuntimeException ()
111+ {
112+ $ promise = Promise \reject (new \RuntimeException ('Connection to tcp://1.2.3.4:80?hostname=example.com failed: Connection failed ' , 42 ));
113+ $ this ->resolver ->expects ($ this ->once ())->method ('resolve ' )->with ('example.com ' )->willReturn (Promise \resolve ('1.2.3.4 ' ));
114+ $ this ->tcp ->expects ($ this ->once ())->method ('connect ' )->with ('1.2.3.4:80?hostname=example.com ' )->willReturn ($ promise );
115+
116+ $ promise = $ this ->connector ->connect ('example.com:80 ' );
117+ $ promise ->cancel ();
118+
119+ $ this ->setExpectedException ('RuntimeException ' , 'Connection to example.com:80 failed: Connection to tcp://1.2.3.4:80 failed: Connection failed ' , 42 );
120+ $ this ->throwRejection ($ promise );
121+ }
122+
123+ public function testConnectRejectsWithOriginalExceptionAfterResolvingIfTcpConnectorRejectsWithInvalidArgumentException ()
124+ {
125+ $ promise = Promise \reject (new \InvalidArgumentException ('Invalid ' , 42 ));
126+ $ this ->resolver ->expects ($ this ->once ())->method ('resolve ' )->with ('example.com ' )->willReturn (Promise \resolve ('1.2.3.4 ' ));
127+ $ this ->tcp ->expects ($ this ->once ())->method ('connect ' )->with ('1.2.3.4:80?hostname=example.com ' )->willReturn ($ promise );
102128
103129 $ promise = $ this ->connector ->connect ('example.com:80 ' );
104130 $ promise ->cancel ();
105131
106- $ this ->setExpectedException ('RuntimeException ' , 'Connection failed ' );
132+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Invalid ' , 42 );
107133 $ this ->throwRejection ($ promise );
108134 }
109135
0 commit comments