Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed "earliest date" validation #117

Merged
merged 4 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Removed the `api_url` config option. [#84](https://github.com/ash-jc-allen/laravel-exchange-rates/pull/84)
- Removed `existsInCache` method from the `src/Classes/CacheRepository.php` file. [#106](https://github.com/ash-jc-allen/laravel-exchange-rates/pull/106)
- Removed `validateIsStringOrArray` method from the `src/Classes/Validation` file. [#106](https://github.com/ash-jc-allen/laravel-exchange-rates/pull/106)
- Removed the validation that ensured a date wasn't before the 4th January 1999. [#117](https://github.com/ash-jc-allen/laravel-exchange-rates/pull/117)

**v5.2.0 (released 2023-01-11):**
- Added support for Laravel 10. [#81](https://github.com/ash-jc-allen/laravel-exchange-rates/pull/81)
Expand Down
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ For example, the `exchange-rates-api-io` driver has a `src/Drivers/ExchangeRates

If you're using or extending the `src/Classes/RequestBuilder` class, you'll need to update your code to use the correct driver's request builder instead.

### Removed the "earliest date" validation

Previously, Laravel Exchange Rates only worked with the `exchangeratesapi.io` API. This API only allowed you to retrieve exchange rates for dates after the 4th January 1999. So, the package used to prevent any dates before this from being used and would throw an `AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidDateException` exception if you tried to use a date before this.

As of v6.0.0, Laravel Exchange Rates now supports multiple APIs. Some of these APIs allow you to retrieve exchange rates for dates before the 4th January 1999. So, the package no longer prevents you from using dates before this. Instead, it will let the API handle the validation. If you'd still like to prevent dates before this from being used, you can add your own validation to your application's code.

## Upgrading from 4.* to 5.0.0

### Minimum PHP Version
Expand Down
10 changes: 1 addition & 9 deletions src/Classes/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ public static function validateStartAndEndDates(Carbon $from, Carbon $to): void
}

/**
* Validate the date that has been passed. We check that the date is in the past but
* that it's not before the earliest possible date that the exchange rates support
* (4th January 1999).
* Validate the date that has been passed is in the past.
*
* @param Carbon $date
*
Expand All @@ -77,11 +75,5 @@ public static function validateDate(Carbon $date): void
if (! $date->isPast()) {
throw new InvalidDateException('The date must be in the past.');
}

$earliestPossibleDate = Carbon::createFromDate(1999, 1, 4)->startOfDay();

if ($date->isBefore($earliestPossibleDate)) {
throw new InvalidDateException('The date cannot be before 4th January 1999.');
}
}
}
11 changes: 0 additions & 11 deletions tests/Unit/Drivers/ExchangeRatesApiIo/ExchangeRateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidCurrencyException;
use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidDateException;
use AshAllenDesign\LaravelExchangeRates\Tests\Unit\TestCase;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;
use Mockery;

Expand Down Expand Up @@ -199,16 +198,6 @@ public function exception_is_thrown_if_the_to_parameter_is_invalid(): void
$exchangeRate->exchangeRate('GBP', 'INVALID', now()->subMinute());
}

/** @test */
public function exception_is_thrown_if_the_date_is_before_the_earliest_possible_date(): void
{
$this->expectException(InvalidDateException::class);
$this->expectExceptionMessage('The date cannot be before 4th January 1999.');

$exchangeRate = new ExchangeRatesApiIoDriver();
$exchangeRate->exchangeRate('GBP', 'USD', Carbon::createFromDate(1999, 1, 3));
}

/** @test */
public function exception_is_thrown_if_the_to_parameter_array_is_invalid(): void
{
Expand Down
11 changes: 0 additions & 11 deletions tests/Unit/Drivers/ExchangeRatesDataApi/ExchangeRateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidCurrencyException;
use AshAllenDesign\LaravelExchangeRates\Exceptions\InvalidDateException;
use AshAllenDesign\LaravelExchangeRates\Tests\Unit\TestCase;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;
use Mockery;

Expand Down Expand Up @@ -199,16 +198,6 @@ public function exception_is_thrown_if_the_to_parameter_is_invalid(): void
$exchangeRate->exchangeRate('GBP', 'INVALID', now()->subMinute());
}

/** @test */
public function exception_is_thrown_if_the_date_is_before_the_earliest_possible_date(): void
{
$this->expectException(InvalidDateException::class);
$this->expectExceptionMessage('The date cannot be before 4th January 1999.');

$exchangeRate = new ExchangeRatesDataApiDriver();
$exchangeRate->exchangeRate('GBP', 'USD', Carbon::createFromDate(1999, 1, 3));
}

/** @test */
public function exception_is_thrown_if_the_to_parameter_array_is_invalid(): void
{
Expand Down