@@ -77,14 +77,38 @@ public function testRejectsImmediatelyIfUriIsInvalid()
7777 $ promise ->then ($ this ->expectCallableNever (), $ this ->expectCallableOnce ());
7878 }
7979
80+ /**
81+ * @expectedException RuntimeException
82+ * @expectedExceptionMessage Connection to example.invalid:80 failed during DNS lookup: DNS error
83+ */
8084 public function testSkipConnectionIfDnsFails ()
8185 {
82- $ this ->resolver ->expects ($ this ->once ())->method ('resolve ' )->with ($ this ->equalTo ('example.invalid ' ))->will ($ this ->returnValue (Promise \reject ()));
86+ $ promise = Promise \reject (new \RuntimeException ('DNS error ' ));
87+ $ this ->resolver ->expects ($ this ->once ())->method ('resolve ' )->with ($ this ->equalTo ('example.invalid ' ))->willReturn ($ promise );
8388 $ this ->tcp ->expects ($ this ->never ())->method ('connect ' );
8489
85- $ this ->connector ->connect ('example.invalid:80 ' );
90+ $ promise = $ this ->connector ->connect ('example.invalid:80 ' );
91+
92+ $ this ->throwRejection ($ promise );
93+ }
94+
95+ public function testRejectionExceptionUsesPreviousExceptionIfDnsFails ()
96+ {
97+ $ exception = new \RuntimeException ();
98+
99+ $ this ->resolver ->expects ($ this ->once ())->method ('resolve ' )->with ($ this ->equalTo ('example.invalid ' ))->willReturn (Promise \reject ($ exception ));
100+
101+ $ promise = $ this ->connector ->connect ('example.invalid:80 ' );
102+
103+ $ promise ->then (null , function ($ e ) {
104+ throw $ e ->getPrevious ();
105+ })->then (null , $ this ->expectCallableOnceWith ($ this ->identicalTo ($ exception )));
86106 }
87107
108+ /**
109+ * @expectedException RuntimeException
110+ * @expectedExceptionMessage Connection to example.com:80 cancelled during DNS lookup
111+ */
88112 public function testCancelDuringDnsCancelsDnsAndDoesNotStartTcpConnection ()
89113 {
90114 $ pending = new Promise \Promise (function () { }, $ this ->expectCallableOnce ());
@@ -94,7 +118,7 @@ public function testCancelDuringDnsCancelsDnsAndDoesNotStartTcpConnection()
94118 $ promise = $ this ->connector ->connect ('example.com:80 ' );
95119 $ promise ->cancel ();
96120
97- $ promise -> then ( $ this ->expectCallableNever (), $ this -> expectCallableOnce () );
121+ $ this ->throwRejection ( $ promise );
98122 }
99123
100124 public function testCancelDuringTcpConnectionCancelsTcpConnection ()
@@ -108,4 +132,14 @@ public function testCancelDuringTcpConnectionCancelsTcpConnection()
108132
109133 $ promise ->then ($ this ->expectCallableNever (), $ this ->expectCallableOnce ());
110134 }
135+
136+ private function throwRejection ($ promise )
137+ {
138+ $ ex = null ;
139+ $ promise ->then (null , function ($ e ) use (&$ ex ) {
140+ $ ex = $ e ;
141+ });
142+
143+ throw $ ex ;
144+ }
111145}
0 commit comments