Skip to content

Commit

Permalink
Merge pull request #109 from clue-labs/internet
Browse files Browse the repository at this point in the history
Update Socket to work around sending secure HTTPS requests with PHP < 7.1.4
  • Loading branch information
WyriHaximus authored Sep 8, 2017
2 parents e11eef9 + bd91a89 commit cdc1b6b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
61 changes: 61 additions & 0 deletions tests/FunctionalIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit cdc1b6b

Please sign in to comment.