Reparaciones con Prueba
This commit is contained in:
@ -61,7 +61,11 @@ class SII implements Define\Money\Provider
|
||||
throw new EmptyResponse($request_uri);
|
||||
}
|
||||
$body = $response->getBody();
|
||||
$domHandler = HTMLDocument::createFromString($body->getContents());
|
||||
$contents = $body->getContents();
|
||||
if (trim($contents) === '') {
|
||||
throw new EmptyResponse($request_uri);
|
||||
}
|
||||
$domHandler = HTMLDocument::createFromString($contents);
|
||||
$table = $domHandler->querySelector('div#mes_all');
|
||||
$tbody = $table->querySelector('tbody');
|
||||
$trs = $tbody->querySelectorAll('tr');
|
||||
@ -70,17 +74,17 @@ class SII implements Define\Money\Provider
|
||||
* [th 1, td #, #, #, #, #, #, #, #, #, #, #, #]
|
||||
*/
|
||||
$year = [];
|
||||
$trim = mb_chr(160);
|
||||
foreach ($trs as $i => $tr) {
|
||||
$tds = $tr->querySelectorAll('td');
|
||||
foreach ($tds as $j => $td) {
|
||||
$value = $td->nodeValue;
|
||||
if (trim($value) === '') {
|
||||
$value = $td->textContent;
|
||||
if (trim($value, "{$trim} ") === '') {
|
||||
continue;
|
||||
}
|
||||
$d = str_pad($j + 1, 2, '0', STR_PAD_LEFT);
|
||||
$m = str_pad($i, 2, '0', STR_PAD_LEFT);
|
||||
$m = str_pad($j + 1, 2, '0', STR_PAD_LEFT);
|
||||
$d = str_pad($i + 1, 2, '0', STR_PAD_LEFT);
|
||||
$date = "{$dateTime->format('Y')}-{$m}-{$d}";
|
||||
trigger_error($date);
|
||||
$value = $this->valorService->clean($value);
|
||||
$year[$date] = $value;
|
||||
}
|
||||
|
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