|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Peso\Debug\Tests\Services; |
| 6 | + |
| 7 | +use Peso\Core\Exceptions\ExchangeRateNotFoundException; |
| 8 | +use Peso\Core\Exceptions\RequestNotSupportedException; |
| 9 | +use Peso\Core\Requests\CurrentExchangeRateRequest; |
| 10 | +use Peso\Core\Responses\ErrorResponse; |
| 11 | +use Peso\Core\Services\NullService; |
| 12 | +use Peso\Debug\Services\BlackHoleService; |
| 13 | +use Peso\Debug\Services\ReplaceableService; |
| 14 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | + |
| 17 | +#[CoversClass(ReplaceableService::class)] |
| 18 | +final class ReplaceableServiceTest extends TestCase |
| 19 | +{ |
| 20 | + public function testSend(): void |
| 21 | + { |
| 22 | + $service = new ReplaceableService(new BlackHoleService()); |
| 23 | + |
| 24 | + $response = $service->send(new CurrentExchangeRateRequest('EUR', 'PHP')); |
| 25 | + self::assertInstanceOf(ErrorResponse::class, $response); |
| 26 | + self::assertInstanceOf(ExchangeRateNotFoundException::class, $response->exception); |
| 27 | + |
| 28 | + $service->service = new NullService(); |
| 29 | + |
| 30 | + $response = $service->send(new CurrentExchangeRateRequest('EUR', 'PHP')); |
| 31 | + self::assertInstanceOf(ErrorResponse::class, $response); |
| 32 | + self::assertInstanceOf(RequestNotSupportedException::class, $response->exception); |
| 33 | + } |
| 34 | + |
| 35 | + public function testSupports(): void |
| 36 | + { |
| 37 | + $service = new ReplaceableService(new BlackHoleService()); |
| 38 | + |
| 39 | + self::assertTrue($service->supports(new CurrentExchangeRateRequest('EUR', 'PHP'))); |
| 40 | + |
| 41 | + $service->service = new NullService(); |
| 42 | + |
| 43 | + self::assertFalse($service->supports(new CurrentExchangeRateRequest('EUR', 'PHP'))); |
| 44 | + } |
| 45 | +} |
0 commit comments