mirror of
http://124.126.16.154:8888/singularity/hdk-skeleton.git
synced 2026-01-15 03:35:06 +08:00
72 lines
2.2 KiB
PHP
72 lines
2.2 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\Config\config;
|
|
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(?string $name = null)
|
|
{
|
|
parent::__construct($name);
|
|
$this->client = make(Client::class);
|
|
}
|
|
|
|
/**
|
|
* @param string $name
|
|
* @param array<int, mixed> $arguments
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function __call(string $name, array $arguments): array
|
|
{
|
|
$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 . config('common.token.basic.salt'))
|
|
)
|
|
)
|
|
);
|
|
return $this->client->{$name}($uri, $data, $headers);
|
|
}
|
|
}
|