@@ -46,23 +46,15 @@ public function queryShouldCreateUdpRequest()
4646 }
4747
4848 /** @test */
49- public function resolveShouldCreateTcpRequestIfRequestIsLargerThan512Bytes ()
49+ public function resolveShouldRejectIfRequestIsLargerThan512Bytes ()
5050 {
51- $ timer = $ this ->getMockBuilder ('React\EventLoop\Timer\TimerInterface ' )->getMock ();
52- $ this ->loop
53- ->expects ($ this ->any ())
54- ->method ('addTimer ' )
55- ->will ($ this ->returnValue ($ timer ));
56-
57- $ this ->executor = $ this ->createExecutorMock ();
58- $ this ->executor
59- ->expects ($ this ->once ())
60- ->method ('createConnection ' )
61- ->with ('8.8.8.8:53 ' , 'tcp ' )
62- ->will ($ this ->returnNewConnectionMock (false ));
63-
6451 $ query = new Query (str_repeat ('a ' , 512 ).'.igor.io ' , Message::TYPE_A , Message::CLASS_IN , 1345656451 );
65- $ this ->executor ->query ('8.8.8.8:53 ' , $ query );
52+ $ promise = $ this ->executor ->query ('8.8.8.8:53 ' , $ query );
53+
54+ $ promise ->then (
55+ null ,
56+ $ this ->expectCallableOnce ()
57+ );
6658 }
6759
6860 /** @test */
@@ -129,7 +121,7 @@ public function resolveShouldNotStartOrCancelTimerWhenCancelledWithTimeoutIsNull
129121 }
130122
131123 /** @test */
132- public function resolveShouldRetryWithTcpIfResponseIsTruncated ()
124+ public function resolveShouldRejectIfResponseIsTruncated ()
133125 {
134126 $ timer = $ this ->getMockBuilder ('React\EventLoop\Timer\TimerInterface ' )->getMock ();
135127
@@ -139,86 +131,38 @@ public function resolveShouldRetryWithTcpIfResponseIsTruncated()
139131 ->will ($ this ->returnValue ($ timer ));
140132
141133 $ this ->parser
142- ->expects ($ this ->at ( 0 ))
134+ ->expects ($ this ->once ( ))
143135 ->method ('parseMessage ' )
144136 ->will ($ this ->returnTruncatedResponse ());
145- $ this ->parser
146- ->expects ($ this ->at (1 ))
147- ->method ('parseMessage ' )
148- ->will ($ this ->returnStandardResponse ());
149137
150138 $ this ->executor = $ this ->createExecutorMock ();
151139 $ this ->executor
152- ->expects ($ this ->at (0 ))
153- ->method ('createConnection ' )
154- ->with ('8.8.8.8:53 ' , 'udp ' )
155- ->will ($ this ->returnNewConnectionMock ());
156- $ this ->executor
157- ->expects ($ this ->at (1 ))
158- ->method ('createConnection ' )
159- ->with ('8.8.8.8:53 ' , 'tcp ' )
160- ->will ($ this ->returnNewConnectionMock ());
161-
162- $ query = new Query ('igor.io ' , Message::TYPE_A , Message::CLASS_IN , 1345656451 );
163- $ this ->executor ->query ('8.8.8.8:53 ' , $ query );
164- }
165-
166- /** @test */
167- public function resolveShouldRetryWithTcpIfUdpThrows ()
168- {
169- $ timer = $ this ->getMockBuilder ('React\EventLoop\Timer\TimerInterface ' )->getMock ();
170-
171- $ this ->loop
172140 ->expects ($ this ->once ())
173- ->method ('addTimer ' )
174- ->will ($ this ->returnValue ($ timer ));
175-
176- $ this ->parser
177- ->expects ($ this ->once ())
178- ->method ('parseMessage ' )
179- ->will ($ this ->returnStandardResponse ());
180-
181- $ this ->executor = $ this ->createExecutorMock ();
182- $ this ->executor
183- ->expects ($ this ->at (0 ))
184141 ->method ('createConnection ' )
185142 ->with ('8.8.8.8:53 ' , 'udp ' )
186- ->will ($ this ->throwException (new \Exception ()));
187- $ this ->executor
188- ->expects ($ this ->at (1 ))
189- ->method ('createConnection ' )
190- ->with ('8.8.8.8:53 ' , 'tcp ' )
191143 ->will ($ this ->returnNewConnectionMock ());
192144
193145 $ query = new Query ('igor.io ' , Message::TYPE_A , Message::CLASS_IN , 1345656451 );
194146 $ this ->executor ->query ('8.8.8.8:53 ' , $ query );
195147 }
196148
197149 /** @test */
198- public function resolveShouldFailIfBothUdpAndTcpThrow ()
150+ public function resolveShouldFailIfUdpThrow ()
199151 {
200- $ timer = $ this ->getMockBuilder ('React\EventLoop\Timer\TimerInterface ' )->getMock ();
201-
202152 $ this ->loop
203- ->expects ($ this ->once ())
204- ->method ('addTimer ' )
205- ->will ($ this ->returnValue ($ timer ));
153+ ->expects ($ this ->never ())
154+ ->method ('addTimer ' );
206155
207156 $ this ->parser
208157 ->expects ($ this ->never ())
209158 ->method ('parseMessage ' );
210159
211160 $ this ->executor = $ this ->createExecutorMock ();
212161 $ this ->executor
213- ->expects ($ this ->at ( 0 ))
162+ ->expects ($ this ->once ( ))
214163 ->method ('createConnection ' )
215164 ->with ('8.8.8.8:53 ' , 'udp ' )
216165 ->will ($ this ->throwException (new \Exception ()));
217- $ this ->executor
218- ->expects ($ this ->at (1 ))
219- ->method ('createConnection ' )
220- ->with ('8.8.8.8:53 ' , 'tcp ' )
221- ->will ($ this ->throwException (new \Exception ()));
222166
223167 $ query = new Query ('igor.io ' , Message::TYPE_A , Message::CLASS_IN , 1345656451 );
224168 $ promise = $ this ->executor ->query ('8.8.8.8:53 ' , $ query );
@@ -235,42 +179,6 @@ public function resolveShouldFailIfBothUdpAndTcpThrow()
235179 $ promise ->then ($ this ->expectCallableNever (), $ mock );
236180 }
237181
238- /** @test */
239- public function resolveShouldFailIfResponseIsTruncatedAfterTcpRequest ()
240- {
241- $ timer = $ this ->getMockBuilder ('React\EventLoop\Timer\TimerInterface ' )->getMock ();
242-
243- $ this ->loop
244- ->expects ($ this ->any ())
245- ->method ('addTimer ' )
246- ->will ($ this ->returnValue ($ timer ));
247-
248- $ this ->parser
249- ->expects ($ this ->once ())
250- ->method ('parseMessage ' )
251- ->will ($ this ->returnTruncatedResponse ());
252-
253- $ this ->executor = $ this ->createExecutorMock ();
254- $ this ->executor
255- ->expects ($ this ->once ())
256- ->method ('createConnection ' )
257- ->with ('8.8.8.8:53 ' , 'tcp ' )
258- ->will ($ this ->returnNewConnectionMock ());
259-
260- $ mock = $ this ->createCallableMock ();
261- $ mock
262- ->expects ($ this ->once ())
263- ->method ('__invoke ' )
264- ->with ($ this ->callback (function ($ e ) {
265- return $ e instanceof \React \Dns \BadServerException &&
266- 'The server set the truncated bit although we issued a TCP request ' === $ e ->getMessage ();
267- }));
268-
269- $ query = new Query (str_repeat ('a ' , 512 ).'.igor.io ' , Message::TYPE_A , Message::CLASS_IN , 1345656451 );
270- $ this ->executor ->query ('8.8.8.8:53 ' , $ query )
271- ->then ($ this ->expectCallableNever (), $ mock );
272- }
273-
274182 /** @test */
275183 public function resolveShouldCancelTimerWhenFullResponseIsReceived ()
276184 {
0 commit comments