@@ -53,16 +53,9 @@ public function testConnectWillRejectWhenBothDnsLookupsReject()
53
53
$ parts = parse_url ($ uri );
54
54
55
55
$ builder = new HappyEyeBallsConnectionBuilder ($ loop , $ connector , $ resolver , $ uri , $ host , $ parts );
56
-
57
56
$ promise = $ builder ->connect ();
58
57
59
- $ exception = null ;
60
- $ promise ->then (null , function ($ e ) use (&$ exception ) {
61
- $ exception = $ e ;
62
- });
63
-
64
- $ this ->assertInstanceOf ('RuntimeException ' , $ exception );
65
- $ this ->assertEquals ('Connection to tcp://reactphp.org:80 failed during DNS lookup: DNS lookup error ' , $ exception ->getMessage ());
58
+ $ this ->setExpectedException ('RuntimeException ' , 'Connection to tcp://reactphp.org:80 failed during DNS lookup: DNS lookup error ' );
66
59
}
67
60
68
61
public function testConnectWillRejectWhenBothDnsLookupsRejectWithDifferentMessages ()
@@ -89,16 +82,10 @@ public function testConnectWillRejectWhenBothDnsLookupsRejectWithDifferentMessag
89
82
90
83
$ builder = new HappyEyeBallsConnectionBuilder ($ loop , $ connector , $ resolver , $ uri , $ host , $ parts );
91
84
85
+ $ this ->setExpectedException ('RuntimeException ' , 'Connection to tcp://reactphp.org:80 failed during DNS lookup. Last error for IPv6: DNS6 error. Previous error for IPv4: DNS4 error ' );
86
+
92
87
$ promise = $ builder ->connect ();
93
88
$ deferred ->reject (new \RuntimeException ('DNS6 error ' ));
94
-
95
- $ exception = null ;
96
- $ promise ->then (null , function ($ e ) use (&$ exception ) {
97
- $ exception = $ e ;
98
- });
99
-
100
- $ this ->assertInstanceOf ('RuntimeException ' , $ exception );
101
- $ this ->assertEquals ('Connection to tcp://reactphp.org:80 failed during DNS lookup. Last error for IPv6: DNS6 error. Previous error for IPv4: DNS4 error ' , $ exception ->getMessage ());
102
89
}
103
90
104
91
public function testConnectWillStartDelayTimerWhenIpv4ResolvesAndIpv6IsPending ()
@@ -249,8 +236,10 @@ public function testConnectWillStartConnectingWithAttemptTimerButWithoutResoluti
249
236
250
237
$ builder = new HappyEyeBallsConnectionBuilder ($ loop , $ connector , $ resolver , $ uri , $ host , $ parts );
251
238
252
- $ builder ->connect ();
253
- $ deferred ->reject (new \RuntimeException ());
239
+ $ this ->setExpectedException ('RuntimeException ' , 'reject ' );
240
+
241
+ $ promise = $ builder ->connect ();
242
+ $ deferred ->reject (new \RuntimeException ('reject ' ));
254
243
}
255
244
256
245
public function testConnectWillStartConnectingWithAttemptTimerWhenIpv6AndIpv4ResolvesAndWillStartNextConnectionAttemptWithoutAttemptTimerImmediatelyWhenFirstConnectionAttemptFails ()
@@ -294,8 +283,8 @@ public function testConnectWillStartConnectingWithAlternatingIPv6AndIPv4WhenReso
294
283
{
295
284
$ timer = $ this ->getMockBuilder ('React\EventLoop\TimerInterface ' )->getMock ();
296
285
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
297
- $ loop ->expects ($ this ->once ( ))->method ('addTimer ' )->with (0.1 , $ this ->anything ())->willReturn ($ timer );
298
- $ loop ->expects ($ this ->once ( ))->method ('cancelTimer ' )->with ($ timer );
286
+ $ loop ->expects ($ this ->exactly ( 3 ))->method ('addTimer ' )->with (0.1 , $ this ->anything ())->willReturn ($ timer );
287
+ $ loop ->expects ($ this ->exactly ( 3 ))->method ('cancelTimer ' )->with ($ timer );
299
288
300
289
$ deferred = new Deferred ();
301
290
$ connector = $ this ->getMockBuilder ('React\Socket\ConnectorInterface ' )->getMock ();
@@ -326,17 +315,17 @@ public function testConnectWillStartConnectingWithAlternatingIPv6AndIPv4WhenReso
326
315
327
316
$ builder = new HappyEyeBallsConnectionBuilder ($ loop , $ connector , $ resolver , $ uri , $ host , $ parts );
328
317
329
- $ builder ->connect ();
318
+ $ promise = $ builder ->connect ();
330
319
331
- $ deferred ->reject (new \RuntimeException ());
320
+ $ deferred ->reject (new \RuntimeException (' reject ' ));
332
321
}
333
322
334
323
public function testConnectWillStartConnectingWithAttemptTimerWhenOnlyIpv6ResolvesAndWillStartNextConnectionAttemptWithoutAttemptTimerImmediatelyWhenFirstConnectionAttemptFails ()
335
324
{
336
325
$ timer = $ this ->getMockBuilder ('React\EventLoop\TimerInterface ' )->getMock ();
337
326
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
338
- $ loop ->expects ($ this ->once ( ))->method ('addTimer ' )->with (0.1 , $ this ->anything ())->willReturn ($ timer );
339
- $ loop ->expects ($ this ->once ( ))->method ('cancelTimer ' )->with ($ timer );
327
+ $ loop ->expects ($ this ->exactly ( 2 ))->method ('addTimer ' )->with (0.1 , $ this ->anything ())->willReturn ($ timer );
328
+ $ loop ->expects ($ this ->exactly ( 2 ))->method ('cancelTimer ' )->with ($ timer );
340
329
341
330
$ connector = $ this ->getMockBuilder ('React\Socket\ConnectorInterface ' )->getMock ();
342
331
$ connector ->expects ($ this ->exactly (2 ))->method ('connect ' )->withConsecutive (
@@ -376,7 +365,7 @@ public function testConnectWillStartConnectingAndWillStartNextConnectionWithoutN
376
365
$ loop ->expects ($ this ->never ())->method ('cancelTimer ' );
377
366
378
367
$ connector = $ this ->getMockBuilder ('React\Socket\ConnectorInterface ' )->getMock ();
379
- $ connector ->expects ($ this ->exactly ( 2 ))->method ('connect ' )->willReturn (new Promise (function () { }));
368
+ $ connector ->expects ($ this ->once ( ))->method ('connect ' )->willReturn (new Promise (function () { }));
380
369
381
370
$ deferred = new Deferred ();
382
371
$ resolver = $ this ->getMockBuilder ('React\Dns\Resolver\ResolverInterface ' )->getMock ();
@@ -394,8 +383,10 @@ public function testConnectWillStartConnectingAndWillStartNextConnectionWithoutN
394
383
395
384
$ builder = new HappyEyeBallsConnectionBuilder ($ loop , $ connector , $ resolver , $ uri , $ host , $ parts );
396
385
386
+ $ this ->setExpectedException ('RuntimeException ' , 'reject ' );
387
+
397
388
$ builder ->connect ();
398
- $ deferred ->reject (new \RuntimeException ());
389
+ $ deferred ->reject (new \RuntimeException (' reject ' ));
399
390
400
391
$ this ->assertNotNull ($ timer );
401
392
$ timer ();
@@ -467,16 +458,10 @@ public function testConnectWillRejectWhenOnlyTcp6ConnectionRejectsAndCancelNextA
467
458
468
459
$ builder = new HappyEyeBallsConnectionBuilder ($ loop , $ connector , $ resolver , $ uri , $ host , $ parts );
469
460
461
+ // $this->setExpectedException('RuntimeException', 'Connection to tcp://reactphp.org:80 failed: Last error for IPv6: Connection refused. Previous error for IPv4: DNS failed');
462
+
470
463
$ promise = $ builder ->connect ();
471
464
$ deferred ->reject (new \RuntimeException ('Connection refused ' ));
472
-
473
- $ exception = null ;
474
- $ promise ->then (null , function ($ e ) use (&$ exception ) {
475
- $ exception = $ e ;
476
- });
477
-
478
- $ this ->assertInstanceOf ('RuntimeException ' , $ exception );
479
- $ this ->assertEquals ('Connection to tcp://reactphp.org:80 failed: Last error for IPv6: Connection refused. Previous error for IPv4: DNS failed ' , $ exception ->getMessage ());
480
465
}
481
466
482
467
public function testConnectWillRejectWhenOnlyTcp4ConnectionRejectsAndWillNeverStartNextAttemptTimer ()
0 commit comments