54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
require_once dirname(__DIR__, 2) . '/modules/servers/hexagamecloud/lib/Idempotency.php';
|
|
|
|
final class IdempotencyTest extends TestCase
|
|
{
|
|
public function testServiceOperationKeyUsesReferenceWhenProvided(): void
|
|
{
|
|
$key = HexaGameCloudIdempotency::serviceOperationKey('renew', '12345', 'invoice-99');
|
|
|
|
$this->assertSame('service:renew:12345:invoice-99', $key);
|
|
}
|
|
|
|
public function testServiceOperationKeyFallsBackToDateSuffix(): void
|
|
{
|
|
$key = HexaGameCloudIdempotency::serviceOperationKey('suspend', '42', null);
|
|
|
|
$this->assertStringStartsWith('service:suspend:42:', $key);
|
|
$this->assertMatchesRegularExpression('/^service:suspend:42:\d{4}-\d{2}-\d{2}$/', $key);
|
|
}
|
|
|
|
public function testRenewKeyPrefersInvoiceId(): void
|
|
{
|
|
$key = HexaGameCloudIdempotency::renewKey('9001', [
|
|
'invoiceid' => '7788',
|
|
'renewalid' => '5555',
|
|
]);
|
|
|
|
$this->assertSame('service:renew:9001:7788', $key);
|
|
}
|
|
|
|
public function testRenewKeyUsesRenewalIdWhenInvoiceMissing(): void
|
|
{
|
|
$key = HexaGameCloudIdempotency::renewKey('9001', [
|
|
'renewalid' => '5555',
|
|
]);
|
|
|
|
$this->assertSame('service:renew:9001:5555', $key);
|
|
}
|
|
|
|
public function testRenewKeyUsesModelInvoiceId(): void
|
|
{
|
|
$key = HexaGameCloudIdempotency::renewKey('9001', [
|
|
'model' => ['invoiceid' => '6611'],
|
|
]);
|
|
|
|
$this->assertSame('service:renew:9001:6611', $key);
|
|
}
|
|
}
|