Reservas
This commit is contained in:
64
app/tests/unit/src/Service/DireccionTest.php
Normal file
64
app/tests/unit/src/Service/DireccionTest.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace Incoviba\Test\Service;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Faker;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Exception\ServiceAction;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class DireccionTest extends TestCase
|
||||
{
|
||||
protected LoggerInterface $logger;
|
||||
protected Repository\Direccion $direccionRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
|
||||
$this->direccionRepository = $this->getMockBuilder(Repository\Direccion::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->direccionRepository->method('fetchByCalleAndNumeroAndExtraAndComuna')
|
||||
->willThrowException(new Implement\Exception\EmptyResult(''));
|
||||
$this->direccionRepository->method('filterData')->willReturnArgument(0);
|
||||
$this->direccionRepository->method('create')->willReturnCallback(function($data) {
|
||||
$direccion = new Model\Direccion();
|
||||
$direccion->calle = $data['calle'];
|
||||
$direccion->numero = $data['numero'];
|
||||
$direccion->extra = $data['extra'];
|
||||
$direccion->comuna = $this->getMockBuilder(Model\Comuna::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$direccion->comuna->id = $data['comuna'];
|
||||
return $direccion;
|
||||
});
|
||||
$this->direccionRepository->method('save')->willReturnCallback(function($direccion) {
|
||||
$direccion->id = 1;
|
||||
return $direccion;
|
||||
});
|
||||
}
|
||||
|
||||
public function testAdd(): void
|
||||
{
|
||||
$direccionService = new Service\Direccion($this->logger, $this->direccionRepository);
|
||||
$faker = Faker\Factory::create('es_ES');
|
||||
|
||||
$data = [
|
||||
'street' => $faker->streetName,
|
||||
'number' => $faker->randomNumber(3),
|
||||
'extra' => $faker->word,
|
||||
'comuna_id' => $faker->numberBetween(10000, 18000),
|
||||
];
|
||||
$direccion = $direccionService->add($data);
|
||||
|
||||
$this->assertEquals($data['street'], $direccion->calle);
|
||||
$this->assertEquals($data['number'], $direccion->numero);
|
||||
$this->assertEquals($data['extra'], $direccion->extra);
|
||||
$this->assertEquals($data['comuna_id'], $direccion->comuna->id);
|
||||
}
|
||||
}
|
65
app/tests/unit/src/Service/PersonaTest.php
Normal file
65
app/tests/unit/src/Service/PersonaTest.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace Incoviba\Test\Service;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Faker;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Exception\ServiceAction;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class PersonaTest extends TestCase
|
||||
{
|
||||
protected LoggerInterface $logger;
|
||||
protected Repository\Persona $personaRepository;
|
||||
protected Repository\Persona\Datos $datosPersonaRepository;
|
||||
protected Repository\Venta\Propietario $propietarioRepository;
|
||||
protected Service\Direccion $direccionService;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
|
||||
$this->personaRepository = $this->getMockBuilder(Repository\Persona::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->personaRepository->method('fetchById')->willThrowException(new Implement\Exception\EmptyResult(''));
|
||||
$this->personaRepository->method('filterData')->willReturnArgument(0);
|
||||
$this->personaRepository->method('create')->willReturnCallback(function($data) {
|
||||
$persona = new Model\Persona();
|
||||
$persona->rut = $data['rut'];
|
||||
$persona->digito = $data['digito'];
|
||||
$persona->nombres = $data['nombres'];
|
||||
$persona->apellidoPaterno = $data['apellido_paterno'];
|
||||
$persona->apellidoMaterno = $data['apellido_materno'];
|
||||
return $persona;
|
||||
});
|
||||
$this->personaRepository->method('save')->willReturnArgument(0);
|
||||
$this->datosPersonaRepository = $this->getMockBuilder(Repository\Persona\Datos::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->propietarioRepository = $this->getMockBuilder(Repository\Venta\Propietario::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->propietarioRepository->method('fetchById')->willThrowException(new Implement\Exception\EmptyResult(''));
|
||||
$this->direccionService = $this->getMockBuilder(Service\Direccion::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
}
|
||||
|
||||
public function testAdd(): void
|
||||
{
|
||||
$personaService = new Service\Persona($this->logger, $this->personaRepository, $this->datosPersonaRepository,
|
||||
$this->propietarioRepository, $this->direccionService);
|
||||
$faker = Faker\Factory::create('es_ES');
|
||||
$digit = $faker->boolean(100-round(1/11*100)) ? $faker->randomNumber(1) : 'K';
|
||||
$data = [
|
||||
'rut' => $faker->randomNumber(8),
|
||||
'digito' => $digit,
|
||||
'nombres' => $faker->name(),
|
||||
'apellido_paterno' => $faker->lastName(),
|
||||
'apellido_materno' => $faker->lastName(),
|
||||
];
|
||||
$persona = $personaService->add($data);
|
||||
$this->assertEquals($data['rut'], $persona->rut);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace Inventario\Service\Venta;
|
||||
namespace Incoviba\Test\Service\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@ -70,4 +70,4 @@ class PagoTest extends TestCase
|
||||
$this->assertTrue($status);
|
||||
$this->assertEquals($pago->uf, $this->uf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
118
app/tests/unit/src/Service/Venta/ReservationTest.php
Normal file
118
app/tests/unit/src/Service/Venta/ReservationTest.php
Normal file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
namespace Incoviba\Tests\Unit\Service\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Faker;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class ReservationTest extends TestCase
|
||||
{
|
||||
protected LoggerInterface $logger;
|
||||
protected Repository\Venta\Reservation $reservationRepository;
|
||||
protected Repository\Venta\Reservation\State $stateRepository;
|
||||
protected Service\Persona $personaService;
|
||||
protected Service\Proyecto\Broker $brokerService;
|
||||
protected Service\Venta\Promotion $promotionService;
|
||||
protected Service\Venta\Unidad $unitService;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->logger = $this->getMockBuilder(LoggerInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->reservationRepository = $this->getMockBuilder(Repository\Venta\Reservation::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->reservationRepository->method('fetchByBuyerAndDate')->willThrowException(new Implement\Exception\EmptyResult(''));
|
||||
$this->reservationRepository->method('filterData')->willReturnArgument(0);
|
||||
$this->reservationRepository->method('create')->willReturnCallback(function($data) {
|
||||
$reservation = new Model\Venta\Reservation();
|
||||
$reservation->buyer = $this->getMockBuilder(Model\Persona::class)->disableOriginalConstructor()->getMock();
|
||||
$reservation->buyer->rut = $data['buyer_rut'];
|
||||
$reservation->project = $this->getMockBuilder(Model\Proyecto::class)->disableOriginalConstructor()->getMock();
|
||||
$reservation->project->id = $data['project_id'];
|
||||
$reservation->date = new DateTimeImmutable($data['date']);
|
||||
if (array_key_exists('broker_rut', $data)) {
|
||||
$reservation->broker = $this->getMockBuilder(Model\Proyecto\Broker::class)->disableOriginalConstructor()->getMock();
|
||||
$reservation->broker->rut = $data['broker_rut'];
|
||||
}
|
||||
return $reservation;
|
||||
});
|
||||
$this->reservationRepository->method('save')->willReturnCallback(function($reservation) {
|
||||
$reservation->id = 1;
|
||||
return $reservation;
|
||||
});
|
||||
$this->stateRepository = $this->getMockBuilder(Repository\Venta\Reservation\State::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->personaService = $this->getMockBuilder(Service\Persona::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->personaService->method('add')->willReturnCallback(function($data) {
|
||||
$persona = new Model\Persona();
|
||||
$persona->rut = $data['rut'];
|
||||
return $persona;
|
||||
});
|
||||
$this->brokerService = $this->getMockBuilder(Service\Proyecto\Broker::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->promotionService = $this->getMockBuilder(Service\Venta\Promotion::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->unitService = $this->getMockBuilder(Service\Venta\Unidad::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->unitService->method('getById')->willReturnCallback(function($id) {
|
||||
$unit = new Model\Venta\Unidad();
|
||||
$unit->id = $id;
|
||||
return $unit;
|
||||
});
|
||||
}
|
||||
|
||||
public function testAdd(): void
|
||||
{
|
||||
$faker = Faker\Factory::create();
|
||||
$reservationService = new Service\Venta\Reservation($this->logger, $this->reservationRepository,
|
||||
$this->stateRepository, $this->personaService, $this->brokerService, $this->promotionService,
|
||||
$this->unitService);
|
||||
|
||||
$units = [];
|
||||
$unitsValue = [];
|
||||
$unitsCount = $faker->numberBetween(1, 10);
|
||||
for ($i = 0; $i < $unitsCount; $i++) {
|
||||
$units[] = $faker->numberBetween(1, 100);
|
||||
$unitsValue[] = $faker->randomFloat(2, 1000, 10000);
|
||||
}
|
||||
$digit = $faker->boolean(100-round(1/11*100)) ? $faker->randomNumber(1) : 'K';
|
||||
$broker = $faker->boolean(10) ? $faker->randomNumber(8, true) : '';
|
||||
$promotions = [];
|
||||
$promotionsCount = $faker->numberBetween(0, 10);
|
||||
for ($i = 0; $i < $promotionsCount; $i++) {
|
||||
$promotions[] = $faker->numberBetween(1, 100);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'project_id' => $faker->numberBetween(1, 100),
|
||||
'date' => $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d'),
|
||||
'buyer_rut' => $faker->randomNumber(8, true),
|
||||
'buyer_digit' => $digit,
|
||||
'buyer_names' => $faker->firstName(),
|
||||
'buyer_last_name' => $faker->lastName(),
|
||||
'buyer_last_name2' => $faker->lastName(),
|
||||
'buyer_address_street' => $faker->streetName(),
|
||||
'buyer_address_number' => $faker->randomNumber(3),
|
||||
'buyer_address_comuna' => $faker->numberBetween(10000, 18000),
|
||||
'buyer_marital_status' => $faker->word(),
|
||||
'buyer_email' => $faker->email(),
|
||||
'buyer_phone' => $faker->randomNumber(9),
|
||||
'buyer_profession' => $faker->word(),
|
||||
'buyer_birthdate' => $faker->dateTimeBetween('-80 year', '-18 year')->format('Y-m-d'),
|
||||
'units' => $units,
|
||||
'units_value' => $unitsValue,
|
||||
'broker_rut' => $broker,
|
||||
'promotions' => $promotions
|
||||
];
|
||||
$reservation = $reservationService->add($data);
|
||||
$this->assertEquals($data['project_id'], $reservation->project->id);
|
||||
$this->assertEquals($data['buyer_rut'], $reservation->buyer->rut);
|
||||
$this->assertCount($unitsCount, $reservation->units);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user