Skip to content

Commit

Permalink
Update Socket to send secure HTTPS requests with PHP < 7.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Sep 8, 2017
1 parent 7de47c7 commit 2125c7d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
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://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 2125c7d

Please sign in to comment.