test(http): 完成并通过了 http 请求的测试

Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
This commit is contained in:
李东云
2023-09-26 10:54:44 +08:00
parent 4032d67f1e
commit 7a209e876f
2 changed files with 11 additions and 5 deletions

View File

@@ -10,7 +10,6 @@ use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Utils;
use Hyperf\Codec\Json;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Guzzle\ClientFactory;
use Psr\Http\Message\ResponseInterface;
use Singularity\HDK\Core\Service\AbstractSingleton;
@@ -28,7 +27,6 @@ final class RequestService extends AbstractSingleton
{
// public const TIMEOUT = 20;
#[Inject]
private ClientFactory $client;
/**
@@ -42,6 +40,9 @@ final class RequestService extends AbstractSingleton
public function __construct(array $options = [])
{
$this->setOptions($options);
/** @var ClientFactory $client */
$client = \Hyperf\Support\make(ClientFactory::class);
$this->client = $client;
}
/**

View File

@@ -30,7 +30,12 @@ class RequestServiceTest
test('Http 请求服务可以正常使用', function () {
/** @var RequestServiceTest $class */
$class = \Hyperf\Support\make(RequestServiceTest::class);
$response = $class->getInstance()->requestGet('https://baidu.com/');
$response = $class->getInstance()->requestGet('http://baidu.com/');
$content = $response->getBody()->getContents();
expect($content)->toBe('');
})->only();
expect($content)->toBe(<<<HTML
<html>
<meta http-equiv="refresh" content="0;url=http://www.baidu.com/">
</html>
HTML);
});