1
0
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:
Filip Halaxa 2020-04-16 13:30:24 +02:00
parent 89c98b887b
commit 7c0a313c2b
4 changed files with 10 additions and 19 deletions

View File

@ -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

View File

@ -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));

View File

@ -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']);
}
}

View File

@ -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