mirror of
http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore.git
synced 2026-01-15 05:05:04 +08:00
63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?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');
|