From 0e903f99c431a4724cd011673f3d41a8abffaa76 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Mon, 5 May 2025 19:08:44 -0400 Subject: [PATCH] FIX: Circular dependency --- app/src/Service/Money/SII.php | 8 ++++++-- app/tests/unit/src/Service/Money/SIITest.php | 8 +------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/src/Service/Money/SII.php b/app/src/Service/Money/SII.php index 721b61a..8693448 100644 --- a/app/src/Service/Money/SII.php +++ b/app/src/Service/Money/SII.php @@ -15,7 +15,7 @@ use Incoviba\Service; 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) {} 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); $d = str_pad($i + 1, 2, '0', STR_PAD_LEFT); $date = "{$dateTime->format('Y')}-{$m}-{$d}"; - $value = $this->valorService->clean($value); + $value = $this->clean($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))); + } } diff --git a/app/tests/unit/src/Service/Money/SIITest.php b/app/tests/unit/src/Service/Money/SIITest.php index 4acb57d..061603b 100644 --- a/app/tests/unit/src/Service/Money/SIITest.php +++ b/app/tests/unit/src/Service/Money/SIITest.php @@ -23,12 +23,6 @@ class SIITest extends TestCase { $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); @@ -52,7 +46,7 @@ class SIITest extends TestCase 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'); $expected = 39107.9;