Files
oficial/app/tests/unit/src/Service/Money/SIITest.php
2025-05-07 19:42:39 -04:00

67 lines
2.3 KiB
PHP

<?php
namespace ProVM\Unit\Service\Money;
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;
class SIITest extends TestCase
{
protected Client $client;
protected Service\UF $ufService;
protected Service\Valor $valorService;
protected \PDO $pdo;
protected Define\Connection $connection;
protected \PDOStatement $statement;
protected Repository\UF $ufRepository;
protected function setUp(): void
{
$this->client = new Client(['base_uri' => 'https://www.sii.cl/valores_y_fechas/']);
$this->pdo = $this->getMockBuilder(PDO::class)
->disableOriginalConstructor()->getMock();
$this->pdo->method('beginTransaction')->willReturn(true);
$this->pdo->method('commit')->willReturn(true);
#$this->pdo->method('rollBack')->willReturn(null);
$this->statement = $this->getMockBuilder(PDOStatement::class)->getMock();
$this->statement->method('fetchAll')->willReturn([]);
$this->connection = $this->getMockBuilder(Define\Connection::class)
->disableOriginalConstructor()->getMock();
$this->connection->method('getPDO')->willReturn($this->pdo);
$this->connection->method('query')->willReturn($this->statement);
$this->connection->method('execute')->willReturn($this->statement);
$this->ufRepository = $this->getMockBuilder(Repository\UF::class)
->disableOriginalConstructor()->getMock();
$this->ufRepository->method('getConnection')->willReturn($this->connection);
$this->ufRepository->method('getTable')->willReturn('uf');
}
public function testGet(): void
{
$provider = new Service\Money\SII($this->client, $this->ufRepository);
$date = new \DateTimeImmutable('2025-05-05');
$expected = 39107.9;
$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);
}
}