mirror of
http://124.126.16.154:8888/singularity/hdk-pay.git
synced 2026-01-15 03:55:07 +08:00
test(pay): 添加账户信息查询功能测试
- 新增 QueryAccountInformationTest 以测试账户信息查询功能 - 实现 getAccount 方法的单元测试 - 添加测试引导文件和 HTTP 测试用例基类 - 更新 composer.json 和 composer.lock 文件
This commit is contained in:
@@ -8,6 +8,11 @@
|
||||
"Singularity\\HDK\\Pay\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Singularity\\HDK\\Test\\Pay\\": "tests/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"hyperf": {
|
||||
"config": "Singularity\\HDK\\Pay\\ConfigProvider"
|
||||
@@ -22,7 +27,7 @@
|
||||
"hyperf/contract": "~3.1.0",
|
||||
"hyperf/di": "~3.1.0",
|
||||
"hyperf/guzzle": "3.1.*",
|
||||
"hyperf/http-server": "3.1.*",
|
||||
"hyperf/http-server": "^3.1",
|
||||
"moneyphp/money": "^4.1",
|
||||
"nesbot/carbon": "*",
|
||||
"singularity/hdk-core": "^1.0.0"
|
||||
|
||||
2
composer.lock
generated
2
composer.lock
generated
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "5c422249d0f82f3e0b7725e8763d1b23",
|
||||
"content-hash": "1502e30908a8b64e02da6b75783f3598",
|
||||
"packages": [
|
||||
{
|
||||
"name": "carbonphp/carbon-doctrine-types",
|
||||
|
||||
@@ -42,19 +42,22 @@ final class AccountBalanceRepo implements AccountRepoInterface
|
||||
{
|
||||
$response = $this->requestService->requestGet(
|
||||
url: "/rpc/v2/account/$uid/balance",
|
||||
params: [
|
||||
'type' => join(',', PointType::values())
|
||||
],
|
||||
options: [
|
||||
'headers' => [
|
||||
Header::CONTENT_TYPE => 'application/json',
|
||||
Header::ACCEPT_LANGUAGE => $locale?->value ?? config('translation.locale', Languages::EN),
|
||||
Header::ACCEPT_LANGUAGE => $locale?->value ?? config('translation.locale', Languages::EN->value),
|
||||
'X-SP-ID' => config('app_name'),
|
||||
'X-SITE' => match (strtoupper(config('site', Site::NorthAmerica))) {
|
||||
'X-SITE' => (match (strtoupper(config('site', Site::NorthAmerica->value))) {
|
||||
'CN' => Site::ChinaMainland,
|
||||
default => Site::NorthAmerica,
|
||||
},
|
||||
'X-ENV' => match (strtolower(config('app_env', Environment::Dev))) {
|
||||
})->value,
|
||||
'X-ENV' => (match (strtolower(config('app_env', Environment::Dev->value))) {
|
||||
'prod', 'production' => Environment::Prod,
|
||||
default => Environment::Dev,
|
||||
},
|
||||
})->value,
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
24
tests/Feature/Account/QueryAccountInformationTest.php
Normal file
24
tests/Feature/Account/QueryAccountInformationTest.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* QueryAccountInformationTest.php@Pay
|
||||
*
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2025/8/18
|
||||
*/
|
||||
|
||||
use Singularity\HDK\Pay\Domain\Account\Aggregate\AccountBalance;
|
||||
|
||||
use Singularity\HDK\Pay\Infratracture\Repository\AccountBalanceRepo;
|
||||
|
||||
use function Hyperf\Support\make;
|
||||
|
||||
it('should be able to query account information', function () {
|
||||
$uid = '123456';
|
||||
$repo = make(AccountBalanceRepo::class);
|
||||
$result = $repo->getAccount($uid);
|
||||
expect($result)
|
||||
->toBeInstanceOf(AccountBalance::class)
|
||||
->and($result->getUid())->tobe($uid);
|
||||
});
|
||||
53
tests/HttpTestCase.php
Normal file
53
tests/HttpTestCase.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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 Singularity\HDK\Test\Pay;
|
||||
|
||||
use Hyperf\Testing\Client;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
use function Hyperf\Support\make;
|
||||
|
||||
/**
|
||||
* Class HttpTestCase.
|
||||
* @method get($uri, $data = [], $headers = [])
|
||||
* @method post($uri, $data = [], $headers = [])
|
||||
* @method json($uri, $data = [], $headers = [])
|
||||
* @method file($uri, $data = [], $headers = [])
|
||||
* @method request($method, $path, $options = [])
|
||||
*/
|
||||
abstract class HttpTestCase extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Client
|
||||
*/
|
||||
protected Client $client;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct(?string $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->client = make(Client::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array<string, mixed> $arguments
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function __call(string $name, array $arguments): array
|
||||
{
|
||||
return $this->client->{$name}(...$arguments);
|
||||
}
|
||||
}
|
||||
32
tests/Pest.php
Normal file
32
tests/Pest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Singularity\HDK\Test\Pay\HttpTestCase;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Test Case
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The closure you provide to your tests functions is always bound to a specific PHPUnit tests
|
||||
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
|
||||
| need to change it using the "uses()" function to bind a different classes or traits.
|
||||
|
|
||||
*/
|
||||
|
||||
// uses(HttpTestCase::class)->in('Feature');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Functions
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
|
||||
| project that you don't want to repeat in every file. Here you can also expose helpers as
|
||||
| global functions to help you to reduce the number of lines of code in your tests files.
|
||||
|
|
||||
*/
|
||||
|
||||
/*function something()
|
||||
{
|
||||
// ..
|
||||
}*/
|
||||
@@ -2,19 +2,16 @@
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
use Hyperf\Config\Config;
|
||||
use Hyperf\Context\ApplicationContext;
|
||||
use Hyperf\Contract\ConfigInterface;
|
||||
use Hyperf\Di\ClassLoader;
|
||||
use Hyperf\Di\Container;
|
||||
use Hyperf\Di\Definition\DefinitionSource;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Swoole\Runtime;
|
||||
|
||||
use function Hyperf\Support\env;
|
||||
use function Hyperf\Support\make;
|
||||
|
||||
ini_set('display_errors', 'on');
|
||||
ini_set('display_startup_errors', 'on');
|
||||
@@ -22,16 +19,25 @@ ini_set('display_startup_errors', 'on');
|
||||
error_reporting(E_ALL);
|
||||
date_default_timezone_set('Asia/Shanghai');
|
||||
|
||||
|
||||
!defined('BASE_PATH') && define('BASE_PATH', dirname(__DIR__, 1));
|
||||
!defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL);
|
||||
|
||||
Swoole\Runtime::enableCoroutine(true);
|
||||
Runtime::enableCoroutine(SWOOLE_HOOK_FLAGS);
|
||||
|
||||
require BASE_PATH . '/vendor/autoload.php';
|
||||
Hyperf\Di\ClassLoader::init();
|
||||
ClassLoader::init();
|
||||
|
||||
$container = new Container(new DefinitionSource([]));
|
||||
if (!$container instanceof ContainerInterface) {
|
||||
throw new RuntimeException('The dependency injection container is invalid.');
|
||||
}
|
||||
$container = ApplicationContext::setContainer($container);
|
||||
|
||||
/** @var Config $config */
|
||||
$config = make(Config::class, [
|
||||
[
|
||||
'dependencies' => [],
|
||||
'payment' => [
|
||||
'base_uri' => env('LUX_PAY_BASE_URI', 'http://test-pay.luxcreo.com'),
|
||||
],
|
||||
],
|
||||
]);
|
||||
ApplicationContext::getContainer()->set(ConfigInterface::class, $config);
|
||||
|
||||
Reference in New Issue
Block a user