Files
oficial/app/tests/unit/src/Service/ValorTest.php

72 lines
1.8 KiB
PHP
Raw Normal View History

2025-04-28 20:20:43 -04:00
<?php
2025-04-29 21:43:21 -04:00
namespace ProVM\Unit\Service;
2025-04-28 20:20:43 -04:00
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use Incoviba\Service\Valor;
use Incoviba\Service;
class ValorTest extends TestCase
{
protected Service\UF $ufService;
protected function setUp(): void
{
$this->ufService = $this->getMockBuilder(Service\UF::class)
->disableOriginalConstructor()
->getMock();
$this->ufService->method('get')->willReturn(35000.0);
}
public static function cleanDataProvider(): array
{
return [
['1.003.000,01', 1003000.01],
['4,273.84', 4273.84],
];
}
#[DataProvider('cleanDataProvider')]
public function testClean($input, $expected): void
{
$valorService = new Valor($this->ufService);
$result = $valorService->clean($input);
$this->assertIsFloat($result);
$this->assertEquals($expected, $result);
}
public function testToUF()
{
$date = '2025-01-01';
$valorService = new Valor($this->ufService);
$input = '1000000';
$result = $valorService->toUF($input, $date);
$this->assertIsFloat($result);
$this->assertEquals($input / 35000, $result);
}
public static function pesosDataProvider(): array
{
return [
[1000.01, 1000.01*35000, false],
[1000, 1000*35000, true],
['1000', 1000, false],
];
}
#[DataProvider('pesosDataProvider')]
public function testToPesos($input, $expected, $force)
{
$date = '2025-01-01';
$valorService = new Valor($this->ufService);
$result = $valorService->toPesos($input, $date, $force);
$this->assertIsInt($result);
$this->assertEquals($expected, $result);
}
}