From 40538544101efeb2eb0441c69ea4273818390208 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Tue, 24 Jun 2025 11:16:19 -0400 Subject: [PATCH] Prueba UF --- app/tests/unit/src/Service/UFTest.php | 66 +++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 app/tests/unit/src/Service/UFTest.php diff --git a/app/tests/unit/src/Service/UFTest.php b/app/tests/unit/src/Service/UFTest.php new file mode 100644 index 0000000..4047b4b --- /dev/null +++ b/app/tests/unit/src/Service/UFTest.php @@ -0,0 +1,66 @@ +dateTime->format('Y-m-1')); + + $this->dateMap = [ + $today->sub(new DateInterval("P1M")), // Case: Date past + $today, // Case: Date === "Today" (1st of month) + new DateTimeImmutable($today->format('Y-m-8')), // Case: Date 8th of month (before 9th) + new DateTimeImmutable($today->format('Y-m-15')), // Case: Date 15th of month (after 9th) + $today->add(new DateInterval("P1M")), // Case: Date one month from now + ]; + $this->ufMap = [ + $faker->randomFloat(2, 10000, 20000), // 1st value + $faker->randomFloat(2, 25000, 38000), // 2nd value + $faker->randomFloat(2, 38000, 39000), // 3rd value (before 9th) + 0.0, // no value (after 9th) + 0.0 // no value + ]; + + $this->redisService = $this->getMockBuilder(Service\Redis::class)->disableOriginalConstructor()->getMock(); + $emptyRedis = $this->getMockBuilder(EmptyRedis::class)->disableOriginalConstructor()->getMock(); + $this->redisService->method('get')->willThrowException($emptyRedis); + $this->moneyService = $this->getMockBuilder(Service\Money::class)->disableOriginalConstructor()->getMock(); + $this->moneyService->method('getUF')->willReturnCallback(function($date) { + return $this->ufMap[array_search($date, $this->dateMap)]; + }); + $this->ufRepository = $this->getMockBuilder(Repository\UF::class)->disableOriginalConstructor()->getMock(); + $emptyResult = $this->getMockBuilder(EmptyResult::class)->disableOriginalConstructor()->getMock(); + $this->ufRepository->method('fetchByFecha')->willThrowException($emptyResult); + $this->logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock(); + } + + public function testGet() + { + $service = new Service\UF($this->redisService, $this->moneyService, $this->ufRepository, $this->logger); + + foreach ($this->dateMap as $i => $date) { + $uf = $service->get($date); + + $this->assertEquals($this->ufMap[$i], $uf); + } + } +} \ No newline at end of file