@@ -523,18 +523,21 @@ public function testFollowingRedirectWithSpecifiedHeaders()
523523 // mock sender to resolve promise with the given $redirectResponse in
524524 // response to the given $requestWithUserAgent
525525 $ redirectResponse = new Response (301 , array ('Location ' => 'http://redirect.com ' ));
526- $ sender ->expects ($ this ->at (0 ))->method ('send ' )->willReturn (Promise \resolve ($ redirectResponse ));
527526
528527 // mock sender to resolve promise with the given $okResponse in
529528 // response to the given $requestWithUserAgent
530529 $ okResponse = new Response (200 );
531530 $ that = $ this ;
532- $ sender ->expects ($ this ->at ( 1 ))
533- -> method ( ' send ' )
534- -> with ($ this ->callback (function (RequestInterface $ request ) use ($ that ) {
531+ $ sender ->expects ($ this ->exactly ( 2 ))-> method ( ' send ' )-> withConsecutive (
532+ array ( $ this -> anything ()),
533+ array ($ this ->callback (function (RequestInterface $ request ) use ($ that ) {
535534 $ that ->assertEquals (array ('Chrome ' ), $ request ->getHeader ('User-Agent ' ));
536535 return true ;
537- }))->willReturn (Promise \resolve ($ okResponse ));
536+ }))
537+ )->willReturnOnConsecutiveCalls (
538+ Promise \resolve ($ redirectResponse ),
539+ Promise \resolve ($ okResponse )
540+ );
538541
539542 $ transaction = new Transaction ($ sender , $ loop );
540543 $ transaction ->send ($ requestWithUserAgent );
@@ -551,18 +554,21 @@ public function testRemovingAuthorizationHeaderWhenChangingHostnamesDuringRedire
551554 // mock sender to resolve promise with the given $redirectResponse in
552555 // response to the given $requestWithAuthorization
553556 $ redirectResponse = new Response (301 , array ('Location ' => 'http://redirect.com ' ));
554- $ sender ->expects ($ this ->at (0 ))->method ('send ' )->willReturn (Promise \resolve ($ redirectResponse ));
555557
556558 // mock sender to resolve promise with the given $okResponse in
557559 // response to the given $requestWithAuthorization
558560 $ okResponse = new Response (200 );
559561 $ that = $ this ;
560- $ sender ->expects ($ this ->at ( 1 ))
561- -> method ( ' send ' )
562- -> with ($ this ->callback (function (RequestInterface $ request ) use ($ that ) {
562+ $ sender ->expects ($ this ->exactly ( 2 ))-> method ( ' send ' )-> withConsecutive (
563+ array ( $ this -> anything ()),
564+ array ($ this ->callback (function (RequestInterface $ request ) use ($ that ) {
563565 $ that ->assertFalse ($ request ->hasHeader ('Authorization ' ));
564566 return true ;
565- }))->willReturn (Promise \resolve ($ okResponse ));
567+ }))
568+ )->willReturnOnConsecutiveCalls (
569+ Promise \resolve ($ redirectResponse ),
570+ Promise \resolve ($ okResponse )
571+ );
566572
567573 $ transaction = new Transaction ($ sender , $ loop );
568574 $ transaction ->send ($ requestWithAuthorization );
@@ -579,18 +585,21 @@ public function testAuthorizationHeaderIsForwardedWhenRedirectingToSameDomain()
579585 // mock sender to resolve promise with the given $redirectResponse in
580586 // response to the given $requestWithAuthorization
581587 $ redirectResponse = new Response (301 , array ('Location ' => 'http://example.com/new ' ));
582- $ sender ->expects ($ this ->at (0 ))->method ('send ' )->willReturn (Promise \resolve ($ redirectResponse ));
583588
584589 // mock sender to resolve promise with the given $okResponse in
585590 // response to the given $requestWithAuthorization
586591 $ okResponse = new Response (200 );
587592 $ that = $ this ;
588- $ sender ->expects ($ this ->at ( 1 ))
589- -> method ( ' send ' )
590- -> with ($ this ->callback (function (RequestInterface $ request ) use ($ that ) {
593+ $ sender ->expects ($ this ->exactly ( 2 ))-> method ( ' send ' )-> withConsecutive (
594+ array ( $ this -> anything ()),
595+ array ($ this ->callback (function (RequestInterface $ request ) use ($ that ) {
591596 $ that ->assertEquals (array ('secret ' ), $ request ->getHeader ('Authorization ' ));
592597 return true ;
593- }))->willReturn (Promise \resolve ($ okResponse ));
598+ }))
599+ )->willReturnOnConsecutiveCalls (
600+ Promise \resolve ($ redirectResponse ),
601+ Promise \resolve ($ okResponse )
602+ );
594603
595604 $ transaction = new Transaction ($ sender , $ loop );
596605 $ transaction ->send ($ requestWithAuthorization );
@@ -606,19 +615,22 @@ public function testAuthorizationHeaderIsForwardedWhenLocationContainsAuthentica
606615 // mock sender to resolve promise with the given $redirectResponse in
607616 // response to the given $requestWithAuthorization
608617 $ redirectResponse =
new Response (
301 ,
array (
'Location ' =>
'http://user:[email protected] /new ' ));
609- $ sender ->expects ($ this ->at (0 ))->method ('send ' )->willReturn (Promise \resolve ($ redirectResponse ));
610618
611619 // mock sender to resolve promise with the given $okResponse in
612620 // response to the given $requestWithAuthorization
613621 $ okResponse = new Response (200 );
614622 $ that = $ this ;
615- $ sender ->expects ($ this ->at ( 1 ))
616- -> method ( ' send ' )
617- -> with ($ this ->callback (function (RequestInterface $ request ) use ($ that ) {
623+ $ sender ->expects ($ this ->exactly ( 2 ))-> method ( ' send ' )-> withConsecutive (
624+ array ( $ this -> anything ()),
625+ array ($ this ->callback (function (RequestInterface $ request ) use ($ that ) {
618626 $ that ->assertEquals ('user:pass ' , $ request ->getUri ()->getUserInfo ());
619627 $ that ->assertFalse ($ request ->hasHeader ('Authorization ' ));
620628 return true ;
621- }))->willReturn (Promise \resolve ($ okResponse ));
629+ }))
630+ )->willReturnOnConsecutiveCalls (
631+ Promise \resolve ($ redirectResponse ),
632+ Promise \resolve ($ okResponse )
633+ );
622634
623635 $ transaction = new Transaction ($ sender , $ loop );
624636 $ transaction ->send ($ request );
@@ -639,19 +651,22 @@ public function testSomeRequestHeadersShouldBeRemovedWhenRedirecting()
639651 // mock sender to resolve promise with the given $redirectResponse in
640652 // response to the given $requestWithCustomHeaders
641653 $ redirectResponse = new Response (301 , array ('Location ' => 'http://example.com/new ' ));
642- $ sender ->expects ($ this ->at (0 ))->method ('send ' )->willReturn (Promise \resolve ($ redirectResponse ));
643654
644655 // mock sender to resolve promise with the given $okResponse in
645656 // response to the given $requestWithCustomHeaders
646657 $ okResponse = new Response (200 );
647658 $ that = $ this ;
648- $ sender ->expects ($ this ->at ( 1 ))
649- -> method ( ' send ' )
650- -> with ($ this ->callback (function (RequestInterface $ request ) use ($ that ) {
659+ $ sender ->expects ($ this ->exactly ( 2 ))-> method ( ' send ' )-> withConsecutive (
660+ array ( $ this -> anything ()),
661+ array ($ this ->callback (function (RequestInterface $ request ) use ($ that ) {
651662 $ that ->assertFalse ($ request ->hasHeader ('Content-Type ' ));
652663 $ that ->assertFalse ($ request ->hasHeader ('Content-Length ' ));
653- return true ;
654- }))->willReturn (Promise \resolve ($ okResponse ));
664+ return true ;;
665+ }))
666+ )->willReturnOnConsecutiveCalls (
667+ Promise \resolve ($ redirectResponse ),
668+ Promise \resolve ($ okResponse )
669+ );
655670
656671 $ transaction = new Transaction ($ sender , $ loop );
657672 $ transaction ->send ($ requestWithCustomHeaders );
@@ -706,12 +721,17 @@ public function testCancelTransactionWillCancelRedirectedRequest()
706721
707722 // mock sender to resolve promise with the given $redirectResponse in
708723 $ redirectResponse = new Response (301 , array ('Location ' => 'http://example.com/new ' ));
709- $ sender ->expects ($ this ->at (0 ))->method ('send ' )->willReturn (Promise \resolve ($ redirectResponse ));
710724
711725 $ pending = new \React \Promise \Promise (function () { }, $ this ->expectCallableOnce ());
712726
713727 // mock sender to return pending promise which should be cancelled when cancelling result
714- $ sender ->expects ($ this ->at (1 ))->method ('send ' )->willReturn ($ pending );
728+ $ sender ->expects ($ this ->exactly (2 ))->method ('send ' )->withConsecutive (
729+ array ($ this ->anything ()),
730+ array ($ this ->anything ())
731+ )->willReturnOnConsecutiveCalls (
732+ Promise \resolve ($ redirectResponse ),
733+ $ pending
734+ );
715735
716736 $ transaction = new Transaction ($ sender , $ loop );
717737 $ promise = $ transaction ->send ($ request );
@@ -728,12 +748,17 @@ public function testCancelTransactionWillCancelRedirectedRequestAgain()
728748
729749 // mock sender to resolve promise with the given $redirectResponse in
730750 $ first = new Deferred ();
731- $ sender ->expects ($ this ->at (0 ))->method ('send ' )->willReturn ($ first ->promise ());
732751
733752 $ second = new \React \Promise \Promise (function () { }, $ this ->expectCallableOnce ());
734753
735754 // mock sender to return pending promise which should be cancelled when cancelling result
736- $ sender ->expects ($ this ->at (1 ))->method ('send ' )->willReturn ($ second );
755+ $ sender ->expects ($ this ->exactly (2 ))->method ('send ' )->withConsecutive (
756+ array ($ this ->anything ()),
757+ array ($ this ->anything ())
758+ )->willReturnOnConsecutiveCalls (
759+ $ first ->promise (),
760+ $ second
761+ );
737762
738763 $ transaction = new Transaction ($ sender , $ loop );
739764 $ promise = $ transaction ->send ($ request );
@@ -794,12 +819,17 @@ public function testCancelTransactionShouldCancelSendingPromise()
794819
795820 // mock sender to resolve promise with the given $redirectResponse in
796821 $ redirectResponse = new Response (301 , array ('Location ' => 'http://example.com/new ' ));
797- $ sender ->expects ($ this ->at (0 ))->method ('send ' )->willReturn (Promise \resolve ($ redirectResponse ));
798822
799823 $ pending = new \React \Promise \Promise (function () { }, $ this ->expectCallableOnce ());
800824
801825 // mock sender to return pending promise which should be cancelled when cancelling result
802- $ sender ->expects ($ this ->at (1 ))->method ('send ' )->willReturn ($ pending );
826+ $ sender ->expects ($ this ->exactly (2 ))->method ('send ' )->withConsecutive (
827+ array ($ this ->anything ()),
828+ array ($ this ->anything ())
829+ )->willReturnOnConsecutiveCalls (
830+ Promise \resolve ($ redirectResponse ),
831+ $ pending
832+ );
803833
804834 $ transaction = new Transaction ($ sender , $ loop );
805835 $ promise = $ transaction ->send ($ request );
0 commit comments