@@ -307,6 +307,10 @@ public function testConfigUri() {
307
307
* @return void
308
308
*/
309
309
public function testRequest () {
310
+ $ this ->Socket ->expects ($ this ->any ())
311
+ ->method ('read ' )
312
+ ->will ($ this ->returnValue (false ));
313
+
310
314
$ this ->Socket ->reset ();
311
315
312
316
$ response = $ this ->Socket ->request (true );
@@ -589,6 +593,10 @@ public function testRequest() {
589
593
* @return void
590
594
*/
591
595
public function testGetWithSchemeAndPort () {
596
+ $ this ->Socket ->expects ($ this ->any ())
597
+ ->method ('read ' )
598
+ ->will ($ this ->returnValue (false ));
599
+
592
600
$ this ->Socket ->reset ();
593
601
$ request = array (
594
602
'uri ' => array (
@@ -609,6 +617,10 @@ public function testGetWithSchemeAndPort() {
609
617
* @return void
610
618
*/
611
619
public function testRequestWithStringQuery () {
620
+ $ this ->Socket ->expects ($ this ->any ())
621
+ ->method ('read ' )
622
+ ->will ($ this ->returnValue (false ));
623
+
612
624
$ this ->Socket ->reset ();
613
625
$ request = array (
614
626
'uri ' => array (
@@ -642,14 +654,18 @@ public function testRequestNotAllowedUri() {
642
654
*/
643
655
public function testRequest2 () {
644
656
$ this ->Socket ->reset ();
657
+
645
658
$ request = array ('uri ' => 'htpp://www.cakephp.org/ ' );
646
659
$ number = mt_rand (0 , 9999999 );
647
660
$ this ->Socket ->expects ($ this ->any ())->method ('connect ' )->will ($ this ->returnValue (true ));
648
661
$ serverResponse = "HTTP/1.x 200 OK \r\nDate: Mon, 16 Apr 2007 04:14:16 GMT \r\nServer: CakeHttp Server \r\nContent-Type: text/html \r\n\r\n<h1>Hello, your lucky number is " . $ number . "</h1> " ;
649
662
$ this ->Socket ->expects ($ this ->at (0 ))->method ('write ' )
650
663
->with ("GET / HTTP/1.1 \r\nHost: www.cakephp.org \r\nConnection: close \r\nUser-Agent: CakePHP \r\n\r\n" );
651
- $ this ->Socket ->expects ($ this ->at (0 ))->method ('read ' )->will ($ this ->returnValue (false ));
652
- $ this ->Socket ->expects ($ this ->at (1 ))->method ('read ' )->will ($ this ->returnValue ($ serverResponse ));
664
+
665
+ $ this ->Socket ->expects ($ this ->any ())
666
+ ->method ('read ' )
667
+ ->will ($ this ->onConsecutiveCalls ($ serverResponse , false ));
668
+
653
669
$ response = (string )$ this ->Socket ->request ($ request );
654
670
$ this ->assertEquals ($ response , "<h1>Hello, your lucky number is " . $ number . "</h1> " );
655
671
}
@@ -662,7 +678,11 @@ public function testRequest2() {
662
678
public function testRequest3 () {
663
679
$ request = array ('uri ' => 'htpp://www.cakephp.org/ ' );
664
680
$ serverResponse = "HTTP/1.x 200 OK \r\nSet-Cookie: foo=bar \r\nDate: Mon, 16 Apr 2007 04:14:16 GMT \r\nServer: CakeHttp Server \r\nContent-Type: text/html \r\n\r\n<h1>This is a cookie test!</h1> " ;
665
- $ this ->Socket ->expects ($ this ->at (1 ))->method ('read ' )->will ($ this ->returnValue ($ serverResponse ));
681
+
682
+ $ this ->Socket ->expects ($ this ->any ())
683
+ ->method ('read ' )
684
+ ->will ($ this ->onConsecutiveCalls ($ serverResponse , false ));
685
+
666
686
$ this ->Socket ->connected = true ;
667
687
$ this ->Socket ->request ($ request );
668
688
$ result = $ this ->Socket ->response ['cookies ' ];
@@ -711,9 +731,10 @@ public function testRequestWithConstructor() {
711
731
*/
712
732
public function testRequestWithResource () {
713
733
$ serverResponse = "HTTP/1.x 200 OK \r\nDate: Mon, 16 Apr 2007 04:14:16 GMT \r\nServer: CakeHttp Server \r\nContent-Type: text/html \r\n\r\n<h1>This is a test!</h1> " ;
714
- $ this ->Socket ->expects ($ this ->at (1 ))->method ('read ' )->will ($ this ->returnValue ($ serverResponse ));
715
- $ this ->Socket ->expects ($ this ->at (2 ))->method ('read ' )->will ($ this ->returnValue (false ));
716
- $ this ->Socket ->expects ($ this ->at (4 ))->method ('read ' )->will ($ this ->returnValue ($ serverResponse ));
734
+
735
+ $ this ->Socket ->expects ($ this ->any ())
736
+ ->method ('read ' )
737
+ ->will ($ this ->onConsecutiveCalls ($ serverResponse , false , $ serverResponse , false ));
717
738
$ this ->Socket ->connected = true ;
718
739
719
740
$ f = fopen (TMP . 'download.txt ' , 'w ' );
@@ -744,8 +765,10 @@ public function testRequestWithCrossCookie() {
744
765
$ this ->Socket ->config ['request ' ]['cookies ' ] = array ();
745
766
746
767
$ serverResponse = "HTTP/1.x 200 OK \r\nSet-Cookie: foo=bar \r\nDate: Mon, 16 Apr 2007 04:14:16 GMT \r\nServer: CakeHttp Server \r\nContent-Type: text/html \r\n\r\n<h1>This is a test!</h1> " ;
768
+
747
769
$ this ->Socket ->expects ($ this ->at (1 ))->method ('read ' )->will ($ this ->returnValue ($ serverResponse ));
748
770
$ this ->Socket ->expects ($ this ->at (2 ))->method ('read ' )->will ($ this ->returnValue (false ));
771
+
749
772
$ expected = array ('www.cakephp.org ' => array ('foo ' => array ('value ' => 'bar ' )));
750
773
$ this ->Socket ->request ('http://www.cakephp.org/ ' );
751
774
$ this ->assertEquals ($ expected , $ this ->Socket ->config ['request ' ]['cookies ' ]);
@@ -781,8 +804,9 @@ public function testRequestWithCrossCookie() {
781
804
public function testRequestCustomResponse () {
782
805
$ this ->Socket ->connected = true ;
783
806
$ serverResponse = "HTTP/1.x 200 OK \r\nDate: Mon, 16 Apr 2007 04:14:16 GMT \r\nServer: CakeHttp Server \r\nContent-Type: text/html \r\n\r\n<h1>This is a test!</h1> " ;
784
- $ this ->Socket ->expects ($ this ->at (1 ))->method ('read ' )->will ($ this ->returnValue ($ serverResponse ));
785
- $ this ->Socket ->expects ($ this ->at (2 ))->method ('read ' )->will ($ this ->returnValue (false ));
807
+ $ this ->Socket ->expects ($ this ->any ())
808
+ ->method ('read ' )
809
+ ->will ($ this ->onConsecutiveCalls ($ serverResponse , false ));
786
810
787
811
$ this ->Socket ->responseClass = 'CustomResponse ' ;
788
812
$ response = $ this ->Socket ->request ('http://www.cakephp.org/ ' );
@@ -817,6 +841,8 @@ public function testRequestWithRedirectUrlEncoded() {
817
841
$ this ->Socket ->expects ($ this ->at (4 ))
818
842
->method ('read ' )
819
843
->will ($ this ->returnValue ($ serverResponse2 ));
844
+ $ this ->Socket ->expects ($ this ->any ())
845
+ ->method ('read ' )->will ($ this ->returnValue (false ));
820
846
821
847
$ response = $ this ->Socket ->request ($ request );
822
848
$ this ->assertEquals ('<h1>You have been redirected</h1> ' , $ response ->body ());
@@ -834,8 +860,10 @@ public function testRequestWithRedirectAsTrue() {
834
860
);
835
861
$ serverResponse1 = "HTTP/1.x 302 Found \r\nDate: Mon, 16 Apr 2007 04:14:16 GMT \r\nServer: CakeHttp Server \r\nContent-Type: text/html \r\nLocation: http://localhost/anotheruri \r\n\r\n" ;
836
862
$ serverResponse2 = "HTTP/1.x 200 OK \r\nDate: Mon, 16 Apr 2007 04:14:16 GMT \r\nServer: CakeHttp Server \r\nContent-Type: text/html \r\n\r\n<h1>You have been redirected</h1> " ;
837
- $ this ->Socket ->expects ($ this ->at (1 ))->method ('read ' )->will ($ this ->returnValue ($ serverResponse1 ));
838
- $ this ->Socket ->expects ($ this ->at (4 ))->method ('read ' )->will ($ this ->returnValue ($ serverResponse2 ));
863
+
864
+ $ this ->Socket ->expects ($ this ->any ())
865
+ ->method ('read ' )
866
+ ->will ($ this ->onConsecutiveCalls ($ serverResponse1 , false , $ serverResponse2 , false ));
839
867
840
868
$ response = $ this ->Socket ->request ($ request );
841
869
$ this ->assertEquals ('<h1>You have been redirected</h1> ' , $ response ->body ());
@@ -853,8 +881,10 @@ public function testRequestWithRedirectAsInt() {
853
881
);
854
882
$ serverResponse1 = "HTTP/1.x 302 Found \r\nDate: Mon, 16 Apr 2007 04:14:16 GMT \r\nServer: CakeHttp Server \r\nContent-Type: text/html \r\nLocation: http://localhost/anotheruri \r\n\r\n" ;
855
883
$ serverResponse2 = "HTTP/1.x 200 OK \r\nDate: Mon, 16 Apr 2007 04:14:16 GMT \r\nServer: CakeHttp Server \r\nContent-Type: text/html \r\n\r\n<h1>You have been redirected</h1> " ;
856
- $ this ->Socket ->expects ($ this ->at (1 ))->method ('read ' )->will ($ this ->returnValue ($ serverResponse1 ));
857
- $ this ->Socket ->expects ($ this ->at (4 ))->method ('read ' )->will ($ this ->returnValue ($ serverResponse2 ));
884
+
885
+ $ this ->Socket ->expects ($ this ->any ())
886
+ ->method ('read ' )
887
+ ->will ($ this ->onConsecutiveCalls ($ serverResponse1 , false , $ serverResponse2 , false ));
858
888
859
889
$ this ->Socket ->request ($ request );
860
890
$ this ->assertEquals (1 , $ this ->Socket ->request ['redirect ' ]);
@@ -872,8 +902,10 @@ public function testRequestWithRedirectAsIntReachingZero() {
872
902
);
873
903
$ serverResponse1 = "HTTP/1.x 302 Found \r\nDate: Mon, 16 Apr 2007 04:14:16 GMT \r\nServer: CakeHttp Server \r\nContent-Type: text/html \r\nLocation: http://localhost/oneruri \r\n\r\n" ;
874
904
$ serverResponse2 = "HTTP/1.x 302 Found \r\nDate: Mon, 16 Apr 2007 04:14:16 GMT \r\nServer: CakeHttp Server \r\nContent-Type: text/html \r\nLocation: http://localhost/anotheruri \r\n\r\n" ;
875
- $ this ->Socket ->expects ($ this ->at (1 ))->method ('read ' )->will ($ this ->returnValue ($ serverResponse1 ));
876
- $ this ->Socket ->expects ($ this ->at (4 ))->method ('read ' )->will ($ this ->returnValue ($ serverResponse2 ));
905
+
906
+ $ this ->Socket ->expects ($ this ->any ())
907
+ ->method ('read ' )
908
+ ->will ($ this ->onConsecutiveCalls ($ serverResponse1 , false , $ serverResponse2 , false ));
877
909
878
910
$ response = $ this ->Socket ->request ($ request );
879
911
$ this ->assertEquals (0 , $ this ->Socket ->request ['redirect ' ]);
@@ -1113,6 +1145,9 @@ public function testHead() {
1113
1145
* @return void
1114
1146
*/
1115
1147
public function testAuth () {
1148
+ $ this ->Socket ->expects ($ this ->any ())
1149
+ ->method ('read ' )->will ($ this ->returnValue (false ));
1150
+
1116
1151
$ this ->Socket ->get ('http://mark:secret@example.com/test ' );
1117
1152
$ this ->assertTrue (strpos ($ this ->Socket ->request ['header ' ], 'Authorization: Basic bWFyazpzZWNyZXQ= ' ) !== false );
1118
1153
@@ -1154,6 +1189,9 @@ public function testAuth() {
1154
1189
* @return void
1155
1190
*/
1156
1191
public function testConsecutiveGetResetsAuthCredentials () {
1192
+ $ this ->Socket ->expects ($ this ->any ())
1193
+ ->method ('read ' )->will ($ this ->returnValue (false ));
1194
+
1157
1195
$ this ->Socket ->get ('http://mark:secret@example.com/test ' );
1158
1196
$ this ->assertEquals ('mark ' , $ this ->Socket ->request ['uri ' ]['user ' ]);
1159
1197
$ this ->assertEquals ('secret ' , $ this ->Socket ->request ['uri ' ]['pass ' ]);
@@ -1813,6 +1851,9 @@ public function testPartialReset() {
1813
1851
* @return void
1814
1852
*/
1815
1853
public function testConfigContext () {
1854
+ $ this ->Socket ->expects ($ this ->any ())
1855
+ ->method ('read ' )->will ($ this ->returnValue (false ));
1856
+
1816
1857
$ this ->Socket ->reset ();
1817
1858
$ this ->Socket ->request ('http://example.com ' );
1818
1859
$ this ->assertTrue ($ this ->Socket ->config ['context ' ]['ssl ' ]['verify_peer ' ]);
@@ -1869,8 +1910,10 @@ public function statusProvider() {
1869
1910
public function testResponseStatusParsing ($ status , $ code , $ msg = '' ) {
1870
1911
$ this ->Socket ->connected = true ;
1871
1912
$ serverResponse = $ status . "\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT \r\nServer: CakeHttp Server \r\n\r\n<h1>This is a test!</h1> " ;
1872
- $ this ->Socket ->expects ($ this ->at (1 ))->method ('read ' )->will ($ this ->returnValue ($ serverResponse ));
1873
- $ this ->Socket ->expects ($ this ->at (2 ))->method ('read ' )->will ($ this ->returnValue (false ));
1913
+
1914
+ $ this ->Socket ->expects ($ this ->any ())
1915
+ ->method ('read ' )
1916
+ ->will ($ this ->onConsecutiveCalls ($ serverResponse , false ));
1874
1917
1875
1918
$ response = $ this ->Socket ->request ('http://www.cakephp.org/ ' );
1876
1919
$ this ->assertInstanceOf ('HttpSocketResponse ' , $ response );
0 commit comments