@@ -92,10 +92,18 @@ public function testConnectRejectsIfGivenIpAndTcpConnectorRejectsWithRuntimeExce
9292 $ this ->tcp ->expects ($ this ->once ())->method ('connect ' )->with ('1.2.3.4:80 ' )->willReturn ($ promise );
9393
9494 $ promise = $ this ->connector ->connect ('1.2.3.4:80 ' );
95- $ promise ->cancel ();
9695
97- $ this ->setExpectedException ('RuntimeException ' , 'Connection to tcp://1.2.3.4:80 failed: Connection failed ' , 42 );
98- $ this ->throwRejection ($ promise );
96+ $ exception = null ;
97+ $ promise ->then (null , function ($ reason ) use (&$ exception ) {
98+ $ exception = $ reason ;
99+ });
100+
101+ assert ($ exception instanceof \RuntimeException);
102+ $ this ->assertInstanceOf ('RuntimeException ' , $ exception );
103+ $ this ->assertEquals ('Connection to tcp://1.2.3.4:80 failed: Connection failed ' , $ exception ->getMessage ());
104+ $ this ->assertEquals (42 , $ exception ->getCode ());
105+ $ this ->assertNull ($ exception ->getPrevious ());
106+ $ this ->assertNotEquals ('' , $ exception ->getTraceAsString ());
99107 }
100108
101109 public function testConnectRejectsIfGivenIpAndTcpConnectorRejectsWithInvalidArgumentException ()
@@ -105,10 +113,18 @@ public function testConnectRejectsIfGivenIpAndTcpConnectorRejectsWithInvalidArgu
105113 $ this ->tcp ->expects ($ this ->once ())->method ('connect ' )->with ('1.2.3.4:80 ' )->willReturn ($ promise );
106114
107115 $ promise = $ this ->connector ->connect ('1.2.3.4:80 ' );
108- $ promise ->cancel ();
109116
110- $ this ->setExpectedException ('InvalidArgumentException ' , 'Invalid ' , 42 );
111- $ this ->throwRejection ($ promise );
117+ $ exception = null ;
118+ $ promise ->then (null , function ($ reason ) use (&$ exception ) {
119+ $ exception = $ reason ;
120+ });
121+
122+ assert ($ exception instanceof \InvalidArgumentException);
123+ $ this ->assertInstanceOf ('InvalidArgumentException ' , $ exception );
124+ $ this ->assertEquals ('Invalid ' , $ exception ->getMessage ());
125+ $ this ->assertEquals (42 , $ exception ->getCode ());
126+ $ this ->assertNull ($ exception ->getPrevious ());
127+ $ this ->assertNotEquals ('' , $ exception ->getTraceAsString ());
112128 }
113129
114130 public function testConnectRejectsWithOriginalHostnameInMessageAfterResolvingIfTcpConnectorRejectsWithRuntimeException ()
@@ -139,10 +155,18 @@ public function testConnectRejectsWithOriginalExceptionAfterResolvingIfTcpConnec
139155 $ this ->tcp ->expects ($ this ->once ())->method ('connect ' )->with ('1.2.3.4:80?hostname=example.com ' )->willReturn ($ promise );
140156
141157 $ promise = $ this ->connector ->connect ('example.com:80 ' );
142- $ promise ->cancel ();
143158
144- $ this ->setExpectedException ('InvalidArgumentException ' , 'Invalid ' , 42 );
145- $ this ->throwRejection ($ promise );
159+ $ exception = null ;
160+ $ promise ->then (null , function ($ reason ) use (&$ exception ) {
161+ $ exception = $ reason ;
162+ });
163+
164+ assert ($ exception instanceof \InvalidArgumentException);
165+ $ this ->assertInstanceOf ('InvalidArgumentException ' , $ exception );
166+ $ this ->assertEquals ('Invalid ' , $ exception ->getMessage ());
167+ $ this ->assertEquals (42 , $ exception ->getCode ());
168+ $ this ->assertNull ($ exception ->getPrevious ());
169+ $ this ->assertNotEquals ('' , $ exception ->getTraceAsString ());
146170 }
147171
148172 public function testSkipConnectionIfDnsFails ()
@@ -153,8 +177,17 @@ public function testSkipConnectionIfDnsFails()
153177
154178 $ promise = $ this ->connector ->connect ('example.invalid:80 ' );
155179
156- $ this ->setExpectedException ('RuntimeException ' , 'Connection to tcp://example.invalid:80 failed during DNS lookup: DNS error ' );
157- $ this ->throwRejection ($ promise );
180+ $ exception = null ;
181+ $ promise ->then (null , function ($ reason ) use (&$ exception ) {
182+ $ exception = $ reason ;
183+ });
184+
185+ assert ($ exception instanceof \RuntimeException);
186+ $ this ->assertInstanceOf ('RuntimeException ' , $ exception );
187+ $ this ->assertEquals ('Connection to tcp://example.invalid:80 failed during DNS lookup: DNS error ' , $ exception ->getMessage ());
188+ $ this ->assertEquals (0 , $ exception ->getCode ());
189+ $ this ->assertInstanceOf ('RuntimeException ' , $ exception ->getPrevious ());
190+ $ this ->assertNotEquals ('' , $ exception ->getTraceAsString ());
158191 }
159192
160193 public function testRejectionExceptionUsesPreviousExceptionIfDnsFails ()
@@ -179,12 +212,17 @@ public function testCancelDuringDnsCancelsDnsAndDoesNotStartTcpConnection()
179212 $ promise = $ this ->connector ->connect ('example.com:80 ' );
180213 $ promise ->cancel ();
181214
182- $ this ->setExpectedException (
183- 'RuntimeException ' ,
184- 'Connection to tcp://example.com:80 cancelled during DNS lookup (ECONNABORTED) ' ,
185- defined ('SOCKET_ECONNABORTED ' ) ? SOCKET_ECONNABORTED : 103
186- );
187- $ this ->throwRejection ($ promise );
215+ $ exception = null ;
216+ $ promise ->then (null , function ($ reason ) use (&$ exception ) {
217+ $ exception = $ reason ;
218+ });
219+
220+ assert ($ exception instanceof \RuntimeException);
221+ $ this ->assertInstanceOf ('RuntimeException ' , $ exception );
222+ $ this ->assertEquals ('Connection to tcp://example.com:80 cancelled during DNS lookup (ECONNABORTED) ' , $ exception ->getMessage ());
223+ $ this ->assertEquals (defined ('SOCKET_ECONNABORTED ' ) ? SOCKET_ECONNABORTED : 103 , $ exception ->getCode ());
224+ $ this ->assertNull ($ exception ->getPrevious ());
225+ $ this ->assertNotEquals ('' , $ exception ->getTraceAsString ());
188226 }
189227
190228 public function testCancelDuringTcpConnectionCancelsTcpConnectionIfGivenIp ()
@@ -349,14 +387,4 @@ public function testCancelDuringTcpConnectionShouldNotCreateAnyGarbageReferences
349387
350388 $ this ->assertEquals (0 , gc_collect_cycles ());
351389 }
352-
353- private function throwRejection ($ promise )
354- {
355- $ ex = null ;
356- $ promise ->then (null , function ($ e ) use (&$ ex ) {
357- $ ex = $ e ;
358- });
359-
360- throw $ ex ;
361- }
362390}
0 commit comments