SII falla si fecha está en el futuro.
This commit is contained in:
@ -38,6 +38,10 @@ class SII implements Define\Money\Provider
|
||||
$dateTime = new DateTimeImmutable();
|
||||
}
|
||||
$year = $this->getUFYear($dateTime);
|
||||
|
||||
if (!isset($year[$dateTime->format('Y-m-d')])) {
|
||||
throw new EmptyResponse("{$dateTime->format('Y-m-d')} not found");
|
||||
}
|
||||
return $year[$dateTime->format('Y-m-d')];
|
||||
}
|
||||
|
||||
@ -51,6 +55,9 @@ class SII implements Define\Money\Provider
|
||||
if ($dateTime === null) {
|
||||
$dateTime = new DateTimeImmutable();
|
||||
}
|
||||
if ($dateTime->format('Y') > (new DateTimeImmutable())->format('Y')) {
|
||||
throw new EmptyResponse("{$dateTime->format('Y')} not found");
|
||||
}
|
||||
$request_uri = "uf/uf{$dateTime->format('Y')}.htm";
|
||||
try {
|
||||
$response = $this->client->get($request_uri);
|
||||
|
@ -5,6 +5,7 @@ use PDO;
|
||||
use PDOStatement;
|
||||
use GuzzleHttp\Client;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Common\Define;
|
||||
@ -53,4 +54,13 @@ class SIITest extends TestCase
|
||||
|
||||
$this->assertEquals($expected, $provider->get(Service\Money::UF, $date));
|
||||
}
|
||||
public function testGetNoValid(): void
|
||||
{
|
||||
$provider = new Service\Money\SII($this->client, $this->ufRepository);
|
||||
|
||||
$date = (new \DateTimeImmutable())->add(new \DateInterval("P1Y"));
|
||||
|
||||
$this->expectException(EmptyResponse::class);
|
||||
$provider->get(Service\Money::UF, $date);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user