Files
Gnuboard7/plugins/_bundled/sirsoft-pay_kginicis/tests/Feature/Concerns/SerializesPaymentCallbacksTest.php
T
thisgunandCodex 8429d8ada5 fix(payment): KG 이니시스 결제 콜백 안정성 보강
KG 이니시스 결제에서 통화 스냅샷 이상 시 서버 오류로 새지 않도록 검증 실패/재통보 가능한 응답으로 처리하고, 주문 단위 콜백 락으로 동시 완료 콜백의 중복 후속 처리를 줄입니다.

백엔드 테스트의 통화 스냅샷 fixture도 최신 계약에 맞춰 복구합니다.

Co-Authored-By: Codex <codex@openai.com>
2026-07-06 13:46:35 +09:00

75 lines
2.4 KiB
PHP

<?php
namespace Plugins\Sirsoft\PayKginicis\Tests\Feature\Concerns;
use Illuminate\Contracts\Cache\LockTimeoutException;
use Plugins\Sirsoft\PayKginicis\Concerns\SerializesPaymentCallbacks;
use Plugins\Sirsoft\PayKginicis\Tests\PluginTestCase;
class SerializesPaymentCallbacksTest extends PluginTestCase
{
private object $traitSubject;
protected function setUp(): void
{
parent::setUp();
$this->traitSubject = new class {
use SerializesPaymentCallbacks {
acquireOrderCallbackLock as public;
releaseOrderCallbackLock as public;
callbackLockKey as public;
}
protected function callbackLockWaitSeconds(): int
{
return 0;
}
protected function callbackLockTtlSeconds(): int
{
return 5;
}
};
}
public function test_same_context_and_order_are_serialized(): void
{
$orderNumber = 'ORD-KG-LOCK-' . random_int(10000, 99999);
$firstLock = $this->traitSubject->acquireOrderCallbackLock('authCallback', $orderNumber);
try {
$this->expectException(LockTimeoutException::class);
$this->traitSubject->acquireOrderCallbackLock('authCallback', $orderNumber);
} finally {
$this->traitSubject->releaseOrderCallbackLock($firstLock);
}
}
public function test_released_lock_allows_next_callback(): void
{
$orderNumber = 'ORD-KG-LOCK-' . random_int(10000, 99999);
$firstLock = $this->traitSubject->acquireOrderCallbackLock('authCallback', $orderNumber);
$this->traitSubject->releaseOrderCallbackLock($firstLock);
$secondLock = $this->traitSubject->acquireOrderCallbackLock('authCallback', $orderNumber);
$this->assertNotNull($secondLock);
$this->traitSubject->releaseOrderCallbackLock($secondLock);
}
public function test_lock_key_is_scoped_by_context_and_order(): void
{
$this->assertNotSame(
$this->traitSubject->callbackLockKey('authCallback', 'ORD-KG-LOCK-A'),
$this->traitSubject->callbackLockKey('vbankNotify', 'ORD-KG-LOCK-A'),
);
$this->assertNotSame(
$this->traitSubject->callbackLockKey('authCallback', 'ORD-KG-LOCK-A'),
$this->traitSubject->callbackLockKey('authCallback', 'ORD-KG-LOCK-B'),
);
}
}