FIX: Circular dependency
This commit is contained in:
@ -15,7 +15,7 @@ use Incoviba\Service;
|
|||||||
|
|
||||||
class SII implements Define\Money\Provider
|
class SII implements Define\Money\Provider
|
||||||
{
|
{
|
||||||
public function __construct(protected ClientInterface $client, protected Service\Valor $valorService,
|
public function __construct(protected ClientInterface $client,
|
||||||
protected Repository\UF $ufRepository) {}
|
protected Repository\UF $ufRepository) {}
|
||||||
|
|
||||||
public function get(string $money_symbol, ?DateTimeInterface $dateTime = null): float
|
public function get(string $money_symbol, ?DateTimeInterface $dateTime = null): float
|
||||||
@ -85,7 +85,7 @@ class SII implements Define\Money\Provider
|
|||||||
$m = str_pad($j + 1, 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);
|
$d = str_pad($i + 1, 2, '0', STR_PAD_LEFT);
|
||||||
$date = "{$dateTime->format('Y')}-{$m}-{$d}";
|
$date = "{$dateTime->format('Y')}-{$m}-{$d}";
|
||||||
$value = $this->valorService->clean($value);
|
$value = $this->clean($value);
|
||||||
$year[$date] = $value;
|
$year[$date] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,4 +130,8 @@ class SII implements Define\Money\Provider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
protected function clean(string $value): float
|
||||||
|
{
|
||||||
|
return trim(str_replace(',', '.', str_replace(['.', '$'], '', $value)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,6 @@ class SIITest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->client = new Client(['base_uri' => 'https://www.sii.cl/valores_y_fechas/']);
|
$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)
|
$this->pdo = $this->getMockBuilder(PDO::class)
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->pdo->method('beginTransaction')->willReturn(true);
|
$this->pdo->method('beginTransaction')->willReturn(true);
|
||||||
@ -52,7 +46,7 @@ class SIITest extends TestCase
|
|||||||
|
|
||||||
public function testGet(): void
|
public function testGet(): void
|
||||||
{
|
{
|
||||||
$provider = new Service\Money\SII($this->client, $this->valorService, $this->ufRepository);
|
$provider = new Service\Money\SII($this->client, $this->ufRepository);
|
||||||
|
|
||||||
$date = new \DateTimeImmutable('2025-05-05');
|
$date = new \DateTimeImmutable('2025-05-05');
|
||||||
$expected = 39107.9;
|
$expected = 39107.9;
|
||||||
|
Reference in New Issue
Block a user