Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ExchangeRateServiceTest | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
| it_returns_the_rate_for_two_currencies | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Apie\Tests\ExchangeRate; |
| 4 | |
| 5 | use Apie\ExchangeRate\ExchangeRateService; |
| 6 | use PHPUnit\Framework\Attributes\Test; |
| 7 | use PHPUnit\Framework\TestCase; |
| 8 | use Symfony\Component\HttpClient\MockHttpClient; |
| 9 | use Symfony\Component\HttpClient\Response\MockResponse; |
| 10 | |
| 11 | class ExchangeRateServiceTest extends TestCase |
| 12 | { |
| 13 | #[Test] |
| 14 | public function it_returns_the_rate_for_two_currencies(): void |
| 15 | { |
| 16 | $client = new MockHttpClient(function (string $method, string $url): MockResponse { |
| 17 | self::assertSame('GET', $method); |
| 18 | self::assertSame( |
| 19 | 'https://api.frankfurter.app/latest?from=USD&to=EUR', |
| 20 | $url |
| 21 | ); |
| 22 | |
| 23 | return new MockResponse(json_encode(['rates' => ['EUR' => 0.92]])); |
| 24 | }); |
| 25 | |
| 26 | $service = new ExchangeRateService($client); |
| 27 | |
| 28 | self::assertSame(0.92, $service->calculateConversionRate('usd', 'eur')); |
| 29 | } |
| 30 | } |