feat: 增加了inArray、hasExtends方法

This commit is contained in:
李东云
2023-01-19 17:43:57 +08:00
parent 3e2d3400b4
commit c83728cad2
4 changed files with 62 additions and 10 deletions

View File

@@ -9,10 +9,11 @@
namespace Singularity\HDK\Test\Core\Unit;
use Hyperf\Utils\ApplicationContext;
use Singularity\HDK\Core\Service\ExtendService;
use Singularity\HDK\Core\Service\UtilsService;
$service = new ExtendService();
$service = make(ExtendService::class, ['utils' => new UtilsService()]);
it('asserts query parameters can be parsed.', function () use ($service) {
$result = $service->parse(
null,
@@ -23,10 +24,15 @@ it('asserts query parameters can be parsed.', function () use ($service) {
);
expect($result)->toBeArray()->toHaveCount(2)->toBe(['a', 'b']);
});
it('asserts has extends', function () use ($service) {
expect($service->hasExtends('a'))->toBeTrue()
->and($service->hasExtends('b'))->toBeTrue()
->and($service->hasExtends('c'))->toBeFalse();
expect($service->hasExtends())->toBeTrue();
});
it('asserts has specify extend', function () use ($service) {
expect($service->hasExtend('a'))->toBeTrue()
->and($service->hasExtend('b'))->toBeTrue()
->and($service->hasExtend('c'))->toBeFalse();
})->depends('it asserts query parameters can be parsed.');
it('asserts parsed extends', function () use ($service) {

View File

@@ -58,5 +58,24 @@ test('断言可以根据参数构建 URL', function (string $url, array $params,
['c' => 'd'],
true,
'http://username:password@127.0.0.1/git/resp?id=1#/page?a=b&c=d',
]
],
])->group('pure', 'utils');
test('断言可以判断是否是数组中的元素', function (
mixed $needle,
array $haystack,
bool $expect,
bool $exceptions = false
) use ($utils) {
try {
expect($utils->inArray($needle, $haystack))->toBe($expect);
} catch (Throwable $e) {
if ($exceptions) {
expect($e::class)->toBe(TypeError::class);
}
}
})->with([
[1, ['1', 2, 3], true, false],
['1', ['1', 2, 3], true, false],
[[1, 2, 3], ['1', 2, 3], false, true],
])->group('pure', 'utils')->only();