ver. 0.269: ShopPaymentMethod refactor + Apilo keepalive

This commit is contained in:
2026-02-14 15:22:02 +01:00
parent 5e5d3d068a
commit 818cd7f2c0
31 changed files with 1832 additions and 269 deletions

View File

@@ -152,19 +152,83 @@ class IntegrationsRepositoryTest extends TestCase
$this->assertNull($this->repository->apiloGetAccessToken());
}
public function testShouldRefreshAccessTokenReturnsFalseForFarFutureDate(): void
{
$reflection = new \ReflectionClass($this->repository);
$method = $reflection->getMethod('shouldRefreshAccessToken');
$method->setAccessible(true);
$future = date('Y-m-d H:i:s', time() + 3600);
$result = $method->invoke($this->repository, $future, 300);
$this->assertFalse($result);
}
public function testShouldRefreshAccessTokenReturnsTrueForNearExpiryDate(): void
{
$reflection = new \ReflectionClass($this->repository);
$method = $reflection->getMethod('shouldRefreshAccessToken');
$method->setAccessible(true);
$near = date('Y-m-d H:i:s', time() + 120);
$result = $method->invoke($this->repository, $near, 300);
$this->assertTrue($result);
}
public function testApiloFetchListThrowsForInvalidType(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->repository->apiloFetchList('invalid');
}
public function testApiloFetchListResultReturnsDetailedErrorWhenConfigMissing(): void
{
$stmt = $this->createMock(\PDOStatement::class);
$stmt->expects($this->once())
->method('fetchAll')
->with(\PDO::FETCH_ASSOC)
->willReturn([]);
$this->mockDb->expects($this->once())
->method('query')
->with('SELECT * FROM pp_shop_apilo_settings')
->willReturn($stmt);
$result = $this->repository->apiloFetchListResult('payment');
$this->assertIsArray($result);
$this->assertFalse((bool)($result['success'] ?? true));
$this->assertStringContainsString('Brakuje konfiguracji Apilo', (string)($result['message'] ?? ''));
}
public function testApiloIntegrationStatusReturnsMissingConfigMessage(): void
{
$stmt = $this->createMock(\PDOStatement::class);
$stmt->expects($this->once())
->method('fetchAll')
->with(\PDO::FETCH_ASSOC)
->willReturn([]);
$this->mockDb->expects($this->once())
->method('query')
->with('SELECT * FROM pp_shop_apilo_settings')
->willReturn($stmt);
$status = $this->repository->apiloIntegrationStatus();
$this->assertIsArray($status);
$this->assertFalse((bool)($status['is_valid'] ?? true));
$this->assertStringContainsString('Brakuje konfiguracji Apilo', (string)($status['message'] ?? ''));
}
public function testAllPublicMethodsExist(): void
{
$expectedMethods = [
'getSettings', 'getSetting', 'saveSetting',
'linkProduct', 'unlinkProduct',
'apiloAuthorize', 'apiloGetAccessToken',
'apiloFetchList', 'apiloProductSearch', 'apiloCreateProduct',
'apiloAuthorize', 'apiloGetAccessToken', 'apiloKeepalive', 'apiloIntegrationStatus',
'apiloFetchList', 'apiloFetchListResult', 'apiloProductSearch', 'apiloCreateProduct',
'getProductSku', 'shopproImportProduct',
];
@@ -201,4 +265,37 @@ class IntegrationsRepositoryTest extends TestCase
$settings = $this->repository->getSettings('shoppro');
$this->assertSame('test.com', $settings['domain']);
}
public function testNormalizeApiloMapListRejectsErrorPayload(): void
{
$reflection = new \ReflectionClass($this->repository);
$method = $reflection->getMethod('normalizeApiloMapList');
$method->setAccessible(true);
$result = $method->invoke($this->repository, [
'message' => 'Missing JWT token',
'code' => 401,
]);
$this->assertNull($result);
}
public function testNormalizeApiloMapListAcceptsIdNameList(): void
{
$reflection = new \ReflectionClass($this->repository);
$method = $reflection->getMethod('normalizeApiloMapList');
$method->setAccessible(true);
$payload = [
['id' => '1', 'name' => 'Przelew'],
['id' => '2', 'name' => 'Karta'],
];
$result = $method->invoke($this->repository, $payload);
$this->assertIsArray($result);
$this->assertCount(2, $result);
$this->assertSame('1', (string)$result[0]['id']);
$this->assertSame('Przelew', (string)$result[0]['name']);
}
}