v7.0.0-beta.2 release
This commit is contained in:
1 parent
6595fd0eb5
commit
fa8eba7a0d
1165 files changed
+107118
-762127
No files matched your search
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Console;
|
||||
|
||||
use App\Console\Commands\Core\Concerns\BundledExtensionUpdatePrompt;
|
||||
use App\Extension\ModuleManager;
|
||||
use App\Extension\PluginManager;
|
||||
use App\Extension\TemplateManager;
|
||||
use App\Services\CoreUpdateService;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* BundledExtensionUpdatePrompt trait 단위 테스트.
|
||||
*
|
||||
* collectBundledUpdates() 가 CoreUpdateService::collectBundledExtensionUpdates() 를
|
||||
* 통해 _bundled 버전 직접 비교 결과를 반환하는지 검증.
|
||||
*/
|
||||
class BundledExtensionUpdatePromptTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* collectBundledUpdates 는 CoreUpdateService 의 결과를 그대로 반환한다.
|
||||
*/
|
||||
public function test_collect_bundled_updates_delegates_to_service(): void
|
||||
{
|
||||
$expected = [
|
||||
'modules' => [
|
||||
['identifier' => 'sirsoft-ecommerce', 'current_version' => '1.0.0', 'latest_version' => '1.1.0', 'update_source' => 'bundled'],
|
||||
],
|
||||
'plugins' => [
|
||||
['identifier' => 'sirsoft-payment', 'current_version' => '1.0.0', 'latest_version' => '1.0.1', 'update_source' => 'bundled'],
|
||||
],
|
||||
'templates' => [],
|
||||
];
|
||||
|
||||
$serviceMock = Mockery::mock(CoreUpdateService::class);
|
||||
$serviceMock->shouldReceive('collectBundledExtensionUpdates')
|
||||
->once()
|
||||
->andReturn($expected);
|
||||
$this->app->instance(CoreUpdateService::class, $serviceMock);
|
||||
|
||||
$harness = $this->makeTraitHarness();
|
||||
$result = $harness->callCollect(
|
||||
Mockery::mock(ModuleManager::class),
|
||||
Mockery::mock(PluginManager::class),
|
||||
Mockery::mock(TemplateManager::class),
|
||||
);
|
||||
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Service 가 빈 결과를 반환하면 trait 도 빈 결과를 반환한다.
|
||||
*/
|
||||
public function test_collect_bundled_updates_returns_empty_when_service_returns_empty(): void
|
||||
{
|
||||
$serviceMock = Mockery::mock(CoreUpdateService::class);
|
||||
$serviceMock->shouldReceive('collectBundledExtensionUpdates')
|
||||
->once()
|
||||
->andReturn(['modules' => [], 'plugins' => [], 'templates' => []]);
|
||||
$this->app->instance(CoreUpdateService::class, $serviceMock);
|
||||
|
||||
$harness = $this->makeTraitHarness();
|
||||
$result = $harness->callCollect(
|
||||
Mockery::mock(ModuleManager::class),
|
||||
Mockery::mock(PluginManager::class),
|
||||
Mockery::mock(TemplateManager::class),
|
||||
);
|
||||
|
||||
$this->assertEmpty($result['modules']);
|
||||
$this->assertEmpty($result['plugins']);
|
||||
$this->assertEmpty($result['templates']);
|
||||
}
|
||||
|
||||
/**
|
||||
* trait 을 사용하는 anonymous 테스트 harness.
|
||||
*/
|
||||
private function makeTraitHarness(): object
|
||||
{
|
||||
return new class
|
||||
{
|
||||
use BundledExtensionUpdatePrompt;
|
||||
|
||||
public function callCollect(ModuleManager $m, PluginManager $p, TemplateManager $t): array
|
||||
{
|
||||
return $this->collectBundledUpdates($m, $p, $t);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
namespace Tests\Unit\Console\Commands;
|
||||
|
||||
use App\Events\Dashboard\DashboardUpdated;
|
||||
use App\Services\DashboardService;
|
||||
use App\Events\GenericBroadcastEvent;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
@@ -21,43 +20,39 @@ class BroadcastDashboardResourcesTest extends TestCase
|
||||
|
||||
public function test_command_broadcasts_resources_update(): void
|
||||
{
|
||||
Event::fake([DashboardUpdated::class]);
|
||||
Event::fake([GenericBroadcastEvent::class]);
|
||||
|
||||
// 커맨드 실행
|
||||
$this->artisan('dashboard:broadcast-resources')
|
||||
->expectsOutput('시스템 리소스 정보가 브로드캐스트되었습니다.')
|
||||
->assertExitCode(0);
|
||||
|
||||
// 이벤트 디스패치 확인
|
||||
Event::assertDispatched(DashboardUpdated::class, function ($event) {
|
||||
return $event->type === 'resources';
|
||||
Event::assertDispatched(GenericBroadcastEvent::class, function ($event) {
|
||||
return $event->channel === 'core.admin.dashboard'
|
||||
&& $event->eventName === 'dashboard.resources.updated'
|
||||
&& $event->payload['type'] === 'resources';
|
||||
});
|
||||
}
|
||||
|
||||
public function test_command_sends_correct_resource_data(): void
|
||||
{
|
||||
Event::fake([DashboardUpdated::class]);
|
||||
Event::fake([GenericBroadcastEvent::class]);
|
||||
|
||||
// 커맨드 실행
|
||||
$this->artisan('dashboard:broadcast-resources')
|
||||
->assertExitCode(0);
|
||||
|
||||
// 이벤트에 올바른 데이터가 포함되어 있는지 확인
|
||||
Event::assertDispatched(DashboardUpdated::class, function ($event) {
|
||||
// resources 타입인지 확인
|
||||
if ($event->type !== 'resources') {
|
||||
Event::assertDispatched(GenericBroadcastEvent::class, function ($event) {
|
||||
if ($event->payload['type'] !== 'resources') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// data가 배열인지 확인
|
||||
if (! is_array($event->data)) {
|
||||
$data = $event->payload['data'] ?? null;
|
||||
if (! is_array($data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 필수 필드가 있는지 확인
|
||||
return isset($event->data['cpu']) &&
|
||||
isset($event->data['memory']) &&
|
||||
isset($event->data['disk']);
|
||||
return isset($data['cpu'])
|
||||
&& isset($data['memory'])
|
||||
&& isset($data['disk']);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user