2023-09-26 10:44:00 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* RequestServiceTest.php@Core
|
|
|
|
|
*
|
|
|
|
|
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
|
|
|
|
* Powered by PhpStorm
|
|
|
|
|
* Created on 2023/9/20
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace Singularity\HDK\Test\Core\Unit;
|
2023-10-30 14:30:13 +08:00
|
|
|
|
2023-09-26 10:44:00 +08:00
|
|
|
use Singularity\HDK\Core\Http\RequestService;
|
|
|
|
|
use Singularity\HDK\Core\Http\RequestServiceFactory;
|
2023-10-30 14:30:13 +08:00
|
|
|
use Teapot\StatusCode\RFC\RFC7231;
|
2023-09-26 10:44:00 +08:00
|
|
|
|
2023-12-14 16:03:23 +08:00
|
|
|
use function Hyperf\Support\make;
|
|
|
|
|
|
2023-09-26 10:44:00 +08:00
|
|
|
class RequestServiceTest
|
|
|
|
|
{
|
|
|
|
|
private RequestService $service;
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->service = RequestServiceFactory::make();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getInstance(): RequestService
|
|
|
|
|
{
|
|
|
|
|
return $this->service;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test('Http 请求服务可以正常使用', function () {
|
|
|
|
|
/** @var RequestServiceTest $class */
|
2023-12-14 16:03:23 +08:00
|
|
|
$class = make(RequestServiceTest::class);
|
2023-10-30 14:30:13 +08:00
|
|
|
$response = $class->getInstance()->setOptions([
|
|
|
|
|
'allow_redirects' => false,
|
|
|
|
|
])->requestGet('https://www.baidu.com');
|
|
|
|
|
expect($response->getStatusCode())->toBe(RFC7231::OK);
|
2023-09-26 10:54:44 +08:00
|
|
|
});
|