@@ -148,8 +148,13 @@ public function testIpv6ResolvesFirstSoIsTheFirstToConnect(array $ipv6, array $i
148
148
{
149
149
$ deferred = new Deferred ();
150
150
151
- $ this ->resolver ->expects ($ this ->at (0 ))->method ('resolveAll ' )->with ('google.com ' , Message::TYPE_AAAA )->will ($ this ->returnValue (Promise \resolve ($ ipv6 )));
152
- $ this ->resolver ->expects ($ this ->at (1 ))->method ('resolveAll ' )->with ('google.com ' , Message::TYPE_A )->will ($ this ->returnValue ($ deferred ->promise ()));
151
+ $ this ->resolver ->expects ($ this ->exactly (2 ))->method ('resolveAll ' )->withConsecutive (
152
+ array ('google.com ' , Message::TYPE_AAAA ),
153
+ array ('google.com ' , Message::TYPE_A )
154
+ )->willReturnOnConsecutiveCalls (
155
+ $ this ->returnValue (Promise \resolve ($ ipv6 )),
156
+ $ this ->returnValue ($ deferred ->promise ())
157
+ );
153
158
$ this ->tcp ->expects ($ this ->any ())->method ('connect ' )->with ($ this ->stringContains (']:80/?hostname=google.com ' ))->will ($ this ->returnValue (Promise \reject ()));
154
159
155
160
$ this ->connector ->connect ('scheme://google.com:80/?hostname=google.com ' );
@@ -168,8 +173,13 @@ public function testIpv6DoesntResolvesWhileIpv4DoesFirstSoIpv4Connects(array $ip
168
173
{
169
174
$ deferred = new Deferred ();
170
175
171
- $ this ->resolver ->expects ($ this ->at (0 ))->method ('resolveAll ' )->with ('google.com ' , Message::TYPE_AAAA )->will ($ this ->returnValue ($ deferred ->promise ()));
172
- $ this ->resolver ->expects ($ this ->at (1 ))->method ('resolveAll ' )->with ('google.com ' , Message::TYPE_A )->will ($ this ->returnValue (Promise \resolve ($ ipv4 )));
176
+ $ this ->resolver ->expects ($ this ->exactly (2 ))->method ('resolveAll ' )->withConsecutive (
177
+ array ('google.com ' , Message::TYPE_AAAA ),
178
+ array ('google.com ' , Message::TYPE_A )
179
+ )->willReturnOnConsecutiveCalls (
180
+ $ this ->returnValue ($ deferred ->promise ()),
181
+ $ this ->returnValue (Promise \resolve ($ ipv4 ))
182
+ );
173
183
$ this ->tcp ->expects ($ this ->any ())->method ('connect ' )->with ($ this ->stringContains (':80/?hostname=google.com ' ))->will ($ this ->returnValue (Promise \reject ()));
174
184
175
185
$ this ->connector ->connect ('scheme://google.com:80/?hostname=google.com ' );
@@ -181,38 +191,6 @@ public function testIpv6DoesntResolvesWhileIpv4DoesFirstSoIpv4Connects(array $ip
181
191
$ this ->loop ->run ();
182
192
}
183
193
184
- /**
185
- * @dataProvider provideIpvAddresses
186
- */
187
- public function testAttemptsToConnectBothIpv6AndIpv4AddressesAlternatingIpv6AndIpv4AddressesWhenMoreThenOneIsResolvedPerFamily (array $ ipv6 , array $ ipv4 )
188
- {
189
- $ this ->resolver ->expects ($ this ->at (0 ))->method ('resolveAll ' )->with ('google.com ' , Message::TYPE_AAAA )->will ($ this ->returnValue (
190
- Promise \Timer \resolve (0.1 , $ this ->loop )->then (function () use ($ ipv6 ) {
191
- return Promise \resolve ($ ipv6 );
192
- })
193
- ));
194
- $ this ->resolver ->expects ($ this ->at (1 ))->method ('resolveAll ' )->with ('google.com ' , Message::TYPE_A )->will ($ this ->returnValue (
195
- Promise \Timer \resolve (0.1 , $ this ->loop )->then (function () use ($ ipv4 ) {
196
- return Promise \resolve ($ ipv4 );
197
- })
198
- ));
199
-
200
- $ i = 0 ;
201
- while (count ($ ipv6 ) > 0 || count ($ ipv4 ) > 0 ) {
202
- if (count ($ ipv6 ) > 0 ) {
203
- $ this ->tcp ->expects ($ this ->at ($ i ++))->method ('connect ' )->with ($ this ->equalTo ('scheme://[ ' . array_shift ($ ipv6 ) . ']:80/?hostname=google.com ' ))->will ($ this ->returnValue (Promise \reject ()));
204
- }
205
- if (count ($ ipv4 ) > 0 ) {
206
- $ this ->tcp ->expects ($ this ->at ($ i ++))->method ('connect ' )->with ($ this ->equalTo ('scheme:// ' . array_shift ($ ipv4 ) . ':80/?hostname=google.com ' ))->will ($ this ->returnValue (Promise \reject ()));
207
- }
208
- }
209
-
210
-
211
- $ this ->connector ->connect ('scheme://google.com:80/?hostname=google.com ' );
212
-
213
- $ this ->loop ->run ();
214
- }
215
-
216
194
public function testRejectsImmediatelyIfUriIsInvalid ()
217
195
{
218
196
$ this ->resolver ->expects ($ this ->never ())->method ('resolveAll ' );
@@ -297,8 +275,13 @@ public function testCancelDuringTcpConnectionCancelsTcpConnectionIfGivenIp()
297
275
*/
298
276
public function testShouldConnectOverIpv4WhenIpv6LookupFails (array $ ipv6 , array $ ipv4 )
299
277
{
300
- $ this ->resolver ->expects ($ this ->at (0 ))->method ('resolveAll ' )->with ($ this ->equalTo ('example.com ' ), Message::TYPE_AAAA )->willReturn (Promise \reject (new \Exception ('failure ' )));
301
- $ this ->resolver ->expects ($ this ->at (1 ))->method ('resolveAll ' )->with ($ this ->equalTo ('example.com ' ), Message::TYPE_A )->willReturn (Promise \resolve ($ ipv4 ));
278
+ $ this ->resolver ->expects ($ this ->exactly (2 ))->method ('resolveAll ' )->withConsecutive (
279
+ array ($ this ->equalTo ('example.com ' ), Message::TYPE_AAAA ),
280
+ array ($ this ->equalTo ('example.com ' ), Message::TYPE_A )
281
+ )->willReturnOnConsecutiveCalls (
282
+ Promise \reject (new \Exception ('failure ' )),
283
+ Promise \resolve ($ ipv4 )
284
+ );
302
285
$ this ->tcp ->expects ($ this ->exactly (1 ))->method ('connect ' )->with ($ this ->equalTo ('1.2.3.4:80?hostname=example.com ' ))->willReturn (Promise \resolve ($ this ->connection ));
303
286
304
287
$ promise = $ this ->connector ->connect ('example.com:80 ' );;
@@ -316,8 +299,13 @@ public function testShouldConnectOverIpv6WhenIpv4LookupFails(array $ipv6, array
316
299
$ ipv6 [] = '1:2:3:4 ' ;
317
300
}
318
301
319
- $ this ->resolver ->expects ($ this ->at (0 ))->method ('resolveAll ' )->with ($ this ->equalTo ('example.com ' ), Message::TYPE_AAAA )->willReturn (Promise \resolve ($ ipv6 ));
320
- $ this ->resolver ->expects ($ this ->at (1 ))->method ('resolveAll ' )->with ($ this ->equalTo ('example.com ' ), Message::TYPE_A )->willReturn (Promise \reject (new \Exception ('failure ' )));
302
+ $ this ->resolver ->expects ($ this ->exactly (2 ))->method ('resolveAll ' )->withConsecutive (
303
+ array ($ this ->equalTo ('example.com ' ), Message::TYPE_AAAA ),
304
+ array ($ this ->equalTo ('example.com ' ), Message::TYPE_A )
305
+ )->willReturnOnConsecutiveCalls (
306
+ Promise \resolve ($ ipv6 ),
307
+ Promise \reject (new \Exception ('failure ' ))
308
+ );
321
309
$ this ->tcp ->expects ($ this ->exactly (1 ))->method ('connect ' )->with ($ this ->equalTo ('[1:2:3:4]:80?hostname=example.com ' ))->willReturn (Promise \resolve ($ this ->connection ));
322
310
323
311
$ promise = $ this ->connector ->connect ('example.com:80 ' );;
0 commit comments