2022-12-20 16:45:31 +08:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* ExtendServiceTest.php@HDK-Core
|
|
|
|
|
*
|
|
|
|
|
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
|
|
|
|
* Powered by PhpStorm
|
|
|
|
|
* Created on 2022/12/20
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace Singularity\HDK\Test\Core\Unit;
|
|
|
|
|
|
2023-04-25 17:04:57 +08:00
|
|
|
use Hyperf\Context\Context;
|
2022-12-20 16:45:31 +08:00
|
|
|
use Singularity\HDK\Core\Service\ExtendService;
|
2023-03-14 18:29:05 +08:00
|
|
|
use Singularity\HDK\Core\Service\UtilsService;
|
2022-12-20 16:45:31 +08:00
|
|
|
|
2023-12-04 17:12:12 +08:00
|
|
|
use function Hyperf\Support\make;
|
|
|
|
|
|
2023-03-14 18:29:05 +08:00
|
|
|
/** @var ExtendService $service */
|
|
|
|
|
$service = make(ExtendService::class, ['utils' => new UtilsService()]);
|
2023-02-02 15:44:26 +08:00
|
|
|
it('asserts no parameters can be parsed.', function (ExtendService $service, $params) {
|
2023-02-01 21:11:13 +08:00
|
|
|
$service->parse(
|
2023-03-14 18:29:05 +08:00
|
|
|
null,
|
|
|
|
|
$params
|
2023-02-01 21:11:13 +08:00
|
|
|
);
|
|
|
|
|
$result = $service->getExtends();
|
2023-04-25 17:04:57 +08:00
|
|
|
expect($result)->toBeArray()->toBe([])->toHaveCount(0)->toBe([]);
|
2023-02-02 15:44:26 +08:00
|
|
|
})->with([
|
|
|
|
|
[$service, null],
|
|
|
|
|
[$service, ''],
|
|
|
|
|
[$service, []],
|
|
|
|
|
[$service, ['extends' => '']],
|
|
|
|
|
[$service, ['extends' => null]],
|
|
|
|
|
]);
|
2023-02-01 21:11:13 +08:00
|
|
|
|
2023-04-25 17:04:57 +08:00
|
|
|
it('asserts has no specify extend', function () use ($service) {
|
|
|
|
|
Context::destroy(ExtendService::class);
|
|
|
|
|
expect($service->hasExtend('a'))->toBeFalse();
|
|
|
|
|
})->depends('it asserts query parameters can be parsed.');
|
|
|
|
|
|
2022-12-20 16:45:31 +08:00
|
|
|
it('asserts query parameters can be parsed.', function () use ($service) {
|
|
|
|
|
$result = $service->parse(
|
|
|
|
|
null,
|
2023-03-14 18:29:05 +08:00
|
|
|
[
|
2022-12-20 16:45:31 +08:00
|
|
|
'id' => 5,
|
|
|
|
|
'extends' => 'a,b',
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
expect($result)->toBeArray()->toHaveCount(2)->toBe(['a', 'b']);
|
|
|
|
|
});
|
2023-03-14 18:29:05 +08:00
|
|
|
|
2022-12-20 16:45:31 +08:00
|
|
|
it('asserts has extends', function () use ($service) {
|
2023-04-25 17:04:57 +08:00
|
|
|
Context::set(ExtendService::class, ['a', 'b']);
|
2023-03-14 18:29:05 +08:00
|
|
|
expect($service->hasExtends())->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('asserts has specify extend', function () use ($service) {
|
2023-04-25 17:04:57 +08:00
|
|
|
Context::set(ExtendService::class, ['a', 'b']);
|
2023-03-14 18:29:05 +08:00
|
|
|
expect($service->hasExtend('a'))->toBeTrue()
|
|
|
|
|
->and($service->hasExtend('b'))->toBeTrue()
|
|
|
|
|
->and($service->hasExtend('c'))->toBeFalse();
|
2022-12-20 16:45:31 +08:00
|
|
|
})->depends('it asserts query parameters can be parsed.');
|
|
|
|
|
|
2023-04-25 17:04:57 +08:00
|
|
|
// it('asserts parsed extends', function () use ($service) {
|
|
|
|
|
// $extends = $service->getExtends();
|
|
|
|
|
// expect($extends)->toBeArray()->toMatchArray([
|
|
|
|
|
// 'a',
|
|
|
|
|
// 'b',
|
|
|
|
|
// ]);
|
|
|
|
|
// })->depends('it asserts query parameters can be parsed.');
|