Files
hdk-core/tests/Unit/ExtendServiceTest.php
2023-12-04 17:12:12 +08:00

70 lines
2.1 KiB
PHP

<?php
/**
* ExtendServiceTest.php@HDK-Core
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2022/12/20
*/
namespace Singularity\HDK\Test\Core\Unit;
use Hyperf\Context\Context;
use Singularity\HDK\Core\Service\ExtendService;
use Singularity\HDK\Core\Service\UtilsService;
use function Hyperf\Support\make;
/** @var ExtendService $service */
$service = make(ExtendService::class, ['utils' => new UtilsService()]);
it('asserts no parameters can be parsed.', function (ExtendService $service, $params) {
$service->parse(
null,
$params
);
$result = $service->getExtends();
expect($result)->toBeArray()->toBe([])->toHaveCount(0)->toBe([]);
})->with([
[$service, null],
[$service, ''],
[$service, []],
[$service, ['extends' => '']],
[$service, ['extends' => null]],
]);
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.');
it('asserts query parameters can be parsed.', function () use ($service) {
$result = $service->parse(
null,
[
'id' => 5,
'extends' => 'a,b',
]
);
expect($result)->toBeArray()->toHaveCount(2)->toBe(['a', 'b']);
});
it('asserts has extends', function () use ($service) {
Context::set(ExtendService::class, ['a', 'b']);
expect($service->hasExtends())->toBeTrue();
});
it('asserts has specify extend', function () use ($service) {
Context::set(ExtendService::class, ['a', 'b']);
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) {
// $extends = $service->getExtends();
// expect($extends)->toBeArray()->toMatchArray([
// 'a',
// 'b',
// ]);
// })->depends('it asserts query parameters can be parsed.');