Reparaciones con Prueba
This commit is contained in:
62
app/tests/unit/src/Service/Money/SIITest.php
Normal file
62
app/tests/unit/src/Service/Money/SIITest.php
Normal 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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user