@@ -92,10 +92,18 @@ public function testConnectRejectsIfGivenIpAndTcpConnectorRejectsWithRuntimeExce
92
92
$ this ->tcp ->expects ($ this ->once ())->method ('connect ' )->with ('1.2.3.4:80 ' )->willReturn ($ promise );
93
93
94
94
$ promise = $ this ->connector ->connect ('1.2.3.4:80 ' );
95
- $ promise ->cancel ();
96
95
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 ());
99
107
}
100
108
101
109
public function testConnectRejectsIfGivenIpAndTcpConnectorRejectsWithInvalidArgumentException ()
@@ -105,10 +113,18 @@ public function testConnectRejectsIfGivenIpAndTcpConnectorRejectsWithInvalidArgu
105
113
$ this ->tcp ->expects ($ this ->once ())->method ('connect ' )->with ('1.2.3.4:80 ' )->willReturn ($ promise );
106
114
107
115
$ promise = $ this ->connector ->connect ('1.2.3.4:80 ' );
108
- $ promise ->cancel ();
109
116
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 ());
112
128
}
113
129
114
130
public function testConnectRejectsWithOriginalHostnameInMessageAfterResolvingIfTcpConnectorRejectsWithRuntimeException ()
@@ -139,10 +155,18 @@ public function testConnectRejectsWithOriginalExceptionAfterResolvingIfTcpConnec
139
155
$ this ->tcp ->expects ($ this ->once ())->method ('connect ' )->with ('1.2.3.4:80?hostname=example.com ' )->willReturn ($ promise );
140
156
141
157
$ promise = $ this ->connector ->connect ('example.com:80 ' );
142
- $ promise ->cancel ();
143
158
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 ());
146
170
}
147
171
148
172
public function testSkipConnectionIfDnsFails ()
@@ -153,8 +177,17 @@ public function testSkipConnectionIfDnsFails()
153
177
154
178
$ promise = $ this ->connector ->connect ('example.invalid:80 ' );
155
179
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 ());
158
191
}
159
192
160
193
public function testRejectionExceptionUsesPreviousExceptionIfDnsFails ()
@@ -179,12 +212,17 @@ public function testCancelDuringDnsCancelsDnsAndDoesNotStartTcpConnection()
179
212
$ promise = $ this ->connector ->connect ('example.com:80 ' );
180
213
$ promise ->cancel ();
181
214
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 ());
188
226
}
189
227
190
228
public function testCancelDuringTcpConnectionCancelsTcpConnectionIfGivenIp ()
@@ -349,14 +387,4 @@ public function testCancelDuringTcpConnectionShouldNotCreateAnyGarbageReferences
349
387
350
388
$ this ->assertEquals (0 , gc_collect_cycles ());
351
389
}
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
- }
362
390
}
0 commit comments