diff --git a/src/Drivers/ExchangeRateHost/RequestBuilder.php b/src/Drivers/ExchangeRateHost/RequestBuilder.php index 7122d25..8acecf7 100644 --- a/src/Drivers/ExchangeRateHost/RequestBuilder.php +++ b/src/Drivers/ExchangeRateHost/RequestBuilder.php @@ -2,7 +2,9 @@ namespace AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRateHost; +use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesApiIo\Response; use AshAllenDesign\LaravelExchangeRates\Interfaces\RequestSender; +use AshAllenDesign\LaravelExchangeRates\Interfaces\ResponseContract; use Illuminate\Http\Client\RequestException; use Illuminate\Support\Facades\Http; @@ -15,15 +17,17 @@ class RequestBuilder implements RequestSender * * @param string $path * @param array $queryParams - * @return mixed + * @return ResponseContract * * @throws RequestException */ - public function makeRequest(string $path, array $queryParams = []): mixed + public function makeRequest(string $path, array $queryParams = []): ResponseContract { - return Http::baseUrl(self::BASE_URL) + $rawResponse = Http::baseUrl(self::BASE_URL) ->get($path, $queryParams) ->throw() ->json(); + + return new Response($rawResponse); } } diff --git a/src/Drivers/ExchangeRateHost/Response.php b/src/Drivers/ExchangeRateHost/Response.php new file mode 100644 index 0000000..b99d385 --- /dev/null +++ b/src/Drivers/ExchangeRateHost/Response.php @@ -0,0 +1,27 @@ +rawResponse[$key]; + } + + public function rates(): array + { + return $this->get('rates'); + } + + public function raw(): mixed + { + return $this->rawResponse; + } +} diff --git a/src/Drivers/ExchangeRatesApiIo/RequestBuilder.php b/src/Drivers/ExchangeRatesApiIo/RequestBuilder.php index ecf94b3..9b8a2ef 100644 --- a/src/Drivers/ExchangeRatesApiIo/RequestBuilder.php +++ b/src/Drivers/ExchangeRatesApiIo/RequestBuilder.php @@ -3,6 +3,7 @@ namespace AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesApiIo; use AshAllenDesign\LaravelExchangeRates\Interfaces\RequestSender; +use AshAllenDesign\LaravelExchangeRates\Interfaces\ResponseContract; use Illuminate\Http\Client\RequestException; use Illuminate\Support\Facades\Http; @@ -22,18 +23,20 @@ public function __construct() * * @param string $path * @param array $queryParams - * @return mixed + * @return ResponseContract * * @throws RequestException */ - public function makeRequest(string $path, array $queryParams = []): mixed + public function makeRequest(string $path, array $queryParams = []): ResponseContract { - return Http::baseUrl(self::BASE_URL) + $rawResponse = Http::baseUrl(self::BASE_URL) ->get( $path, array_merge(['access_key' => $this->apiKey], $queryParams) ) ->throw() ->json(); + + return new Response($rawResponse); } } diff --git a/src/Drivers/ExchangeRatesApiIo/Response.php b/src/Drivers/ExchangeRatesApiIo/Response.php new file mode 100644 index 0000000..04a4687 --- /dev/null +++ b/src/Drivers/ExchangeRatesApiIo/Response.php @@ -0,0 +1,27 @@ +rawResponse[$key]; + } + + public function rates(): array + { + return $this->get('rates'); + } + + public function raw(): mixed + { + return $this->rawResponse; + } +} diff --git a/src/Drivers/ExchangeRatesDataApi/RequestBuilder.php b/src/Drivers/ExchangeRatesDataApi/RequestBuilder.php index daf082b..d07d349 100644 --- a/src/Drivers/ExchangeRatesDataApi/RequestBuilder.php +++ b/src/Drivers/ExchangeRatesDataApi/RequestBuilder.php @@ -5,6 +5,7 @@ namespace AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesDataApi; use AshAllenDesign\LaravelExchangeRates\Interfaces\RequestSender; +use AshAllenDesign\LaravelExchangeRates\Interfaces\ResponseContract; use Illuminate\Http\Client\RequestException; use Illuminate\Support\Facades\Http; @@ -24,18 +25,20 @@ public function __construct() * * @param string $path * @param array $queryParams - * @return mixed + * @return ResponseContract * * @throws RequestException */ - public function makeRequest(string $path, array $queryParams = []): mixed + public function makeRequest(string $path, array $queryParams = []): ResponseContract { - return Http::baseUrl(self::BASE_URL) + $rawResponse = Http::baseUrl(self::BASE_URL) ->withHeaders([ 'apiKey' => $this->apiKey, ]) ->get($path, $queryParams) ->throw() ->json(); + + return new Response($rawResponse); } } diff --git a/src/Drivers/ExchangeRatesDataApi/Response.php b/src/Drivers/ExchangeRatesDataApi/Response.php new file mode 100644 index 0000000..87c0cf3 --- /dev/null +++ b/src/Drivers/ExchangeRatesDataApi/Response.php @@ -0,0 +1,27 @@ +rawResponse[$key]; + } + + public function rates(): array + { + return $this->get('rates'); + } + + public function raw(): mixed + { + return $this->rawResponse; + } +} diff --git a/src/Drivers/Support/SharedDriverLogicHandler.php b/src/Drivers/Support/SharedDriverLogicHandler.php index f3bd4a4..14c375c 100644 --- a/src/Drivers/Support/SharedDriverLogicHandler.php +++ b/src/Drivers/Support/SharedDriverLogicHandler.php @@ -66,9 +66,9 @@ public function currencies(): array $response = $this->requestBuilder->makeRequest('/latest', []); - $currencies = [$response['base']]; + $currencies = [$response->get('base')]; - foreach ($response['rates'] as $currency => $rate) { + foreach ($response->rates() as $currency => $rate) { $currencies[] = $currency; } @@ -122,7 +122,7 @@ public function exchangeRate(string $from, string|array $to, Carbon $date = null ? '/'.$date->format('Y-m-d') : '/latest'; - $response = $this->requestBuilder->makeRequest($url, $queryParams)['rates']; + $response = $this->requestBuilder->makeRequest($url, $queryParams)->rates(); $exchangeRate = is_string($to) ? $response[$to] : $response; @@ -199,7 +199,7 @@ private function makeRequestForExchangeRates(string $from, string|array $to, Car 'symbols' => $symbols, ]); - $conversions = $result['rates']; + $conversions = $result->rates(); if (is_string($to)) { foreach ($conversions as $date => $rate) { diff --git a/src/Interfaces/RequestSender.php b/src/Interfaces/RequestSender.php index 4c72a56..a318bd9 100644 --- a/src/Interfaces/RequestSender.php +++ b/src/Interfaces/RequestSender.php @@ -13,9 +13,9 @@ interface RequestSender * * @param string $path * @param string[] $queryParams - * @return mixed + * @return ResponseContract * * @throws RequestException */ - public function makeRequest(string $path, array $queryParams = []): mixed; + public function makeRequest(string $path, array $queryParams = []): ResponseContract; } diff --git a/src/Interfaces/ResponseContract.php b/src/Interfaces/ResponseContract.php new file mode 100644 index 0000000..b6c0c2b --- /dev/null +++ b/src/Interfaces/ResponseContract.php @@ -0,0 +1,14 @@ +convertBetweenDateRange(100, 'GBP', 'INVALID', now()->subWeek(), now()->subDay()); } - private function mockResponseForOneSymbol(): array + private function mockResponseForOneSymbol(): Response { - return [ + return new Response([ 'rates' => [ '2019-11-08' => [ 'EUR' => 1.1606583254, @@ -291,12 +292,12 @@ private function mockResponseForOneSymbol(): array 'start_date' => '2019-11-03', 'base' => 'GBP', 'end_date' => '2019-11-10', - ]; + ]); } - private function mockResponseForMultipleSymbols(): array + private function mockResponseForMultipleSymbols(): Response { - return [ + return new Response([ 'rates' => [ '2019-11-08' => [ 'EUR' => 1.1606583254, @@ -322,6 +323,6 @@ private function mockResponseForMultipleSymbols(): array 'start_date' => '2019-11-03', 'base' => 'GBP', 'end_date' => '2019-11-10', - ]; + ]); } } diff --git a/tests/Unit/Drivers/ExchangeRateHost/ConvertTest.php b/tests/Unit/Drivers/ExchangeRateHost/ConvertTest.php index de3f967..51f60ae 100644 --- a/tests/Unit/Drivers/ExchangeRateHost/ConvertTest.php +++ b/tests/Unit/Drivers/ExchangeRateHost/ConvertTest.php @@ -6,6 +6,7 @@ use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRateHost\ExchangeRateHostDriver; use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRateHost\RequestBuilder; +use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRateHost\Response; use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidCurrencyException; use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidDateException; use AshAllenDesign\LaravelExchangeRates\Tests\Unit\TestCase; @@ -142,9 +143,9 @@ public function exception_is_thrown_if_the_to_parameter_is_invalid(): void $exchangeRate->convert(100, 'GBP', 'INVALID', now()->subMinute()); } - private function mockResponseForCurrentDateAndOneSymbol(): array + private function mockResponseForCurrentDateAndOneSymbol(): Response { - return [ + return new Response([ 'rates' => [ 'CAD' => 1.4561, 'HKD' => 8.6372, @@ -181,13 +182,12 @@ private function mockResponseForCurrentDateAndOneSymbol(): array ], 'base' => 'EUR', 'date' => '2019-11-08', - ]; + ]); } - private function mockResponseForPastDateAndOneSymbol(): array + private function mockResponseForPastDateAndOneSymbol(): Response { - return - [ + return new Response([ 'rates' => [ 'CAD' => 1.4969, 'HKD' => 8.8843, @@ -224,12 +224,12 @@ private function mockResponseForPastDateAndOneSymbol(): array ], 'base' => 'EUR', 'date' => '2018-11-09', - ]; + ]); } - private function mockResponseForCurrentDateAndMultipleSymbols(): array + private function mockResponseForCurrentDateAndMultipleSymbols(): Response { - return [ + return new Response([ 'rates' => [ 'CAD' => 1.4561, 'USD' => 1.1034, @@ -237,6 +237,6 @@ private function mockResponseForCurrentDateAndMultipleSymbols(): array ], 'base' => 'EUR', 'date' => '2019-11-08', - ]; + ]); } } diff --git a/tests/Unit/Drivers/ExchangeRateHost/CurrenciesTest.php b/tests/Unit/Drivers/ExchangeRateHost/CurrenciesTest.php index c439890..45ceec2 100644 --- a/tests/Unit/Drivers/ExchangeRateHost/CurrenciesTest.php +++ b/tests/Unit/Drivers/ExchangeRateHost/CurrenciesTest.php @@ -6,6 +6,7 @@ use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRateHost\ExchangeRateHostDriver; use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRateHost\RequestBuilder; +use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRateHost\Response; use AshAllenDesign\LaravelExchangeRates\Tests\Unit\TestCase; use Illuminate\Support\Facades\Cache; use Mockery; @@ -77,9 +78,9 @@ public function currencies_are_not_cached_if_the_shouldCache_option_is_false(): $this->assertNull(Cache::get('laravel_xr_currencies')); } - private function mockResponse(): array + private function mockResponse(): Response { - return [ + return new Response([ 'rates' => [ 'CAD' => 1.4682, 'HKD' => 8.7298, @@ -116,7 +117,7 @@ private function mockResponse(): array ], 'base' => 'EUR', 'date' => '2019-11-01', - ]; + ]); } private function expectedResponse(): array diff --git a/tests/Unit/Drivers/ExchangeRateHost/ExchangeRateBetweenDateRangeTest.php b/tests/Unit/Drivers/ExchangeRateHost/ExchangeRateBetweenDateRangeTest.php index 664f3dc..5f467c2 100644 --- a/tests/Unit/Drivers/ExchangeRateHost/ExchangeRateBetweenDateRangeTest.php +++ b/tests/Unit/Drivers/ExchangeRateHost/ExchangeRateBetweenDateRangeTest.php @@ -6,6 +6,7 @@ use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRateHost\ExchangeRateHostDriver; use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRateHost\RequestBuilder; +use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRateHost\Response; use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidCurrencyException; use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidDateException; use AshAllenDesign\LaravelExchangeRates\Tests\Unit\TestCase; @@ -282,9 +283,9 @@ public function exception_is_thrown_if_one_of_the_to_parameter_currencies_are_in $exchangeRate->exchangeRateBetweenDateRange('GBP', ['USD', 'INVALID'], now()->subWeek(), now()->subDay()); } - private function mockResponseForOneSymbol(): array + private function mockResponseForOneSymbol(): Response { - return [ + return new Response([ 'rates' => [ '2019-11-08' => [ 'EUR' => 1.1606583254, @@ -305,12 +306,12 @@ private function mockResponseForOneSymbol(): array 'start_date' => '2019-11-03', 'base' => 'GBP', 'end_date' => '2019-11-10', - ]; + ]); } - private function mockResponseForMultipleSymbols(): array + private function mockResponseForMultipleSymbols(): Response { - return [ + return new Response([ 'rates' => [ '2019-11-08' => [ 'EUR' => 1.1606583254, @@ -336,6 +337,6 @@ private function mockResponseForMultipleSymbols(): array 'start_date' => '2019-11-03', 'base' => 'GBP', 'end_date' => '2019-11-10', - ]; + ]); } } diff --git a/tests/Unit/Drivers/ExchangeRateHost/ExchangeRateTest.php b/tests/Unit/Drivers/ExchangeRateHost/ExchangeRateTest.php index 7f7bf88..b34bec7 100644 --- a/tests/Unit/Drivers/ExchangeRateHost/ExchangeRateTest.php +++ b/tests/Unit/Drivers/ExchangeRateHost/ExchangeRateTest.php @@ -6,6 +6,7 @@ use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRateHost\ExchangeRateHostDriver; use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRateHost\RequestBuilder; +use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRateHost\Response; use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidCurrencyException; use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidDateException; use AshAllenDesign\LaravelExchangeRates\Tests\Unit\TestCase; @@ -26,7 +27,7 @@ public function exchange_rate_for_today_is_returned_if_no_date_parameter_passed_ $exchangeRate = new ExchangeRateHostDriver($requestBuilderMock); $rate = $exchangeRate->exchangeRate('EUR', 'GBP'); $this->assertEquals('0.86158', $rate); - $this->assertEquals('0.86158', Cache::get('laravel_xr_EUR_GBP_'.now()->format('Y-m-d'))); + $this->assertEquals('0.86158', Cache::get('laravel_xr_EUR_GBP_' . now()->format('Y-m-d'))); } /** @test */ @@ -36,14 +37,14 @@ public function exchange_rate_in_the_past_is_returned_if_date_parameter_passed_a $requestBuilderMock = Mockery::mock(RequestBuilder::class); $requestBuilderMock->expects('makeRequest') - ->withArgs(['/'.$mockDate->format('Y-m-d'), ['base' => 'EUR', 'symbols' => 'GBP']]) + ->withArgs(['/' . $mockDate->format('Y-m-d'), ['base' => 'EUR', 'symbols' => 'GBP']]) ->once() ->andReturn($this->mockResponseForPastDateAndOneSymbol()); $exchangeRate = new ExchangeRateHostDriver($requestBuilderMock); $rate = $exchangeRate->exchangeRate('EUR', 'GBP', $mockDate); $this->assertEquals('0.87053', $rate); - $this->assertEquals('0.87053', Cache::get('laravel_xr_EUR_GBP_'.$mockDate->format('Y-m-d'))); + $this->assertEquals('0.87053', Cache::get('laravel_xr_EUR_GBP_' . $mockDate->format('Y-m-d'))); } /** @test */ @@ -51,7 +52,7 @@ public function cached_exchange_rate_is_returned_if_it_exists(): void { $mockDate = now(); - Cache::forever('laravel_xr_EUR_GBP_'.$mockDate->format('Y-m-d'), 0.123456); + Cache::forever('laravel_xr_EUR_GBP_' . $mockDate->format('Y-m-d'), 0.123456); $requestBuilderMock = Mockery::mock(RequestBuilder::class); $requestBuilderMock->expects('makeRequest')->never(); @@ -59,7 +60,7 @@ public function cached_exchange_rate_is_returned_if_it_exists(): void $exchangeRate = new ExchangeRateHostDriver($requestBuilderMock); $rate = $exchangeRate->exchangeRate('EUR', 'GBP', $mockDate); $this->assertEquals('0.123456', $rate); - $this->assertEquals('0.123456', Cache::get('laravel_xr_EUR_GBP_'.$mockDate->format('Y-m-d'))); + $this->assertEquals('0.123456', Cache::get('laravel_xr_EUR_GBP_' . $mockDate->format('Y-m-d'))); } /** @test */ @@ -76,7 +77,7 @@ public function multiple_exchange_rates_can_be_returned_if_no_date_parameter_pas $this->assertEquals(['CAD' => 1.4561, 'USD' => 1.1034, 'GBP' => 0.86158], $response); $this->assertEquals( ['CAD' => 1.4561, 'USD' => 1.1034, 'GBP' => 0.86158], - Cache::get('laravel_xr_EUR_CAD_GBP_USD_'.now()->format('Y-m-d')) + Cache::get('laravel_xr_EUR_CAD_GBP_USD_' . now()->format('Y-m-d')) ); } @@ -87,7 +88,7 @@ public function multiple_exchange_rates_can_be_returned_if_date_parameter_passed $requestBuilderMock = Mockery::mock(RequestBuilder::class); $requestBuilderMock->expects('makeRequest') - ->withArgs(['/'.$mockDate->format('Y-m-d'), ['base' => 'EUR', 'symbols' => 'GBP,CAD,USD']]) + ->withArgs(['/' . $mockDate->format('Y-m-d'), ['base' => 'EUR', 'symbols' => 'GBP,CAD,USD']]) ->once() ->andReturn($this->mockResponseForPastDateAndMultipleSymbols()); @@ -96,7 +97,7 @@ public function multiple_exchange_rates_can_be_returned_if_date_parameter_passed $this->assertEquals(['CAD' => 1.4969, 'USD' => 1.1346, 'GBP' => 0.87053], $response); $this->assertEquals( ['CAD' => 1.4969, 'USD' => 1.1346, 'GBP' => 0.87053], - Cache::get('laravel_xr_EUR_CAD_GBP_USD_'.$mockDate->format('Y-m-d')) + Cache::get('laravel_xr_EUR_CAD_GBP_USD_' . $mockDate->format('Y-m-d')) ); } @@ -105,9 +106,9 @@ public function multiple_cached_exchange_rates_are_returned_if_they_exist(): voi { $mockDate = now(); - Cache::forget('laravel_xr_EUR_CAD_GBP_USD_'.$mockDate->format('Y-m-d')); + Cache::forget('laravel_xr_EUR_CAD_GBP_USD_' . $mockDate->format('Y-m-d')); - Cache::forever('laravel_xr_EUR_CAD_GBP_USD_'.$mockDate->format('Y-m-d'), + Cache::forever('laravel_xr_EUR_CAD_GBP_USD_' . $mockDate->format('Y-m-d'), ['CAD' => 1.4561, 'USD' => 1.1034, 'GBP' => 0.86158] ); @@ -119,7 +120,7 @@ public function multiple_cached_exchange_rates_are_returned_if_they_exist(): voi $this->assertEquals(['CAD' => 1.4561, 'USD' => 1.1034, 'GBP' => 0.86158], $rate); $this->assertEquals( ['CAD' => 1.4561, 'USD' => 1.1034, 'GBP' => 0.86158], - Cache::get('laravel_xr_EUR_CAD_GBP_USD_'.$mockDate->format('Y-m-d')) + Cache::get('laravel_xr_EUR_CAD_GBP_USD_' . $mockDate->format('Y-m-d')) ); } @@ -128,18 +129,18 @@ public function cached_exchange_rate_is_not_used_if_should_bust_cache_method_is_ { $mockDate = now(); - Cache::forever('laravel_xr_EUR_GBP_'.$mockDate->format('Y-m-d'), '0.123456'); + Cache::forever('laravel_xr_EUR_GBP_' . $mockDate->format('Y-m-d'), '0.123456'); $requestBuilderMock = Mockery::mock(RequestBuilder::class); $requestBuilderMock->expects('makeRequest') - ->withArgs(['/'.$mockDate->format('Y-m-d'), ['base' => 'EUR', 'symbols' => 'GBP']]) + ->withArgs(['/' . $mockDate->format('Y-m-d'), ['base' => 'EUR', 'symbols' => 'GBP']]) ->once() ->andReturn($this->mockResponseForPastDateAndOneSymbol()); $exchangeRate = new ExchangeRateHostDriver($requestBuilderMock); $rate = $exchangeRate->shouldBustCache()->exchangeRate('EUR', 'GBP', $mockDate); $this->assertEquals('0.87053', $rate); - $this->assertEquals('0.87053', Cache::get('laravel_xr_EUR_GBP_'.$mockDate->format('Y-m-d'))); + $this->assertEquals('0.87053', Cache::get('laravel_xr_EUR_GBP_' . $mockDate->format('Y-m-d'))); } /** @test */ @@ -154,7 +155,7 @@ public function exchange_rate_is_not_cached_if_the_shouldCache_option_is_false() $exchangeRate = new ExchangeRateHostDriver($requestBuilderMock); $rate = $exchangeRate->shouldCache(false)->exchangeRate('EUR', 'GBP'); $this->assertEquals('0.86158', $rate); - $this->assertNull(Cache::get('laravel_xr_EUR_GBP_'.now()->format('Y-m-d'))); + $this->assertNull(Cache::get('laravel_xr_EUR_GBP_' . now()->format('Y-m-d'))); } /** @test */ @@ -208,53 +209,51 @@ public function exception_is_thrown_if_the_to_parameter_array_is_invalid(): void $exchangeRate->exchangeRate('GBP', ['INVALID'], now()->subMinute()); } - private function mockResponseForCurrentDateAndOneSymbol(): array + private function mockResponseForCurrentDateAndOneSymbol(): Response { - return [ + return new Response([ 'rates' => [ 'GBP' => 0.86158, ], - 'base' => 'EUR', - 'date' => '2019-11-08', - ]; + 'base' => 'EUR', + 'date' => '2019-11-08', + ]); } - private function mockResponseForCurrentDateAndMultipleSymbols(): array + private function mockResponseForCurrentDateAndMultipleSymbols(): Response { - return [ + return new Response([ 'rates' => [ 'CAD' => 1.4561, 'USD' => 1.1034, 'GBP' => 0.86158, ], - 'base' => 'EUR', - 'date' => '2019-11-08', - ]; + 'base' => 'EUR', + 'date' => '2019-11-08', + ]); } - private function mockResponseForPastDateAndOneSymbol(): array + private function mockResponseForPastDateAndOneSymbol(): Response { - return - [ - 'rates' => [ - 'GBP' => 0.87053, - ], - 'base' => 'EUR', - 'date' => '2018-11-09', - ]; + return new Response([ + 'rates' => [ + 'GBP' => 0.87053, + ], + 'base' => 'EUR', + 'date' => '2018-11-09', + ]); } - private function mockResponseForPastDateAndMultipleSymbols(): array + private function mockResponseForPastDateAndMultipleSymbols(): Response { - return - [ - 'rates' => [ - 'CAD' => 1.4969, - 'USD' => 1.1346, - 'GBP' => 0.87053, - ], - 'base' => 'EUR', - 'date' => '2018-11-09', - ]; + return new Response([ + 'rates' => [ + 'CAD' => 1.4969, + 'USD' => 1.1346, + 'GBP' => 0.87053, + ], + 'base' => 'EUR', + 'date' => '2018-11-09', + ]); } } diff --git a/tests/Unit/Drivers/ExchangeRatesApiIo/ConvertBetweenDateRangeTest.php b/tests/Unit/Drivers/ExchangeRatesApiIo/ConvertBetweenDateRangeTest.php index eab95f2..0a6f28c 100644 --- a/tests/Unit/Drivers/ExchangeRatesApiIo/ConvertBetweenDateRangeTest.php +++ b/tests/Unit/Drivers/ExchangeRatesApiIo/ConvertBetweenDateRangeTest.php @@ -6,6 +6,7 @@ use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesApiIo\ExchangeRatesApiIoDriver; use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesApiIo\RequestBuilder; +use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesApiIo\Response; use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidCurrencyException; use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidDateException; use AshAllenDesign\LaravelExchangeRates\Tests\Unit\TestCase; @@ -268,9 +269,9 @@ public function exception_is_thrown_if_the_to_parameter_is_invalid(): void $exchangeRate->convertBetweenDateRange(100, 'GBP', 'INVALID', now()->subWeek(), now()->subDay()); } - private function mockResponseForOneSymbol(): array + private function mockResponseForOneSymbol(): Response { - return [ + return new Response([ 'rates' => [ '2019-11-08' => [ 'EUR' => 1.1606583254, @@ -291,12 +292,12 @@ private function mockResponseForOneSymbol(): array 'start_date' => '2019-11-03', 'base' => 'GBP', 'end_date' => '2019-11-10', - ]; + ]); } - private function mockResponseForMultipleSymbols(): array + private function mockResponseForMultipleSymbols(): Response { - return [ + return new Response([ 'rates' => [ '2019-11-08' => [ 'EUR' => 1.1606583254, @@ -322,6 +323,6 @@ private function mockResponseForMultipleSymbols(): array 'start_date' => '2019-11-03', 'base' => 'GBP', 'end_date' => '2019-11-10', - ]; + ]); } } diff --git a/tests/Unit/Drivers/ExchangeRatesApiIo/ConvertTest.php b/tests/Unit/Drivers/ExchangeRatesApiIo/ConvertTest.php index 826de05..188f05c 100644 --- a/tests/Unit/Drivers/ExchangeRatesApiIo/ConvertTest.php +++ b/tests/Unit/Drivers/ExchangeRatesApiIo/ConvertTest.php @@ -6,6 +6,7 @@ use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesApiIo\ExchangeRatesApiIoDriver; use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesApiIo\RequestBuilder; +use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesApiIo\Response; use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidCurrencyException; use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidDateException; use AshAllenDesign\LaravelExchangeRates\Tests\Unit\TestCase; @@ -142,9 +143,9 @@ public function exception_is_thrown_if_the_to_parameter_is_invalid(): void $exchangeRate->convert(100, 'GBP', 'INVALID', now()->subMinute()); } - private function mockResponseForCurrentDateAndOneSymbol(): array + private function mockResponseForCurrentDateAndOneSymbol(): Response { - return [ + return new Response([ 'rates' => [ 'CAD' => 1.4561, 'HKD' => 8.6372, @@ -181,13 +182,12 @@ private function mockResponseForCurrentDateAndOneSymbol(): array ], 'base' => 'EUR', 'date' => '2019-11-08', - ]; + ]); } - private function mockResponseForPastDateAndOneSymbol(): array + private function mockResponseForPastDateAndOneSymbol(): Response { - return - [ + return new Response([ 'rates' => [ 'CAD' => 1.4969, 'HKD' => 8.8843, @@ -224,12 +224,12 @@ private function mockResponseForPastDateAndOneSymbol(): array ], 'base' => 'EUR', 'date' => '2018-11-09', - ]; + ]); } - private function mockResponseForCurrentDateAndMultipleSymbols(): array + private function mockResponseForCurrentDateAndMultipleSymbols(): Response { - return [ + return new Response([ 'rates' => [ 'CAD' => 1.4561, 'USD' => 1.1034, @@ -237,6 +237,6 @@ private function mockResponseForCurrentDateAndMultipleSymbols(): array ], 'base' => 'EUR', 'date' => '2019-11-08', - ]; + ]); } } diff --git a/tests/Unit/Drivers/ExchangeRatesApiIo/CurrenciesTest.php b/tests/Unit/Drivers/ExchangeRatesApiIo/CurrenciesTest.php index 77b324b..607eecc 100644 --- a/tests/Unit/Drivers/ExchangeRatesApiIo/CurrenciesTest.php +++ b/tests/Unit/Drivers/ExchangeRatesApiIo/CurrenciesTest.php @@ -6,6 +6,7 @@ use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesApiIo\ExchangeRatesApiIoDriver; use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesApiIo\RequestBuilder; +use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesApiIo\Response; use AshAllenDesign\LaravelExchangeRates\Tests\Unit\TestCase; use Illuminate\Support\Facades\Cache; use Mockery; @@ -77,9 +78,9 @@ public function currencies_are_not_cached_if_the_shouldCache_option_is_false(): $this->assertNull(Cache::get('laravel_xr_currencies')); } - private function mockResponse(): array + private function mockResponse(): Response { - return [ + return new Response([ 'rates' => [ 'CAD' => 1.4682, 'HKD' => 8.7298, @@ -116,7 +117,7 @@ private function mockResponse(): array ], 'base' => 'EUR', 'date' => '2019-11-01', - ]; + ]); } private function expectedResponse(): array diff --git a/tests/Unit/Drivers/ExchangeRatesApiIo/ExchangeRateBetweenDateRangeTest.php b/tests/Unit/Drivers/ExchangeRatesApiIo/ExchangeRateBetweenDateRangeTest.php index 67add1f..32946fe 100644 --- a/tests/Unit/Drivers/ExchangeRatesApiIo/ExchangeRateBetweenDateRangeTest.php +++ b/tests/Unit/Drivers/ExchangeRatesApiIo/ExchangeRateBetweenDateRangeTest.php @@ -6,6 +6,7 @@ use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesApiIo\ExchangeRatesApiIoDriver; use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesApiIo\RequestBuilder; +use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesApiIo\Response; use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidCurrencyException; use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidDateException; use AshAllenDesign\LaravelExchangeRates\Tests\Unit\TestCase; @@ -282,9 +283,9 @@ public function exception_is_thrown_if_one_of_the_to_parameter_currencies_are_in $exchangeRate->exchangeRateBetweenDateRange('GBP', ['USD', 'INVALID'], now()->subWeek(), now()->subDay()); } - private function mockResponseForOneSymbol(): array + private function mockResponseForOneSymbol(): Response { - return [ + return new Response([ 'rates' => [ '2019-11-08' => [ 'EUR' => 1.1606583254, @@ -305,12 +306,12 @@ private function mockResponseForOneSymbol(): array 'start_date' => '2019-11-03', 'base' => 'GBP', 'end_date' => '2019-11-10', - ]; + ]); } - private function mockResponseForMultipleSymbols(): array + private function mockResponseForMultipleSymbols(): Response { - return [ + return new Response([ 'rates' => [ '2019-11-08' => [ 'EUR' => 1.1606583254, @@ -336,6 +337,6 @@ private function mockResponseForMultipleSymbols(): array 'start_date' => '2019-11-03', 'base' => 'GBP', 'end_date' => '2019-11-10', - ]; + ]); } } diff --git a/tests/Unit/Drivers/ExchangeRatesApiIo/ExchangeRateTest.php b/tests/Unit/Drivers/ExchangeRatesApiIo/ExchangeRateTest.php index 9cde773..eb7ea29 100644 --- a/tests/Unit/Drivers/ExchangeRatesApiIo/ExchangeRateTest.php +++ b/tests/Unit/Drivers/ExchangeRatesApiIo/ExchangeRateTest.php @@ -6,6 +6,7 @@ use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesApiIo\ExchangeRatesApiIoDriver; use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesApiIo\RequestBuilder; +use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesApiIo\Response; use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidCurrencyException; use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidDateException; use AshAllenDesign\LaravelExchangeRates\Tests\Unit\TestCase; @@ -208,20 +209,20 @@ public function exception_is_thrown_if_the_to_parameter_array_is_invalid(): void $exchangeRate->exchangeRate('GBP', ['INVALID'], now()->subMinute()); } - private function mockResponseForCurrentDateAndOneSymbol(): array + private function mockResponseForCurrentDateAndOneSymbol(): Response { - return [ + return new Response([ 'rates' => [ 'GBP' => 0.86158, ], 'base' => 'EUR', 'date' => '2019-11-08', - ]; + ]); } - private function mockResponseForCurrentDateAndMultipleSymbols(): array + private function mockResponseForCurrentDateAndMultipleSymbols(): Response { - return [ + return new Response([ 'rates' => [ 'CAD' => 1.4561, 'USD' => 1.1034, @@ -229,25 +230,23 @@ private function mockResponseForCurrentDateAndMultipleSymbols(): array ], 'base' => 'EUR', 'date' => '2019-11-08', - ]; + ]); } - private function mockResponseForPastDateAndOneSymbol(): array + private function mockResponseForPastDateAndOneSymbol(): Response { - return - [ + return new Response([ 'rates' => [ 'GBP' => 0.87053, ], 'base' => 'EUR', 'date' => '2018-11-09', - ]; + ]); } - private function mockResponseForPastDateAndMultipleSymbols(): array + private function mockResponseForPastDateAndMultipleSymbols(): Response { - return - [ + return new Response([ 'rates' => [ 'CAD' => 1.4969, 'USD' => 1.1346, @@ -255,6 +254,6 @@ private function mockResponseForPastDateAndMultipleSymbols(): array ], 'base' => 'EUR', 'date' => '2018-11-09', - ]; + ]); } } diff --git a/tests/Unit/Drivers/ExchangeRatesDataApi/ConvertBetweenDateRangeTest.php b/tests/Unit/Drivers/ExchangeRatesDataApi/ConvertBetweenDateRangeTest.php index ec6575d..68a3aae 100644 --- a/tests/Unit/Drivers/ExchangeRatesDataApi/ConvertBetweenDateRangeTest.php +++ b/tests/Unit/Drivers/ExchangeRatesDataApi/ConvertBetweenDateRangeTest.php @@ -6,6 +6,7 @@ use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesDataApi\ExchangeRatesDataApiDriver; use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesDataApi\RequestBuilder; +use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesDataApi\Response; use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidCurrencyException; use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidDateException; use AshAllenDesign\LaravelExchangeRates\Tests\Unit\TestCase; @@ -268,9 +269,9 @@ public function exception_is_thrown_if_the_to_parameter_is_invalid(): void $exchangeRate->convertBetweenDateRange(100, 'GBP', 'INVALID', now()->subWeek(), now()->subDay()); } - private function mockResponseForOneSymbol(): array + private function mockResponseForOneSymbol(): Response { - return [ + return new Response([ 'rates' => [ '2019-11-08' => [ 'EUR' => 1.1606583254, @@ -291,12 +292,12 @@ private function mockResponseForOneSymbol(): array 'start_date' => '2019-11-03', 'base' => 'GBP', 'end_date' => '2019-11-10', - ]; + ]); } - private function mockResponseForMultipleSymbols(): array + private function mockResponseForMultipleSymbols(): Response { - return [ + return new Response([ 'rates' => [ '2019-11-08' => [ 'EUR' => 1.1606583254, @@ -322,6 +323,6 @@ private function mockResponseForMultipleSymbols(): array 'start_date' => '2019-11-03', 'base' => 'GBP', 'end_date' => '2019-11-10', - ]; + ]); } } diff --git a/tests/Unit/Drivers/ExchangeRatesDataApi/ConvertTest.php b/tests/Unit/Drivers/ExchangeRatesDataApi/ConvertTest.php index 6dd61f9..e4e467a 100644 --- a/tests/Unit/Drivers/ExchangeRatesDataApi/ConvertTest.php +++ b/tests/Unit/Drivers/ExchangeRatesDataApi/ConvertTest.php @@ -11,6 +11,8 @@ use AshAllenDesign\LaravelExchangeRates\Tests\Unit\TestCase; use Illuminate\Support\Facades\Cache; use Mockery; +use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesDataApi\Response; + final class ConvertTest extends TestCase { @@ -142,9 +144,9 @@ public function exception_is_thrown_if_the_to_parameter_is_invalid(): void $exchangeRate->convert(100, 'GBP', 'INVALID', now()->subMinute()); } - private function mockResponseForCurrentDateAndOneSymbol(): array + private function mockResponseForCurrentDateAndOneSymbol(): Response { - return [ + return new Response([ 'rates' => [ 'CAD' => 1.4561, 'HKD' => 8.6372, @@ -181,13 +183,13 @@ private function mockResponseForCurrentDateAndOneSymbol(): array ], 'base' => 'EUR', 'date' => '2019-11-08', - ]; + ]); } - private function mockResponseForPastDateAndOneSymbol(): array + private function mockResponseForPastDateAndOneSymbol(): Response { return - [ + new Response([ 'rates' => [ 'CAD' => 1.4969, 'HKD' => 8.8843, @@ -224,12 +226,12 @@ private function mockResponseForPastDateAndOneSymbol(): array ], 'base' => 'EUR', 'date' => '2018-11-09', - ]; + ]); } - private function mockResponseForCurrentDateAndMultipleSymbols(): array + private function mockResponseForCurrentDateAndMultipleSymbols(): Response { - return [ + return new Response([ 'rates' => [ 'CAD' => 1.4561, 'USD' => 1.1034, @@ -237,6 +239,6 @@ private function mockResponseForCurrentDateAndMultipleSymbols(): array ], 'base' => 'EUR', 'date' => '2019-11-08', - ]; + ]); } } diff --git a/tests/Unit/Drivers/ExchangeRatesDataApi/CurrenciesTest.php b/tests/Unit/Drivers/ExchangeRatesDataApi/CurrenciesTest.php index 71a9892..c634229 100644 --- a/tests/Unit/Drivers/ExchangeRatesDataApi/CurrenciesTest.php +++ b/tests/Unit/Drivers/ExchangeRatesDataApi/CurrenciesTest.php @@ -9,6 +9,8 @@ use AshAllenDesign\LaravelExchangeRates\Tests\Unit\TestCase; use Illuminate\Support\Facades\Cache; use Mockery; +use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesDataApi\Response; + final class CurrenciesTest extends TestCase { @@ -77,9 +79,9 @@ public function currencies_are_not_cached_if_the_shouldCache_option_is_false(): $this->assertNull(Cache::get('laravel_xr_currencies')); } - private function mockResponse(): array + private function mockResponse(): Response { - return [ + return new Response([ 'rates' => [ 'CAD' => 1.4682, 'HKD' => 8.7298, @@ -116,7 +118,7 @@ private function mockResponse(): array ], 'base' => 'EUR', 'date' => '2019-11-01', - ]; + ]); } private function expectedResponse(): array diff --git a/tests/Unit/Drivers/ExchangeRatesDataApi/ExchangeRateBetweenDateRangeTest.php b/tests/Unit/Drivers/ExchangeRatesDataApi/ExchangeRateBetweenDateRangeTest.php index 59e9f30..01880f2 100644 --- a/tests/Unit/Drivers/ExchangeRatesDataApi/ExchangeRateBetweenDateRangeTest.php +++ b/tests/Unit/Drivers/ExchangeRatesDataApi/ExchangeRateBetweenDateRangeTest.php @@ -12,6 +12,8 @@ use Carbon\Carbon; use Illuminate\Support\Facades\Cache; use Mockery; +use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesDataApi\Response; + final class ExchangeRateBetweenDateRangeTest extends TestCase { @@ -282,9 +284,9 @@ public function exception_is_thrown_if_one_of_the_to_parameter_currencies_are_in $exchangeRate->exchangeRateBetweenDateRange('GBP', ['USD', 'INVALID'], now()->subWeek(), now()->subDay()); } - private function mockResponseForOneSymbol(): array + private function mockResponseForOneSymbol(): Response { - return [ + return new Response([ 'rates' => [ '2019-11-08' => [ 'EUR' => 1.1606583254, @@ -305,12 +307,12 @@ private function mockResponseForOneSymbol(): array 'start_date' => '2019-11-03', 'base' => 'GBP', 'end_date' => '2019-11-10', - ]; + ]); } - private function mockResponseForMultipleSymbols(): array + private function mockResponseForMultipleSymbols(): Response { - return [ + return new Response([ 'rates' => [ '2019-11-08' => [ 'EUR' => 1.1606583254, @@ -336,6 +338,6 @@ private function mockResponseForMultipleSymbols(): array 'start_date' => '2019-11-03', 'base' => 'GBP', 'end_date' => '2019-11-10', - ]; + ]); } } diff --git a/tests/Unit/Drivers/ExchangeRatesDataApi/ExchangeRateTest.php b/tests/Unit/Drivers/ExchangeRatesDataApi/ExchangeRateTest.php index 061524e..f0ccedd 100644 --- a/tests/Unit/Drivers/ExchangeRatesDataApi/ExchangeRateTest.php +++ b/tests/Unit/Drivers/ExchangeRatesDataApi/ExchangeRateTest.php @@ -6,6 +6,7 @@ use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesDataApi\ExchangeRatesDataApiDriver; use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesDataApi\RequestBuilder; +use AshAllenDesign\LaravelExchangeRates\Drivers\ExchangeRatesDataApi\Response; use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidCurrencyException; use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidDateException; use AshAllenDesign\LaravelExchangeRates\Tests\Unit\TestCase; @@ -208,20 +209,20 @@ public function exception_is_thrown_if_the_to_parameter_array_is_invalid(): void $exchangeRate->exchangeRate('GBP', ['INVALID'], now()->subMinute()); } - private function mockResponseForCurrentDateAndOneSymbol(): array + private function mockResponseForCurrentDateAndOneSymbol(): Response { - return [ + return new Response([ 'rates' => [ 'GBP' => 0.86158, ], 'base' => 'EUR', 'date' => '2019-11-08', - ]; + ]); } - private function mockResponseForCurrentDateAndMultipleSymbols(): array + private function mockResponseForCurrentDateAndMultipleSymbols(): Response { - return [ + return new Response([ 'rates' => [ 'CAD' => 1.4561, 'USD' => 1.1034, @@ -229,25 +230,24 @@ private function mockResponseForCurrentDateAndMultipleSymbols(): array ], 'base' => 'EUR', 'date' => '2019-11-08', - ]; + ]); } - private function mockResponseForPastDateAndOneSymbol(): array + private function mockResponseForPastDateAndOneSymbol(): Response { - return + return new Response( [ 'rates' => [ 'GBP' => 0.87053, ], 'base' => 'EUR', 'date' => '2018-11-09', - ]; + ]); } - private function mockResponseForPastDateAndMultipleSymbols(): array + private function mockResponseForPastDateAndMultipleSymbols(): Response { - return - [ + return new Response([ 'rates' => [ 'CAD' => 1.4969, 'USD' => 1.1346, @@ -255,6 +255,6 @@ private function mockResponseForPastDateAndMultipleSymbols(): array ], 'base' => 'EUR', 'date' => '2018-11-09', - ]; + ]); } }