mirror of
https://github.com/halaxa/json-machine.git
synced 2025-01-18 05:28:14 +01:00
Definition of deprecated httpClientChunks moved to examples
This commit is contained in:
parent
89c98b887b
commit
7c0a313c2b
@ -139,7 +139,7 @@ Guzzle uses its own streams, but they can be converted back to PHP streams by ca
|
||||
|
||||
### Symfony HttpClient
|
||||
A stream response of Symfony HttpClient works as iterator. And because JSON Machine is
|
||||
based on iterators, the integration with Symfony HttpClient is very simple. See working
|
||||
based on iterators, the integration with Symfony HttpClient is very simple. See
|
||||
[HttpClient example](src/examples/symfonyHttpClient.php).
|
||||
|
||||
## Efficiency of parsing streams/files
|
||||
|
@ -2,10 +2,17 @@
|
||||
|
||||
use JsonMachine\JsonMachine;
|
||||
use Symfony\Component\HttpClient\HttpClient;
|
||||
use function JsonMachine\httpClientChunks;
|
||||
use Symfony\Contracts\HttpClient\ResponseStreamInterface;
|
||||
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
function httpClientChunks(ResponseStreamInterface $responseStream)
|
||||
{
|
||||
foreach ($responseStream as $chunk) {
|
||||
yield $chunk->getContent();
|
||||
}
|
||||
}
|
||||
|
||||
$client = HttpClient::create();
|
||||
$response = $client->request('GET', 'https://httpbin.org/anything?key=value');
|
||||
$jsonChunks = httpClientChunks($client->stream($response));
|
||||
|
@ -26,20 +26,4 @@ class FunctionsTest extends \PHPUnit_Framework_TestCase
|
||||
[[(object)["one" => "two"]], [["one" => "two"]]],
|
||||
];
|
||||
}
|
||||
|
||||
public function testHttpClientChunks()
|
||||
{
|
||||
if (PHP_VERSION_ID < 70205) {
|
||||
$this->markTestSkipped("Symfony HttpClient supports PHP >= 7.2.5");
|
||||
}
|
||||
|
||||
$url = 'https://httpbin.org/anything?key=value';
|
||||
$client = HttpClient::create();
|
||||
$response = $client->request('GET', $url);
|
||||
|
||||
$this->assertSame(200, $response->getStatusCode());
|
||||
|
||||
$result = json_decode(implode(iterator_to_array(httpClientChunks($client->stream($response)))), true);
|
||||
$this->assertSame(['key'=>'value'], $result['args']);
|
||||
}
|
||||
}
|
||||
|
@ -51,5 +51,5 @@ do
|
||||
--user "$(id -u):$(id -g)" \
|
||||
--env COMPOSER_CACHE_DIR=/dev/null \
|
||||
"$CONTAINER_NAME" \
|
||||
test/run.sh "$@"
|
||||
test/run.sh "$@" || true
|
||||
done
|
||||
|
Loading…
x
Reference in New Issue
Block a user