mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Fixed http client does not works when using guzzle 7.0 and curl hook for hyperf/testing
. (#2624)
* Update HttpClient.php * Create HttpClientTest.php * Update HttpClientTest.php * Update CHANGELOG-2.0.md
This commit is contained in:
parent
df2ab77895
commit
38d12e4e5d
@ -11,6 +11,7 @@
|
||||
- [#2594](https://github.com/hyperf/hyperf/pull/2594) Fixed crontab does not stops when using signal.
|
||||
- [#2601](https://github.com/hyperf/hyperf/pull/2601) Fixed `@property` will be replaced by `@property-read` when the property has `getter` and `setter` at the same time.
|
||||
- [#2607](https://github.com/hyperf/hyperf/pull/2607) Fixed memory leak in `RetryAnnotationAspect`.
|
||||
- [#2624](https://github.com/hyperf/hyperf/pull/2624) Fixed http client does not works when using guzzle 7.0 and curl hook for `hyperf/testing`.
|
||||
|
||||
## Optimized
|
||||
|
||||
|
@ -13,7 +13,9 @@ namespace Hyperf\Testing;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Hyperf\Contract\PackerInterface;
|
||||
use Hyperf\Guzzle\CoroutineHandler;
|
||||
use Hyperf\Utils\Arr;
|
||||
use Hyperf\Utils\Coroutine;
|
||||
use Hyperf\Utils\Packer\JsonPacker;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
@ -38,9 +40,14 @@ class HttpClient
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->packer = $packer ?? new JsonPacker();
|
||||
$handler = null;
|
||||
if (Coroutine::inCoroutine()) {
|
||||
$handler = new CoroutineHandler();
|
||||
}
|
||||
$this->client = new Client([
|
||||
'base_uri' => $baseUri,
|
||||
'timeout' => 2,
|
||||
'handler' => $handler,
|
||||
]);
|
||||
}
|
||||
|
||||
|
55
src/testing/tests/HttpClientTest.php
Normal file
55
src/testing/tests/HttpClientTest.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
namespace tests;
|
||||
|
||||
use Hyperf\Testing\HttpClient;
|
||||
use Mockery;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class HttpClientTest extends TestCase
|
||||
{
|
||||
protected function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group NonCoroutine
|
||||
*/
|
||||
public function testJsonRequest()
|
||||
{
|
||||
run(function () {
|
||||
$client = new HttpClient(Mockery::mock(ContainerInterface::class), null, 'http://127.0.0.1:4151');
|
||||
|
||||
$data = $client->get('/stats', [
|
||||
'format' => 'json',
|
||||
]);
|
||||
|
||||
$this->assertIsArray($data);
|
||||
}, SWOOLE_HOOK_ALL);
|
||||
|
||||
run(function () {
|
||||
$client = new HttpClient(Mockery::mock(ContainerInterface::class), null, 'http://127.0.0.1:4151');
|
||||
|
||||
$data = $client->get('/stats', [
|
||||
'format' => 'json',
|
||||
]);
|
||||
|
||||
$this->assertIsArray($data);
|
||||
}, SWOOLE_HOOK_ALL & ~SWOOLE_HOOK_CURL);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user