SII falla si fecha está en el futuro.

This commit is contained in:
Juan Pablo Vial
2025-05-07 19:42:39 -04:00
parent f3e15b34a8
commit 878b02ee52
2 changed files with 17 additions and 0 deletions

View File

@ -38,6 +38,10 @@ class SII implements Define\Money\Provider
$dateTime = new DateTimeImmutable(); $dateTime = new DateTimeImmutable();
} }
$year = $this->getUFYear($dateTime); $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')]; return $year[$dateTime->format('Y-m-d')];
} }
@ -51,6 +55,9 @@ class SII implements Define\Money\Provider
if ($dateTime === null) { if ($dateTime === null) {
$dateTime = new DateTimeImmutable(); $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"; $request_uri = "uf/uf{$dateTime->format('Y')}.htm";
try { try {
$response = $this->client->get($request_uri); $response = $this->client->get($request_uri);

View File

@ -5,6 +5,7 @@ use PDO;
use PDOStatement; use PDOStatement;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Incoviba\Common\Implement\Exception\EmptyResponse;
use Incoviba\Service; use Incoviba\Service;
use Incoviba\Repository; use Incoviba\Repository;
use Incoviba\Common\Define; use Incoviba\Common\Define;
@ -53,4 +54,13 @@ class SIITest extends TestCase
$this->assertEquals($expected, $provider->get(Service\Money::UF, $date)); $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);
}
} }