Reparaciones con Prueba

This commit is contained in:
Juan Pablo Vial
2025-05-05 19:01:15 -04:00
parent 167d8e1ab7
commit 186cd0f5b8
2 changed files with 72 additions and 6 deletions

View File

@ -0,0 +1,62 @@
<?php
namespace ProVM\Unit\Service\Money;
use PDO;
use PDOStatement;
use GuzzleHttp\Client;
use PHPUnit\Framework\TestCase;
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->ufService = $this->getMockBuilder(Service\UF::class)
->disableOriginalConstructor()->getMock();
$this->ufService->method('get')->willReturn(1.0);
$this->valorService = new Service\Valor($this->ufService);
$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->valorService, $this->ufRepository);
$date = new \DateTimeImmutable('2025-05-05');
$expected = 39107.9;
$this->assertEquals($expected, $provider->get(Service\Money::UF, $date));
}
}