Skip to content

Commit cdc1b6b

Browse files
authored
Merge pull request #109 from clue-labs/internet
Update Socket to work around sending secure HTTPS requests with PHP < 7.1.4
2 parents e11eef9 + bd91a89 commit cdc1b6b

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ To run the test suite, go to the project root and run:
131131
$ php vendor/bin/phpunit
132132
```
133133

134+
The test suite also contains a number of functional integration tests that send
135+
test HTTP requests against the online service http://httpbin.org and thus rely
136+
on a stable internet connection.
137+
If you do not want to run these, they can simply be skipped like this:
138+
139+
```bash
140+
$ php vendor/bin/phpunit --exclude-group internet
141+
134142
## License
135143

136144
MIT, see [LICENSE file](LICENSE).

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"php": ">=5.4.0",
88
"guzzlehttp/psr7": "^1.0",
99
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
10-
"react/socket": "^1.0 || ^0.8.2",
11-
"react/stream": "^1.0 || ^0.7 || ^0.6 || ^0.5 || ^0.4.2",
10+
"react/socket": "^1.0 || ^0.8.3",
11+
"react/stream": "^1.0 || ^0.7.1",
1212
"react/promise": "~2.2",
1313
"evenement/evenement": "^3.0 || ^2.0"
1414
},

tests/FunctionalIntegrationTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,67 @@ public function testSuccessfulResponseEmitsEnd()
4646
$loop->run();
4747
}
4848

49+
/** @group internet */
50+
public function testPostDataReturnsData()
51+
{
52+
$loop = Factory::create();
53+
$client = new Client($loop);
54+
55+
$data = str_repeat('.', 33000);
56+
$request = $client->request('POST', 'https://' . (mt_rand(0, 1) === 0 ? 'eu.' : '') . 'httpbin.org/post', array('Content-Length' => strlen($data)));
57+
58+
$buffer = '';
59+
$request->on('response', function (Response $response) use (&$buffer) {
60+
$response->on('data', function ($chunk) use (&$buffer) {
61+
$buffer .= $chunk;
62+
});
63+
});
64+
65+
$request->on('error', 'printf');
66+
$request->on('error', $this->expectCallableNever());
67+
68+
$request->end($data);
69+
70+
$loop->run();
71+
72+
$this->assertNotEquals('', $buffer);
73+
74+
$parsed = json_decode($buffer, true);
75+
$this->assertTrue(is_array($parsed) && isset($parsed['data']));
76+
$this->assertEquals(strlen($data), strlen($parsed['data']));
77+
$this->assertEquals($data, $parsed['data']);
78+
}
79+
80+
/** @group internet */
81+
public function testPostJsonReturnsData()
82+
{
83+
$loop = Factory::create();
84+
$client = new Client($loop);
85+
86+
$data = json_encode(array('numbers' => range(1, 50)));
87+
$request = $client->request('POST', 'https://httpbin.org/post', array('Content-Length' => strlen($data), 'Content-Type' => 'application/json'));
88+
89+
$buffer = '';
90+
$request->on('response', function (Response $response) use (&$buffer) {
91+
$response->on('data', function ($chunk) use (&$buffer) {
92+
$buffer .= $chunk;
93+
});
94+
});
95+
96+
$request->on('error', 'printf');
97+
$request->on('error', $this->expectCallableNever());
98+
99+
$request->end($data);
100+
101+
$loop->run();
102+
103+
$this->assertNotEquals('', $buffer);
104+
105+
$parsed = json_decode($buffer, true);
106+
$this->assertTrue(is_array($parsed) && isset($parsed['json']));
107+
$this->assertEquals(json_decode($data, true), $parsed['json']);
108+
}
109+
49110
/** @group internet */
50111
public function testCancelPendingConnectionEmitsClose()
51112
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy