Skip to content

Add support for invalid dates on higher layer #6

@maciej-sz

Description

@maciej-sz

Currently invalid dates are thrown on the transport level.

Example 1

    public function testFromMonthInTheFuture()
    {
        $inTwoMonths = (new \DateTimeImmutable())->add(new \DateInterval('P2M'));
        $currencyAverages = CurrencyAverageRatesService::create();
        $rates = $currencyAverages->fromMonth(...extract_ym($inTwoMonths));
        var_dump($rates->fromTable('A')->toArray());
    }

Causes: ClientException : HTTP/1.1 400 B��dny zakres dat / Invalid date range returned for...

Example 2

    public function testFromMonthBeforeRecords()
    {
        $currencyAverages = CurrencyAverageRatesService::create();
        $rates = $currencyAverages->fromMonth(1970, 1);
        var_dump($rates->fromTable('A')->toArray());
    }

Causes:
ClientException : HTTP/1.1 404 Bark danych / No data available returned for...

Example 3

    public function testFromDayBeforeInvalid()
    {
        $inTwoMonths = (new \DateTimeImmutable())->add(new \DateInterval('P2M'));
        self::expectException(RateNotFoundException::class);
        self::expectExceptionMessage("Gold rate from day before {$inTwoMonths->format('Y-m-d')} has not been found");

        $goldRates = GoldRatesService::create();
        $goldRates->fromDayBefore($inTwoMonths);
    }

Causes:
ClientException : HTTP/1.1 400 B��dny zakres dat / Invalid date range returned for ...

Todo

  • Move exceptions to higher layer
  • Handle caching of invalid requests (?)
  • Tests for average rates
  • Tests for trading rates
  • Tests for gold rates

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions