Valor con pruebas
This commit is contained in:
69
app/tests/unit/src/Service/ValorTest.php
Normal file
69
app/tests/unit/src/Service/ValorTest.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user