feat: 增加了inArray、hasExtends方法

This commit is contained in:
李东云
2023-03-14 18:29:05 +08:00
parent 7c1efe1a1f
commit de96e288c3
11 changed files with 139 additions and 78 deletions

View File

@@ -9,15 +9,18 @@
namespace Singularity\HDK\Test\Core\Unit;
use Darabonba\GatewaySpi\Models\InterceptorContext\request;
use Singularity\HDK\Core\Service\ExtendService;
use Singularity\HDK\Core\Service\UtilsService;
$service = new ExtendService();
$service = new ExtendService(new UtilsService());
/** @var ExtendService $service */
$service = make(ExtendService::class, ['utils' => new UtilsService()]);
it('asserts no parameters can be parsed.', function (ExtendService $service, $params) {
$service->parse(
request: null,
params: $params
null,
$params
);
$result = $service->getExtends();
expect($result)->toBeArray()->toHaveCount(0)->toBe([]);
@@ -32,17 +35,22 @@ it('asserts no parameters can be parsed.', function (ExtendService $service, $pa
it('asserts query parameters can be parsed.', function () use ($service) {
$result = $service->parse(
null,
params: [
[
'id' => 5,
'extends' => 'a,b',
]
);
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

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