@@ -53,16 +53,9 @@ public function testConnectWillRejectWhenBothDnsLookupsReject()
5353 $ parts = parse_url ($ uri );
5454
5555 $ builder = new HappyEyeBallsConnectionBuilder ($ loop , $ connector , $ resolver , $ uri , $ host , $ parts );
56-
5756 $ promise = $ builder ->connect ();
5857
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 ' );
6659 }
6760
6861 public function testConnectWillRejectWhenBothDnsLookupsRejectWithDifferentMessages ()
@@ -89,16 +82,10 @@ public function testConnectWillRejectWhenBothDnsLookupsRejectWithDifferentMessag
8982
9083 $ builder = new HappyEyeBallsConnectionBuilder ($ loop , $ connector , $ resolver , $ uri , $ host , $ parts );
9184
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+
9287 $ promise = $ builder ->connect ();
9388 $ 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 ());
10289 }
10390
10491 public function testConnectWillStartDelayTimerWhenIpv4ResolvesAndIpv6IsPending ()
@@ -249,8 +236,10 @@ public function testConnectWillStartConnectingWithAttemptTimerButWithoutResoluti
249236
250237 $ builder = new HappyEyeBallsConnectionBuilder ($ loop , $ connector , $ resolver , $ uri , $ host , $ parts );
251238
252- $ builder ->connect ();
253- $ deferred ->reject (new \RuntimeException ());
239+ $ this ->setExpectedException ('RuntimeException ' , 'reject ' );
240+
241+ $ promise = $ builder ->connect ();
242+ $ deferred ->reject (new \RuntimeException ('reject ' ));
254243 }
255244
256245 public function testConnectWillStartConnectingWithAttemptTimerWhenIpv6AndIpv4ResolvesAndWillStartNextConnectionAttemptWithoutAttemptTimerImmediatelyWhenFirstConnectionAttemptFails ()
@@ -294,8 +283,8 @@ public function testConnectWillStartConnectingWithAlternatingIPv6AndIPv4WhenReso
294283 {
295284 $ timer = $ this ->getMockBuilder ('React\EventLoop\TimerInterface ' )->getMock ();
296285 $ 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 );
299288
300289 $ deferred = new Deferred ();
301290 $ connector = $ this ->getMockBuilder ('React\Socket\ConnectorInterface ' )->getMock ();
@@ -326,17 +315,17 @@ public function testConnectWillStartConnectingWithAlternatingIPv6AndIPv4WhenReso
326315
327316 $ builder = new HappyEyeBallsConnectionBuilder ($ loop , $ connector , $ resolver , $ uri , $ host , $ parts );
328317
329- $ builder ->connect ();
318+ $ promise = $ builder ->connect ();
330319
331- $ deferred ->reject (new \RuntimeException ());
320+ $ deferred ->reject (new \RuntimeException (' reject ' ));
332321 }
333322
334323 public function testConnectWillStartConnectingWithAttemptTimerWhenOnlyIpv6ResolvesAndWillStartNextConnectionAttemptWithoutAttemptTimerImmediatelyWhenFirstConnectionAttemptFails ()
335324 {
336325 $ timer = $ this ->getMockBuilder ('React\EventLoop\TimerInterface ' )->getMock ();
337326 $ 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 );
340329
341330 $ connector = $ this ->getMockBuilder ('React\Socket\ConnectorInterface ' )->getMock ();
342331 $ connector ->expects ($ this ->exactly (2 ))->method ('connect ' )->withConsecutive (
@@ -376,7 +365,7 @@ public function testConnectWillStartConnectingAndWillStartNextConnectionWithoutN
376365 $ loop ->expects ($ this ->never ())->method ('cancelTimer ' );
377366
378367 $ 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 () { }));
380369
381370 $ deferred = new Deferred ();
382371 $ resolver = $ this ->getMockBuilder ('React\Dns\Resolver\ResolverInterface ' )->getMock ();
@@ -394,8 +383,10 @@ public function testConnectWillStartConnectingAndWillStartNextConnectionWithoutN
394383
395384 $ builder = new HappyEyeBallsConnectionBuilder ($ loop , $ connector , $ resolver , $ uri , $ host , $ parts );
396385
386+ $ this ->setExpectedException ('RuntimeException ' , 'reject ' );
387+
397388 $ builder ->connect ();
398- $ deferred ->reject (new \RuntimeException ());
389+ $ deferred ->reject (new \RuntimeException (' reject ' ));
399390
400391 $ this ->assertNotNull ($ timer );
401392 $ timer ();
@@ -467,16 +458,10 @@ public function testConnectWillRejectWhenOnlyTcp6ConnectionRejectsAndCancelNextA
467458
468459 $ builder = new HappyEyeBallsConnectionBuilder ($ loop , $ connector , $ resolver , $ uri , $ host , $ parts );
469460
461+ // $this->setExpectedException('RuntimeException', 'Connection to tcp://reactphp.org:80 failed: Last error for IPv6: Connection refused. Previous error for IPv4: DNS failed');
462+
470463 $ promise = $ builder ->connect ();
471464 $ 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 ());
480465 }
481466
482467 public function testConnectWillRejectWhenOnlyTcp4ConnectionRejectsAndWillNeverStartNextAttemptTimer ()
0 commit comments