Files
Gnuboard7/plugins/_bundled/sirsoft-message_bizppurio/tests/PluginTestCase.php
T
chym1217 6549170bda feat(message_bizppurio): 비즈뿌리오 발송 엔진 API 클라이언트
발송 시스템(api.bizppurio.com)과 카카오 관리 시스템(kapi.ppurio.com)의
API 클라이언트를 인증 방식(토큰 vs bizId+apiKey)에 따라 분리 구현했다.
토큰 캐시(23h)·재발급, SMS/LMS EUC-KR byte 자동 판별, ShouldQueue 발송
Job(429·일시오류 재시도, 영구실패 즉시)을 포함한다. 실제 발송 없이
Http::fake 단위테스트 30건으로 검증했다.
2026-07-28 12:36:18 +09:00

101 lines
2.9 KiB
PHP

<?php
namespace Plugins\Sirsoft\MessageBizppurio\Tests;
use App\Extension\HookManager;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
/**
* 비즈뿌리오 메시징 플러그인 테스트 베이스 클래스
*
* 모든 플러그인 테스트는 이 클래스를 상속받아야 합니다.
* 코어 + 번들 확장 마이그레이션을 자동으로 처리합니다.
*/
abstract class PluginTestCase extends TestCase
{
use RefreshDatabase;
/**
* HookManager static state 스냅샷 — tearDown 에서 복원하여 테스트 간 훅 격리 보장.
*
* @var array{hooks: array, filters: array, dispatching: array}|null
*/
private ?array $hookSnapshot = null;
/**
* 테스트 환경 설정
*/
protected function setUp(): void
{
parent::setUp();
$this->snapshotHookManager();
}
/**
* tearDown 에 HookManager 상태 복원.
*/
protected function tearDown(): void
{
$this->restoreHookManager();
parent::tearDown();
}
/**
* HookManager static $hooks / $filters / $dispatching 를 스냅샷.
*/
private function snapshotHookManager(): void
{
$ref = new \ReflectionClass(HookManager::class);
$this->hookSnapshot = [
'hooks' => $ref->getProperty('hooks')->getValue(),
'filters' => $ref->getProperty('filters')->getValue(),
'dispatching' => $ref->getProperty('dispatching')->getValue(),
];
}
/**
* 스냅샷 시점으로 HookManager 복원.
*/
private function restoreHookManager(): void
{
if ($this->hookSnapshot === null) {
return;
}
$ref = new \ReflectionClass(HookManager::class);
$ref->getProperty('hooks')->setValue(null, $this->hookSnapshot['hooks']);
$ref->getProperty('filters')->setValue(null, $this->hookSnapshot['filters']);
$ref->getProperty('dispatching')->setValue(null, $this->hookSnapshot['dispatching']);
$this->hookSnapshot = null;
}
/**
* 마이그레이션 경로를 반환합니다.
*
* RefreshDatabase 의 migrate:fresh 명령에 코어 + 번들 확장 마이그레이션 경로를 전달합니다.
*
* @return array<string, mixed>
*/
protected function migrateFreshUsing(): array
{
$paths = ['database/migrations'];
foreach (glob(base_path('modules/_bundled/*/database/migrations'), GLOB_ONLYDIR) as $p) {
$paths[] = str_replace(base_path().DIRECTORY_SEPARATOR, '', $p);
}
foreach (glob(base_path('plugins/_bundled/*/database/migrations'), GLOB_ONLYDIR) as $p) {
$paths[] = str_replace(base_path().DIRECTORY_SEPARATOR, '', $p);
}
return [
'--drop-views' => $this->shouldDropViews(),
'--drop-types' => $this->shouldDropTypes(),
'--seed' => false,
'--path' => $paths,
];
}
}