mirror of
http://124.126.16.154:8888/singularity/hdk-skeleton.git
synced 2026-01-15 05:35:07 +08:00
65 lines
2.0 KiB
PHP
65 lines
2.0 KiB
PHP
<?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\Client;
|
|
use Lmc\HttpConstants\Header;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Singularity\HDK\Core\Enumerations\Http\Header\RFCs\RFC7617;
|
|
|
|
use function Hyperf\Support\make;
|
|
|
|
/**
|
|
* Class HttpTestCase.
|
|
* @method get($uri, $data = [], $headers = [], $uid = 'TDD_MOCK_PERSONAL_USER_1')
|
|
* @method post($uri, $data = [], $headers = [], $uid = 'TDD_MOCK_PERSONAL_USER_1')
|
|
* @method put($uri, $data = [], $headers = [], $uid = 'TDD_MOCK_PERSONAL_USER_1')
|
|
* @method patch($uri, $data = [], $headers = [], $uid = 'TDD_MOCK_PERSONAL_USER_1')
|
|
* @method delete($uri, $data = [], $headers = [], $uid = 'TDD_MOCK_PERSONAL_USER_1')
|
|
* @method json($uri, $data = [], $headers = [], $uid = 'TDD_MOCK_PERSONAL_USER_1')
|
|
* @method file($uri, $data = [], $headers = [], $uid = 'TDD_MOCK_PERSONAL_USER_1')
|
|
* @method request($method, $path, $options = [])
|
|
*/
|
|
abstract class HttpTestCase extends TestCase
|
|
{
|
|
protected Client $client;
|
|
|
|
public function __construct($name = null, array $data = [], $dataName = '')
|
|
{
|
|
parent::__construct($name, $data, $dataName);
|
|
$this->client = make(Client::class);
|
|
}
|
|
|
|
public function __call($name, $arguments)
|
|
{
|
|
$uri = $arguments[0];
|
|
$data = $arguments[1] ?? [];
|
|
$headers = $arguments[2] ?? [];
|
|
$uid = $arguments[3] ?? 'TDD_MOCK_PERSONAL_USER_1';
|
|
|
|
$headers[Header::ACCEPT] ??= 'application/json';
|
|
$headers[Header::AUTHORIZATION] ??= sprintf(
|
|
'%s %s',
|
|
RFC7617::BASIC,
|
|
base64_encode(
|
|
sprintf(
|
|
'%s:%s',
|
|
$uid,
|
|
md5($uid . \Hyperf\Config\config('common.token.basic.salt'))
|
|
)
|
|
)
|
|
);
|
|
return $this->client->{$name}($uri, $data, $headers);
|
|
}
|
|
}
|