mirror of
http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore.git
synced 2026-01-15 03:45:06 +08:00
feat(utils): 重写了构造URL的方法,增加对应的单元测试
This commit is contained in:
@@ -47,4 +47,4 @@ it('asserts oss policy can be generated', function ($setDir, $isImage, $maxSize)
|
||||
->and($signature)->toBe($sign);
|
||||
})->with([
|
||||
['uploaded', true, 1048576000],
|
||||
])->only();
|
||||
]);
|
||||
|
||||
62
tests/Unit/UtilsServiceTest.php
Normal file
62
tests/Unit/UtilsServiceTest.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* UtilsServiceTest.php@HDK-Core
|
||||
*
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2023/1/12
|
||||
*/
|
||||
|
||||
use Singularity\HDK\Core\Service\UtilsService;
|
||||
|
||||
$utils = new UtilsService();
|
||||
|
||||
$length_data = [];
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
try {
|
||||
$length_data[] = random_int(1, 9);
|
||||
} catch (Exception $e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
test('断言验证码可以正常生成指定长度', function (int $length) use ($utils) {
|
||||
try {
|
||||
$code = $utils->generateSecureCode($length);
|
||||
expect($code)->toHaveLength($length);
|
||||
} catch (Exception $e) {
|
||||
expect($e)->toBeNull();
|
||||
}
|
||||
})->with($length_data)->group('pure', 'utils');
|
||||
|
||||
test('断言可以根据参数构建 URL', function (string $url, array $params, bool $anchorQuery, string $expect) use ($utils) {
|
||||
$url = $utils->buildUrl(url: $url, moreQueries: $params, anchorQuery: $anchorQuery);
|
||||
expect($url)->toBe($expect);
|
||||
})->with([
|
||||
['baidu.com/list', ['a' => 'b'], false, 'baidu.com/list?a=b'],
|
||||
['/api/v1/doc/categories/1?order=id', ['sort' => 'desc'], false, '/api/v1/doc/categories/1?order=id&sort=desc'],
|
||||
['//google.com/search?c=d', ['a' => 'b'], false, '//google.com/search?c=d&a=b'],
|
||||
[
|
||||
'https://support.luxcreo.com/#/support?id=123',
|
||||
['category' => 'abc'],
|
||||
true,
|
||||
'https://support.luxcreo.com/#/support?id=123&category=abc',
|
||||
],
|
||||
[
|
||||
'https://support.luxcreo.com/#/support',
|
||||
['category' => 'abc'],
|
||||
true,
|
||||
'https://support.luxcreo.com/#/support?category=abc',
|
||||
],
|
||||
[
|
||||
'ssh://username:password@127.0.0.1/git/resp?id=1#/page?a=b',
|
||||
['c' => 'd'],
|
||||
false,
|
||||
'ssh://username:password@127.0.0.1/git/resp?id=1&c=d#/page?a=b',
|
||||
],
|
||||
[
|
||||
'http://username:password@127.0.0.1/git/resp?id=1#/page?a=b',
|
||||
['c' => 'd'],
|
||||
true,
|
||||
'http://username:password@127.0.0.1/git/resp?id=1#/page?a=b&c=d',
|
||||
]
|
||||
])->group('pure', 'utils');
|
||||
Reference in New Issue
Block a user