get Uf asincronico

This commit is contained in:
Juan Pablo Vial
2025-06-24 11:20:53 -04:00
parent 200510d60a
commit 39198bbe7c
2 changed files with 115 additions and 6 deletions

View File

@ -0,0 +1,73 @@
<?php
namespace Inventario\Service\Venta;
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
use Incoviba\Model;
use Incoviba\Repository;
use Incoviba\Service;
class PagoTest extends TestCase
{
protected float $uf;
protected Model\Venta\Pago $pago;
protected Repository\Venta\Pago $pagoRepository;
protected Repository\Venta\EstadoPago $estadoPagoRepository;
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository;
protected Service\UF $ufService;
protected Service\Valor $valorService;
protected Service\Queue $queueService;
protected function setUp(): void
{
$fecha = new DateTimeImmutable();
$this->uf = 37568.84;
$tipoEstadoPago = $this->getMockBuilder(Model\Venta\TipoEstadoPago::class)->disableOriginalConstructor()->getMock();
$tipoEstadoPago->id = 1;
$tipoEstadoPago->descripcion = 'depositado';
$estadoPago = $this->getMockBuilder(Model\Venta\EstadoPago::class)->disableOriginalConstructor()->getMock();
$estadoPago->id = 1;
$estadoPago->tipoEstadoPago = $tipoEstadoPago;
$estadoPago->fecha = $fecha;
$this->pago = $this->getMockBuilder(Model\Venta\Pago::class)->disableOriginalConstructor()->getMock();
$this->pago->id = 1;
$this->pago->fecha = $fecha;
$this->pago->uf = $this->uf;
$this->pago->currentEstado = $estadoPago;
$this->pagoRepository = $this->getMockBuilder(Repository\Venta\Pago::class)->disableOriginalConstructor()->getMock();
$this->pagoRepository->method('fetchById')->willReturn($this->pago);
$this->pagoRepository->method('edit')->willReturnCallback(function() {
$this->pago->uf = $this->uf;
return $this->pago;
});
$this->estadoPagoRepository = $this->getMockBuilder(Repository\Venta\EstadoPago::class)->disableOriginalConstructor()->getMock();
$this->estadoPagoRepository->method('fetchCurrentByPago')->with($this->pago->id)->willReturn($estadoPago);
$this->tipoEstadoPagoRepository = $this->getMockBuilder(Repository\Venta\TipoEstadoPago::class)->disableOriginalConstructor()->getMock();
$this->ufService = $this->getMockBuilder(Service\UF::class)->disableOriginalConstructor()->getMock();
$this->ufService->method('get')->with($fecha)->willReturn($this->uf);
$this->valorService = $this->getMockBuilder(Service\Valor::class)->disableOriginalConstructor()->getMock();
$this->queueService = $this->getMockBuilder(Service\Queue::class)->disableOriginalConstructor()->getMock();
}
public function testUpdateUF(): void
{
$this->pago->uf = null;
$pagoService = new Service\Venta\Pago(
$this->pagoRepository,
$this->estadoPagoRepository,
$this->tipoEstadoPagoRepository,
$this->ufService,
$this->valorService,
$this->queueService
);
$status = $pagoService->updateUF($this->pago->id);
$pago = $pagoService->getById($this->pago->id);
$this->assertTrue($status);
$this->assertEquals($pago->uf, $this->uf);
}
}