v7.0.0-beta.4 release

This commit is contained in:
HeuJung committed 2026-05-11 11:29:41 +09:00
1 parent 05db17887d
commit 1db039ff34
1545 files changed
+136783 -11634

No files matched your search

@@ -0,0 +1,79 @@
<?php
namespace Tests\Unit\Console;
use App\Services\LanguagePackService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Mockery;
use Tests\TestCase;
/**
* language-pack:check-updates 콘솔 커맨드 회귀 테스트.
*
* 본 커맨드는 LanguagePackService::checkUpdates() 에 위임하므로 위임 동작과
* 출력 포맷이 회귀 없이 유지되는지 검증합니다.
*/
class CheckLanguagePackUpdatesCommandTest extends TestCase
{
use RefreshDatabase;
/**
* 테스트 정리.
*
* @return void
*/
protected function tearDown(): void
{
Mockery::close();
parent::tearDown();
}
public function test_outputs_no_packs_message_when_empty(): void
{
$service = Mockery::mock(LanguagePackService::class);
$service->shouldReceive('checkUpdates')
->once()
->with(null)
->andReturn(['checked' => 0, 'updates' => 0, 'details' => []]);
$this->app->instance(LanguagePackService::class, $service);
$this->artisan('language-pack:check-updates')
->expectsOutputToContain('GitHub 기반 언어팩이 없습니다')
->assertSuccessful();
}
public function test_renders_each_detail_line(): void
{
$service = Mockery::mock(LanguagePackService::class);
$service->shouldReceive('checkUpdates')
->once()
->with(null)
->andReturn([
'checked' => 2,
'updates' => 1,
'details' => [
['identifier' => 'foo-core-ja', 'current' => '1.0.0', 'latest' => '1.1.0', 'has_update' => true, 'error' => null],
['identifier' => 'foo-core-de', 'current' => '1.0.0', 'latest' => '1.0.0', 'has_update' => false, 'error' => null],
],
]);
$this->app->instance(LanguagePackService::class, $service);
$this->artisan('language-pack:check-updates')
->expectsOutputToContain('foo-core-ja')
->expectsOutputToContain('foo-core-de')
->assertSuccessful();
}
public function test_passes_identifier_option(): void
{
$service = Mockery::mock(LanguagePackService::class);
$service->shouldReceive('checkUpdates')
->once()
->with('foo-core-ja')
->andReturn(['checked' => 0, 'updates' => 0, 'details' => []]);
$this->app->instance(LanguagePackService::class, $service);
$this->artisan('language-pack:check-updates', ['--identifier' => 'foo-core-ja'])
->assertSuccessful();
}
}
@@ -20,6 +20,10 @@ class BroadcastDashboardResourcesTest extends TestCase
public function test_command_broadcasts_resources_update(): void
{
// HookManager::broadcast 는 null/log 드라이버 또는 host 미설정 시 dispatch 스킵
config(['broadcasting.default' => 'reverb']);
config(['broadcasting.connections.reverb.options.host' => 'localhost']);
Event::fake([GenericBroadcastEvent::class]);
$this->artisan('dashboard:broadcast-resources')
@@ -35,6 +39,10 @@ class BroadcastDashboardResourcesTest extends TestCase
public function test_command_sends_correct_resource_data(): void
{
// HookManager::broadcast 는 null/log 드라이버 또는 host 미설정 시 dispatch 스킵
config(['broadcasting.default' => 'reverb']);
config(['broadcasting.connections.reverb.options.host' => 'localhost']);
Event::fake([GenericBroadcastEvent::class]);
$this->artisan('dashboard:broadcast-resources')
@@ -5,13 +5,14 @@ namespace Tests\Unit\Console\Commands;
use App\Jobs\GenerateSitemapJob;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Config;
use Mockery;
use Tests\TestCase;
/**
* SeoGenerateSitemapCommand 유닛 테스트
*
* seo:generate-sitemap 커맨드의 큐 디스패치, 동기 실행, 출력 메시지를 검증합니다.
* seo:generate-sitemap 커맨드의 큐 드라이버 분기, 강제 동기, 출력 메시지를 검증합니다.
*/
class SeoGenerateSitemapCommandTest extends TestCase
{
@@ -22,52 +23,48 @@ class SeoGenerateSitemapCommandTest extends TestCase
}
/**
* --sync 없이 실행 시 잡이 큐에 디스패치되는지 확인합니다.
* 큐 드라이버가 sync 가 아닐 때 비동기 디스패치되는지 확인합니다.
*/
public function test_command_dispatches_job_to_queue(): void
public function test_command_dispatches_async_when_queue_driver_is_not_sync(): void
{
Config::set('queue.default', 'database');
Bus::fake([GenerateSitemapJob::class]);
$this->artisan('seo:generate-sitemap')
->expectsOutput('Sitemap 생성이 큐에 디스패치되었습니다.')
->assertExitCode(Command::SUCCESS);
Bus::assertDispatched(GenerateSitemapJob::class);
Bus::assertNotDispatchedSync(GenerateSitemapJob::class);
}
/**
* --sync 옵션으로 실행 시 잡이 동기적으로 디스패치되는지 확인합니다.
* 큐 드라이버가 sync 일 때 옵션 없이도 동기 실행되는지 확인합니다.
*/
public function test_command_dispatches_job_sync(): void
public function test_command_dispatches_sync_when_queue_driver_is_sync(): void
{
Config::set('queue.default', 'sync');
Bus::fake([GenerateSitemapJob::class]);
$this->artisan('seo:generate-sitemap', ['--sync' => true])
$this->artisan('seo:generate-sitemap')
->expectsOutput('Sitemap이 생성되었습니다.')
->assertExitCode(Command::SUCCESS);
Bus::assertDispatchedSync(GenerateSitemapJob::class);
}
/**
* 큐 디스패치 시 올바른 출력 메시지를 확인합니다.
* --sync 옵션은 큐 드라이버와 무관하게 동기 실행을 강제합니다.
*/
public function test_command_outputs_queue_dispatch_message(): void
{
Bus::fake([GenerateSitemapJob::class]);
$this->artisan('seo:generate-sitemap')
->expectsOutput('Sitemap 생성이 큐에 디스패치되었습니다.')
->assertExitCode(Command::SUCCESS);
}
/**
* 동기 실행 시 올바른 출력 메시지를 확인합니다.
*/
public function test_command_outputs_sync_success_message(): void
public function test_command_forces_sync_when_option_provided(): void
{
Config::set('queue.default', 'database');
Bus::fake([GenerateSitemapJob::class]);
$this->artisan('seo:generate-sitemap', ['--sync' => true])
->expectsOutput('Sitemap이 생성되었습니다.')
->assertExitCode(Command::SUCCESS);
Bus::assertDispatchedSync(GenerateSitemapJob::class);
}
}
@@ -0,0 +1,163 @@
<?php
namespace Tests\Unit\Console\Commands\Traits;
use App\Console\Commands\Traits\HasUnifiedConfirm;
use Illuminate\Console\Command;
use Symfony\Component\Console\Tester\CommandTester;
use Tests\TestCase;
/**
* HasUnifiedConfirm trait 단위 테스트.
*
* Symfony QuestionHelper 를 거치므로 CommandTester 의 setInputs() 로 STDIN 시뮬레이션,
* --no-interaction 시 default 즉시 반환을 검증한다.
*/
class HasUnifiedConfirmTest extends TestCase
{
public function test_returns_default_when_non_interactive_default_false(): void
{
$tester = $this->makeTester(false);
$tester->execute([], ['interactive' => false]);
$this->assertSame('false', trim($tester->getDisplay()));
}
public function test_returns_default_when_non_interactive_default_true(): void
{
$tester = $this->makeTester(true);
$tester->execute([], ['interactive' => false]);
$this->assertSame('true', trim($tester->getDisplay()));
}
public function test_resolves_immediately_on_yes_input(): void
{
$tester = $this->makeTester(false);
$tester->setInputs(['yes']);
$tester->execute([]);
$display = $tester->getDisplay();
$this->assertStringEndsWith('true', trim($display));
$this->assertStringNotContainsString('yes, y, no, n', $display);
}
public function test_resolves_immediately_on_no_input(): void
{
$tester = $this->makeTester(true);
$tester->setInputs(['no']);
$tester->execute([]);
$this->assertStringEndsWith('false', trim($tester->getDisplay()));
}
public function test_resolves_on_y_short_input(): void
{
$tester = $this->makeTester(false);
$tester->setInputs(['y']);
$tester->execute([]);
$this->assertStringEndsWith('true', trim($tester->getDisplay()));
}
public function test_returns_default_on_empty_input(): void
{
$tester = $this->makeTester(true);
$tester->setInputs(['']);
$tester->execute([]);
$this->assertStringEndsWith('true', trim($tester->getDisplay()));
}
public function test_loops_on_invalid_input_then_resolves(): void
{
$tester = $this->makeTester(false);
$tester->setInputs(['abc', 'y']);
$tester->execute([]);
$display = $tester->getDisplay();
$this->assertStringContainsString('yes, y, no, n 중 하나로 입력해 주세요.', $display);
$this->assertStringEndsWith('true', trim($display));
}
public function test_loops_multiple_times_on_invalid_input(): void
{
$tester = $this->makeTester(true);
$tester->setInputs(['abc', 'foo', 'no']);
$tester->execute([]);
$display = $tester->getDisplay();
$this->assertSame(2, substr_count($display, 'yes, y, no, n 중 하나로 입력해 주세요.'));
$this->assertStringEndsWith('false', trim($display));
}
/**
* Symfony QuestionHelper 가 default 값을 자동 표시하는 `[default]` 가
* 우리가 직접 그린 `[yes]` / `[no]` 옆에 빈 `[]` 로 중복 출력되지 않아야 한다.
*
* 회귀 시나리오 (이전): `진행할까요? (yes/no) [no] []:`
* 정상: `진행할까요? (yes/no) [no]:`
*/
public function test_prompt_does_not_show_duplicate_empty_default_brackets(): void
{
$tester = $this->makeTester(false);
$tester->setInputs(['no']);
$tester->execute([]);
$display = $tester->getDisplay();
// `[no] []` 또는 `[yes] []` 같은 중복 default 표시가 없어야 함
$this->assertStringNotContainsString('[no] []', $display);
$this->assertStringNotContainsString('[yes] []', $display);
$this->assertStringNotContainsString('[]', $display);
// 정상 prompt 형식 확인
$this->assertStringContainsString('진행할까요? (yes/no) [no]:', $display);
}
public function test_prompt_does_not_show_duplicate_brackets_when_default_yes(): void
{
$tester = $this->makeTester(true);
$tester->setInputs(['yes']);
$tester->execute([]);
$display = $tester->getDisplay();
$this->assertStringNotContainsString('[]', $display);
$this->assertStringContainsString('진행할까요? (yes/no) [yes]:', $display);
}
private function makeTester(bool $default): CommandTester
{
$command = new class($default) extends Command
{
use HasUnifiedConfirm;
protected $signature = 'test:unified-confirm';
public function __construct(private bool $defaultValue)
{
parent::__construct();
}
public function handle(): int
{
$result = $this->unifiedConfirm('진행할까요?', $this->defaultValue);
$this->line($result ? 'true' : 'false');
return self::SUCCESS;
}
};
$command->setLaravel($this->app);
return new CommandTester($command);
}
}
@@ -0,0 +1,173 @@
<?php
namespace Tests\Unit\Console\Helpers;
use App\Console\Helpers\ConsoleConfirm;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase;
/**
* ConsoleConfirm 헬퍼 단위 테스트.
*
* - parse(): 입력 정규화 규칙 (대소문자/공백/empty/유효값/무효값)
* - ask(): STDIN 루프 동작 (1회 결정/재질문/EOF/non-tty)
*/
class ConsoleConfirmTest extends TestCase
{
/**
* @return array<string, array{string, bool, bool|null}>
*/
public static function parseCases(): array
{
return [
'empty + default true' => ['', true, true],
'empty + default false' => ['', false, false],
'yes lowercase' => ['yes', false, true],
'y short' => ['y', false, true],
'Y uppercase' => ['Y', false, true],
'YES uppercase' => ['YES', false, true],
'yes with surrounding whitespace' => [' yes ', false, true],
'yes with newline (fgets style)' => ["\nyes\n", false, true],
'no lowercase' => ['no', true, false],
'n short' => ['n', true, false],
'N uppercase + default true' => ['N', true, false],
'NO uppercase' => ['NO', true, false],
'invalid - yell_no (default false)' => ['yell_no', false, null],
'invalid - nope (default true)' => ['nope', true, null],
'invalid - yeah (y로 시작이지만 무관)' => ['yeah', false, null],
'invalid - 1 (numeric truthy)' => ['1', false, null],
'invalid - 0 (numeric falsy)' => ['0', false, null],
'invalid - true literal' => ['true', false, null],
'invalid - false literal' => ['false', false, null],
'invalid - 한글 예 (비ASCII)' => ['예', false, null],
'invalid - 한글 네 (비ASCII)' => ['네', false, null],
'whitespace-only → empty → default' => [" \t \n", true, true],
];
}
#[DataProvider('parseCases')]
public function test_parse_normalizes_input(string $raw, bool $default, ?bool $expected): void
{
$this->assertSame($expected, ConsoleConfirm::parse($raw, $default));
}
public function test_ask_returns_immediately_on_first_valid_input(): void
{
$stdin = $this->makeStdin(["yes\n"]);
$output = '';
$result = ConsoleConfirm::ask(
'진행할까요?',
false,
$stdin,
function (string $text) use (&$output) {
$output .= $text;
},
);
$this->assertTrue($result);
$this->assertStringContainsString('진행할까요? (yes/no) [no]: ', $output);
$this->assertStringNotContainsString('yes, y, no, n', $output);
}
public function test_ask_loops_on_invalid_input_then_resolves(): void
{
$stdin = $this->makeStdin(["abc\n", "y\n"]);
$output = '';
$result = ConsoleConfirm::ask(
'진행할까요?',
false,
$stdin,
function (string $text) use (&$output) {
$output .= $text;
},
);
$this->assertTrue($result);
$this->assertStringContainsString('yes, y, no, n 중 하나로 입력해 주세요.', $output);
// 질문이 정확히 2회 출력되어야 함
$this->assertSame(2, substr_count($output, '진행할까요? (yes/no) [no]: '));
}
public function test_ask_loops_multiple_times_on_invalid_input(): void
{
$stdin = $this->makeStdin(["a\n", "b\n", "no\n"]);
$output = '';
$result = ConsoleConfirm::ask(
'진행할까요?',
true,
$stdin,
function (string $text) use (&$output) {
$output .= $text;
},
);
$this->assertFalse($result);
$this->assertSame(2, substr_count($output, 'yes, y, no, n 중 하나로 입력해 주세요.'));
$this->assertSame(3, substr_count($output, '진행할까요? (yes/no) [yes]: '));
}
public function test_ask_returns_default_on_eof(): void
{
$stdin = $this->makeStdin([]);
$resultDefaultTrue = ConsoleConfirm::ask('Q?', true, $stdin, fn () => null);
$this->assertTrue($resultDefaultTrue);
$stdin2 = $this->makeStdin([]);
$resultDefaultFalse = ConsoleConfirm::ask('Q?', false, $stdin2, fn () => null);
$this->assertFalse($resultDefaultFalse);
}
public function test_ask_returns_default_on_empty_input(): void
{
$stdin = $this->makeStdin(["\n"]);
$result = ConsoleConfirm::ask('Q?', true, $stdin, fn () => null);
$this->assertTrue($result);
}
public function test_ask_uses_yes_hint_when_default_true(): void
{
$stdin = $this->makeStdin(["yes\n"]);
$output = '';
ConsoleConfirm::ask('Q?', true, $stdin, function (string $text) use (&$output) {
$output .= $text;
});
$this->assertStringContainsString('Q? (yes/no) [yes]: ', $output);
}
public function test_ask_uses_no_hint_when_default_false(): void
{
$stdin = $this->makeStdin(["no\n"]);
$output = '';
ConsoleConfirm::ask('Q?', false, $stdin, function (string $text) use (&$output) {
$output .= $text;
});
$this->assertStringContainsString('Q? (yes/no) [no]: ', $output);
}
/**
* 메모리 기반 STDIN 리소스 생성.
*
* @param array<string> $lines fgets() 가 차례로 반환할 줄 (개행 포함 권장)
* @return resource
*/
private function makeStdin(array $lines)
{
$stream = fopen('php://memory', 'r+');
foreach ($lines as $line) {
fwrite($stream, $line);
}
rewind($stream);
return $stream;
}
}