1010use Clue \React \Buzz \Message \ResponseException ;
1111use Clue \React \Block ;
1212use React \Stream \ReadableStream ;
13+ use Psr \Http \Message \ServerRequestInterface ;
14+ use React \Http \Response ;
15+ use React \Promise \Stream ;
1316
1417class FunctionalBrowserTest extends TestCase
1518{
@@ -25,28 +28,33 @@ public function setUp()
2528 $ this ->browser = new Browser ($ this ->loop );
2629 }
2730
31+ /** @group online */
2832 public function testSimpleRequest ()
2933 {
3034 Block \await ($ this ->browser ->get ($ this ->base . 'get ' ), $ this ->loop );
3135 }
3236
37+ /** @group online */
3338 public function testRedirectRequestRelative ()
3439 {
3540 Block \await ($ this ->browser ->get ($ this ->base . 'redirect-to?url=get ' ), $ this ->loop );
3641 }
3742
43+ /** @group online */
3844 public function testRedirectRequestAbsolute ()
3945 {
4046 Block \await ($ this ->browser ->get ($ this ->base . 'redirect-to?url= ' . urlencode ($ this ->base . 'get ' )), $ this ->loop );
4147 }
4248
49+ /** @group online */
4350 public function testNotFollowingRedirectsResolvesWithRedirectResult ()
4451 {
4552 $ browser = $ this ->browser ->withOptions (array ('followRedirects ' => false ));
4653
4754 Block \await ($ browser ->get ($ this ->base . 'redirect/3 ' ), $ this ->loop );
4855 }
4956
57+ /** @group online */
5058 public function testRejectingRedirectsRejects ()
5159 {
5260 $ browser = $ this ->browser ->withOptions (array ('maxRedirects ' => 0 ));
@@ -55,6 +63,7 @@ public function testRejectingRedirectsRejects()
5563 Block \await ($ browser ->get ($ this ->base . 'redirect/3 ' ), $ this ->loop );
5664 }
5765
66+ /** @group online */
5867 public function testCanAccessHttps ()
5968 {
6069 if (!function_exists ('stream_socket_enable_crypto ' )) {
@@ -64,6 +73,7 @@ public function testCanAccessHttps()
6473 Block \await ($ this ->browser ->get ('https://www.google.com/ ' ), $ this ->loop );
6574 }
6675
76+ /** @group online */
6777 public function testVerifyPeerEnabledForBadSslRejects ()
6878 {
6979 if (!function_exists ('stream_socket_enable_crypto ' )) {
@@ -89,6 +99,7 @@ public function testVerifyPeerEnabledForBadSslRejects()
8999 Block \await ($ browser ->get ('https://self-signed.badssl.com/ ' ), $ this ->loop );
90100 }
91101
102+ /** @group online */
92103 public function testVerifyPeerDisabledForBadSslResolves ()
93104 {
94105 if (!function_exists ('stream_socket_enable_crypto ' )) {
@@ -113,12 +124,14 @@ public function testVerifyPeerDisabledForBadSslResolves()
113124 Block \await ($ browser ->get ('https://self-signed.badssl.com/ ' ), $ this ->loop );
114125 }
115126
127+ /** @group online */
116128 public function testInvalidPort ()
117129 {
118130 $ this ->setExpectedException ('RuntimeException ' );
119131 Block \await ($ this ->browser ->get ('http://www.google.com:443/ ' ), $ this ->loop );
120132 }
121133
134+ /** @group online */
122135 public function testErrorStatusCodeRejectsWithResponseException ()
123136 {
124137 try {
@@ -132,6 +145,7 @@ public function testErrorStatusCodeRejectsWithResponseException()
132145 }
133146 }
134147
148+ /** @group online */
135149 public function testPostString ()
136150 {
137151 $ response = Block \await ($ this ->browser ->post ($ this ->base . 'post ' , array (), 'hello world ' ), $ this ->loop );
@@ -142,6 +156,28 @@ public function testPostString()
142156
143157 public function testPostStreamChunked ()
144158 {
159+ // httpbin used to support `Transfer-Encoding: chunked` for requests,
160+ // but not rejects those, so let's start our own server instance
161+ $ that = $ this ;
162+ $ server = new \React \Http \Server (function (ServerRequestInterface $ request ) use ($ that ) {
163+ $ that ->assertFalse ($ request ->hasHeader ('Content-Length ' ));
164+ $ that ->assertNull ($ request ->getBody ()->getSize ());
165+
166+ return Stream \buffer ($ request ->getBody ())->then (function ($ body ) {
167+ return new Response (
168+ 200 ,
169+ array (),
170+ json_encode (array (
171+ 'data ' => $ body
172+ ))
173+ );
174+ });
175+ });
176+ $ socket = new \React \Socket \Server (0 , $ this ->loop );
177+ $ server ->listen ($ socket );
178+
179+ $ this ->base = str_replace ('tcp: ' , 'http: ' , $ socket ->getAddress ()) . '/ ' ;
180+
145181 $ stream = new ReadableStream ();
146182
147183 $ this ->loop ->addTimer (0.001 , function () use ($ stream ) {
@@ -153,8 +189,11 @@ public function testPostStreamChunked()
153189 $ data = json_decode ((string )$ response ->getBody (), true );
154190
155191 $ this ->assertEquals ('hello world ' , $ data ['data ' ]);
192+
193+ $ socket ->close ();
156194 }
157195
196+ /** @group online */
158197 public function testPostStreamKnownLength ()
159198 {
160199 $ stream = new ReadableStream ();
@@ -170,6 +209,7 @@ public function testPostStreamKnownLength()
170209 $ this ->assertEquals ('hello world ' , $ data ['data ' ]);
171210 }
172211
212+ /** @group online */
173213 public function testPostStreamClosed ()
174214 {
175215 $ stream = new ReadableStream ();
0 commit comments