|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | + |
| 10 | +namespace OCA\TwoFactorGateway\Tests\Unit\Service; |
| 11 | + |
| 12 | +use OCA\TwoFactorGateway\Provider\Gateway\IGateway; |
| 13 | +use OCA\TwoFactorGateway\Service\GatewayDirectIntegrationService; |
| 14 | +use OCA\TwoFactorGateway\Service\GatewayRuntimeAvailabilityService; |
| 15 | +use PHPUnit\Framework\MockObject\MockObject; |
| 16 | +use PHPUnit\Framework\TestCase; |
| 17 | + |
| 18 | +class GatewayDirectIntegrationServiceTest extends TestCase { |
| 19 | + private GatewayRuntimeAvailabilityService&MockObject $gatewayRuntimeAvailabilityService; |
| 20 | + private GatewayDirectIntegrationService $service; |
| 21 | + |
| 22 | + protected function setUp(): void { |
| 23 | + parent::setUp(); |
| 24 | + $this->gatewayRuntimeAvailabilityService = $this->createMock(GatewayRuntimeAvailabilityService::class); |
| 25 | + $this->service = new GatewayDirectIntegrationService($this->gatewayRuntimeAvailabilityService); |
| 26 | + } |
| 27 | + |
| 28 | + public function testEnsureAvailableDelegatesToRuntimeAvailabilityService(): void { |
| 29 | + $gateway = $this->createMock(IGateway::class); |
| 30 | + |
| 31 | + $this->gatewayRuntimeAvailabilityService->expects($this->once()) |
| 32 | + ->method('getGateway') |
| 33 | + ->with('sms') |
| 34 | + ->willReturn($gateway); |
| 35 | + |
| 36 | + $this->service->ensureAvailable('sms'); |
| 37 | + } |
| 38 | + |
| 39 | + public function testIsGatewayCompleteDelegatesToRuntimeAvailabilityService(): void { |
| 40 | + $this->gatewayRuntimeAvailabilityService->expects($this->once()) |
| 41 | + ->method('hasDirectGatewayFallback') |
| 42 | + ->with('signal') |
| 43 | + ->willReturn(true); |
| 44 | + |
| 45 | + $this->assertTrue($this->service->isGatewayComplete('signal')); |
| 46 | + } |
| 47 | + |
| 48 | + public function testSendDelegatesToResolvedGateway(): void { |
| 49 | + $gateway = $this->createMock(IGateway::class); |
| 50 | + $gateway->expects($this->once()) |
| 51 | + ->method('send') |
| 52 | + ->with('+5511999999999', 'hello', []); |
| 53 | + |
| 54 | + $this->gatewayRuntimeAvailabilityService->expects($this->once()) |
| 55 | + ->method('getGateway') |
| 56 | + ->with('whatsapp') |
| 57 | + ->willReturn($gateway); |
| 58 | + |
| 59 | + $this->service->send('whatsapp', '+5511999999999', 'hello'); |
| 60 | + } |
| 61 | +} |
0 commit comments