diff --git a/README.md b/README.md index 82845b2..6d17a2b 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,14 @@ To run the test suite, go to the project root and run: $ php vendor/bin/phpunit ``` +The test suite also contains a number of functional integration tests that send +test HTTP requests against the online service http://httpbin.org and thus rely +on a stable internet connection. +If you do not want to run these, they can simply be skipped like this: + +```bash +$ php vendor/bin/phpunit --exclude-group internet + ## License MIT, see [LICENSE file](LICENSE). diff --git a/composer.json b/composer.json index aa0e86b..c6c7b7e 100644 --- a/composer.json +++ b/composer.json @@ -7,8 +7,8 @@ "php": ">=5.4.0", "guzzlehttp/psr7": "^1.0", "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3", - "react/socket": "^1.0 || ^0.8.2", - "react/stream": "^1.0 || ^0.7 || ^0.6 || ^0.5 || ^0.4.2", + "react/socket": "^1.0 || ^0.8.3", + "react/stream": "^1.0 || ^0.7.1", "react/promise": "~2.2", "evenement/evenement": "^3.0 || ^2.0" }, diff --git a/tests/FunctionalIntegrationTest.php b/tests/FunctionalIntegrationTest.php index c59c8a4..cfa6800 100644 --- a/tests/FunctionalIntegrationTest.php +++ b/tests/FunctionalIntegrationTest.php @@ -46,6 +46,67 @@ public function testSuccessfulResponseEmitsEnd() $loop->run(); } + /** @group internet */ + public function testPostDataReturnsData() + { + $loop = Factory::create(); + $client = new Client($loop); + + $data = str_repeat('.', 33000); + $request = $client->request('POST', 'https://' . (mt_rand(0, 1) === 0 ? 'eu.' : '') . 'httpbin.org/post', array('Content-Length' => strlen($data))); + + $buffer = ''; + $request->on('response', function (Response $response) use (&$buffer) { + $response->on('data', function ($chunk) use (&$buffer) { + $buffer .= $chunk; + }); + }); + + $request->on('error', 'printf'); + $request->on('error', $this->expectCallableNever()); + + $request->end($data); + + $loop->run(); + + $this->assertNotEquals('', $buffer); + + $parsed = json_decode($buffer, true); + $this->assertTrue(is_array($parsed) && isset($parsed['data'])); + $this->assertEquals(strlen($data), strlen($parsed['data'])); + $this->assertEquals($data, $parsed['data']); + } + + /** @group internet */ + public function testPostJsonReturnsData() + { + $loop = Factory::create(); + $client = new Client($loop); + + $data = json_encode(array('numbers' => range(1, 50))); + $request = $client->request('POST', 'https://httpbin.org/post', array('Content-Length' => strlen($data), 'Content-Type' => 'application/json')); + + $buffer = ''; + $request->on('response', function (Response $response) use (&$buffer) { + $response->on('data', function ($chunk) use (&$buffer) { + $buffer .= $chunk; + }); + }); + + $request->on('error', 'printf'); + $request->on('error', $this->expectCallableNever()); + + $request->end($data); + + $loop->run(); + + $this->assertNotEquals('', $buffer); + + $parsed = json_decode($buffer, true); + $this->assertTrue(is_array($parsed) && isset($parsed['json'])); + $this->assertEquals(json_decode($data, true), $parsed['json']); + } + /** @group internet */ public function testCancelPendingConnectionEmitsClose() {