@@ -68,6 +68,28 @@ public function testConnectionToInvalidSchemeWillReject()
6868 $ promise ->then (null , $ this ->expectCallableOnce ());
6969 }
7070
71+ public function testConnectWillRejectWithTlsUriWhenUnderlyingConnectorRejects ()
72+ {
73+ $ this ->tcp ->expects ($ this ->once ())->method ('connect ' )->with ('example.com:80 ' )->willReturn (\React \Promise \reject (new \RuntimeException ('Connection to tcp://example.com:80 failed: Connection refused ' , 42 )));
74+
75+ $ promise = $ this ->connector ->connect ('example.com:80 ' );
76+ $ promise ->cancel ();
77+
78+ $ this ->setExpectedException ('RuntimeException ' , 'Connection to tls://example.com:80 failed: Connection refused ' , 42 );
79+ $ this ->throwRejection ($ promise );
80+ }
81+
82+ public function testConnectWillRejectWithOriginalMessageWhenUnderlyingConnectorRejectsWithInvalidArgumentException ()
83+ {
84+ $ this ->tcp ->expects ($ this ->once ())->method ('connect ' )->with ('example.com:80 ' )->willReturn (\React \Promise \reject (new \InvalidArgumentException ('Invalid ' , 42 )));
85+
86+ $ promise = $ this ->connector ->connect ('example.com:80 ' );
87+ $ promise ->cancel ();
88+
89+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Invalid ' , 42 );
90+ $ this ->throwRejection ($ promise );
91+ }
92+
7193 public function testCancelDuringTcpConnectionCancelsTcpConnection ()
7294 {
7395 $ pending = new Promise \Promise (function () { }, $ this ->expectCallableOnce ());
@@ -79,13 +101,13 @@ public function testCancelDuringTcpConnectionCancelsTcpConnection()
79101
80102 public function testCancelDuringTcpConnectionCancelsTcpConnectionAndRejectsWithTcpRejection ()
81103 {
82- $ pending = new Promise \Promise (function () { }, function () { throw new \RuntimeException ('Connection cancelled ' ); });
104+ $ pending = new Promise \Promise (function () { }, function () { throw new \RuntimeException ('Connection to tcp://example.com:80 cancelled ' , 42 ); });
83105 $ this ->tcp ->expects ($ this ->once ())->method ('connect ' )->with ($ this ->equalTo ('example.com:80 ' ))->will ($ this ->returnValue ($ pending ));
84106
85107 $ promise = $ this ->connector ->connect ('example.com:80 ' );
86108 $ promise ->cancel ();
87109
88- $ this ->setExpectedException ('RuntimeException ' , 'Connection cancelled ' );
110+ $ this ->setExpectedException ('RuntimeException ' , 'Connection to tls://example.com:80 cancelled ' , 42 );
89111 $ this ->throwRejection ($ promise );
90112 }
91113
@@ -139,7 +161,7 @@ public function testConnectionWillBeRejectedIfStreamEncryptionFailsAndClosesConn
139161 try {
140162 $ this ->throwRejection ($ promise );
141163 } catch (\RuntimeException $ e ) {
142- $ this ->assertEquals ('Connection to example.com:80 failed during TLS handshake: TLS error ' , $ e ->getMessage ());
164+ $ this ->assertEquals ('Connection to tls:// example.com:80 failed during TLS handshake: TLS error ' , $ e ->getMessage ());
143165 $ this ->assertEquals (123 , $ e ->getCode ());
144166 $ this ->assertNull ($ e ->getPrevious ());
145167 }
@@ -165,7 +187,7 @@ public function testCancelDuringStreamEncryptionCancelsEncryptionAndClosesConnec
165187 $ promise = $ this ->connector ->connect ('example.com:80 ' );
166188 $ promise ->cancel ();
167189
168- $ this ->setExpectedException ('RuntimeException ' , 'Connection to example.com:80 cancelled during TLS handshake ' );
190+ $ this ->setExpectedException ('RuntimeException ' , 'Connection to tls:// example.com:80 cancelled during TLS handshake ' );
169191 $ this ->throwRejection ($ promise );
170192 }
171193
0 commit comments