v7.0.0-beta.2 release

This commit is contained in:
HeuJung committed 2026-04-20 20:37:49 +09:00
1 parent 6595fd0eb5
commit fa8eba7a0d
1165 files changed
+107118 -762127

No files matched your search

@@ -0,0 +1,151 @@
<?php
namespace Tests\Unit\Providers;
use App\Extension\HookManager;
use App\Repositories\JsonConfigRepository;
use App\Services\DriverRegistryService;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
/**
* CoreServiceProvider의 확장 드라이버 Config 적용 로직 테스트
*
* applyExtensionDriverConfigs()의 핵심 흐름을 검증합니다:
* - 코어 드라이버 선택 시 스킵
* - 플러그인 드라이버 사용 가능 시 액션 훅 발행
* - 플러그인 드라이버 사용 불가 시 기본 드라이버 폴백 + 로그 경고
*/
class CoreServiceProviderDriverHookTest extends TestCase
{
private DriverRegistryService $driverRegistry;
protected function setUp(): void
{
parent::setUp();
$this->driverRegistry = new DriverRegistryService();
}
protected function tearDown(): void
{
HookManager::resetAll();
parent::tearDown();
}
/**
* 코어 드라이버가 선택된 경우 액션 훅이 발행되지 않는지 검증합니다.
*/
#[Test]
public function it_skips_core_drivers(): void
{
$hookFired = false;
HookManager::addAction('core.settings.apply_driver_config', function () use (&$hookFired) {
$hookFired = true;
});
// smtp는 코어 드라이버 → 훅 발행되면 안 됨
$this->assertTrue($this->driverRegistry->isCoreDriver('mail', 'smtp'));
$this->assertFalse($hookFired);
}
/**
* 플러그인 드라이버가 등록되고 사용 가능할 때 액션 훅이 발행되는지 검증합니다.
*/
#[Test]
public function it_fires_action_hook_for_available_plugin_driver(): void
{
// 플러그인 드라이버 등록
HookManager::addFilter('core.settings.available_mail_drivers', function (array $drivers) {
$drivers[] = [
'id' => 'custom_api',
'label' => ['ko' => '커스텀 API', 'en' => 'Custom API'],
'provider' => 'sirsoft-custom_mail',
];
return $drivers;
});
// custom_api가 사용 가능한지 확인
$this->assertTrue($this->driverRegistry->isDriverAvailable('mail', 'custom_api'));
// 액션 훅 발행 검증
$hookParams = null;
HookManager::addAction('core.settings.apply_driver_config', function (string $category, string $driver, array $settings) use (&$hookParams) {
$hookParams = compact('category', 'driver', 'settings');
});
// 액션 훅 직접 발행 (CoreServiceProvider가 하는 것과 동일)
HookManager::doAction('core.settings.apply_driver_config', 'mail', 'custom_api', ['mailer' => 'custom_api']);
$this->assertNotNull($hookParams);
$this->assertEquals('mail', $hookParams['category']);
$this->assertEquals('custom_api', $hookParams['driver']);
}
/**
* 플러그인 드라이버가 등록되지 않은 경우(사용 불가) 기본 드라이버로 폴백하는지 검증합니다.
*/
#[Test]
public function it_falls_back_to_default_when_plugin_driver_unavailable(): void
{
// 'custom_api'는 어디에도 등록되지 않은 드라이버
$this->assertFalse($this->driverRegistry->isDriverAvailable('mail', 'custom_api'));
// 폴백 시 Config::set이 호출되어야 함
$defaultDriver = $this->driverRegistry->getDefaultDriver('mail');
$configKey = $this->driverRegistry->getConfigKey('mail');
$this->assertEquals('smtp', $defaultDriver);
$this->assertEquals('mail.default', $configKey);
// 폴백 적용 시뮬레이션
Config::set($configKey, $defaultDriver);
$this->assertEquals('smtp', Config::get('mail.default'));
}
/**
* 폴백 시 경고 로그가 기록되는지 검증합니다.
*/
#[Test]
public function it_logs_warning_on_fallback(): void
{
Log::shouldReceive('warning')
->once()
->withArgs(function (string $message) {
return str_contains($message, 'custom_api')
&& str_contains($message, 'mail')
&& str_contains($message, '폴백');
});
// 사용 불가능한 드라이버에 대해 폴백 로직 시뮬레이션
$selectedDriver = 'custom_api';
$category = 'mail';
if (! $this->driverRegistry->isDriverAvailable($category, $selectedDriver)) {
$defaultDriver = $this->driverRegistry->getDefaultDriver($category);
$configKey = $this->driverRegistry->getConfigKey($category);
if ($configKey && $defaultDriver) {
Config::set($configKey, $defaultDriver);
}
Log::warning("플러그인 드라이버 '{$selectedDriver}'가 '{$category}' 카테고리에서 사용 불가능합니다. 기본 드라이버 '{$defaultDriver}'로 폴백합니다.");
}
}
/**
* 카테고리별 Config 키 매핑이 올바른지 검증합니다.
*/
#[Test]
public function it_maps_categories_to_correct_config_keys(): void
{
$this->assertEquals('filesystems.default', $this->driverRegistry->getConfigKey('storage'));
$this->assertEquals('cache.default', $this->driverRegistry->getConfigKey('cache'));
$this->assertEquals('session.driver', $this->driverRegistry->getConfigKey('session'));
$this->assertEquals('queue.default', $this->driverRegistry->getConfigKey('queue'));
$this->assertEquals('mail.default', $this->driverRegistry->getConfigKey('mail'));
}
}
@@ -0,0 +1,93 @@
<?php
namespace Tests\Unit\Providers;
use App\Providers\SettingsServiceProvider;
use Illuminate\Support\Facades\Config;
use ReflectionMethod;
use Tests\TestCase;
/**
* SettingsServiceProvider 웹소켓 설정 테스트
*
* applyWebsocketConfig()가 drivers.json의 websocket_enabled 값에 따라
* 브로드캐스트 드라이버를 올바르게 제어하는지 검증합니다.
*
* 재현 시나리오 (이슈: 비밀번호 변경 시 Reverb 발송 시도):
* - drivers.json: websocket_enabled=false (환경설정에서 OFF)
* - .env: BROADCAST_CONNECTION=reverb, REVERB_HOST=localhost
* - 기대 동작: broadcasting.default가 'null'로 강제되어 broadcast 경로가 차단되어야 함
*/
class SettingsServiceProviderWebsocketConfigTest extends TestCase
{
/**
* applyWebsocketConfig를 리플렉션으로 호출합니다.
*
* @param array $driverSettings drivers 카테고리 설정 데이터
*/
private function callApplyWebsocketConfig(array $driverSettings): void
{
$provider = new SettingsServiceProvider($this->app);
$method = new ReflectionMethod($provider, 'applyWebsocketConfig');
$method->invoke($provider, $driverSettings);
}
/**
* 웹소켓 비활성화 시 broadcasting.default가 'null'로 강제되는지 테스트합니다.
*/
public function test_broadcasting_default_forced_to_null_when_websocket_disabled(): void
{
// .env 초기 상태: BROADCAST_CONNECTION=reverb
Config::set('broadcasting.default', 'reverb');
Config::set('broadcasting.connections.reverb.options.host', 'localhost');
// PO 설정: 웹소켓 OFF
$this->callApplyWebsocketConfig([
'websocket_enabled' => false,
'websocket_host' => 'g7.dev',
'websocket_port' => '443',
'websocket_scheme' => 'https',
]);
$this->assertSame(
'null',
config('broadcasting.default'),
'웹소켓 비활성화 시 broadcasting.default는 "null"로 강제되어야 함 (HookManager::broadcast가 즉시 return)'
);
}
/**
* 웹소켓 활성화 시 broadcasting.default가 유지되는지 테스트합니다.
*/
public function test_broadcasting_default_preserved_when_websocket_enabled(): void
{
Config::set('broadcasting.default', 'reverb');
$this->callApplyWebsocketConfig([
'websocket_enabled' => true,
'websocket_app_id' => 'test-app',
'websocket_app_key' => 'test-key',
'websocket_app_secret' => 'test-secret',
'websocket_host' => 'g7.dev',
'websocket_port' => '443',
'websocket_scheme' => 'https',
'websocket_server_host' => '127.0.0.1',
'websocket_server_port' => 8080,
'websocket_server_scheme' => 'http',
]);
$this->assertSame('reverb', config('broadcasting.default'));
}
/**
* websocket_enabled 키 미존재 시 broadcasting.default가 'null'로 강제되는지 테스트합니다.
*/
public function test_broadcasting_default_forced_to_null_when_websocket_key_missing(): void
{
Config::set('broadcasting.default', 'reverb');
$this->callApplyWebsocketConfig([]);
$this->assertSame('null', config('broadcasting.default'));
}
}