feature/cierres (#30)
Reservas agregar y aprobar Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl> Reviewed-on: #30
This commit is contained in:
64
app/tests/unit/src/Repository/DireccionTest.php
Normal file
64
app/tests/unit/src/Repository/DireccionTest.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace Incoviba\Test\Repository;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Faker;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class DireccionTest extends TestCase
|
||||
{
|
||||
protected Define\Connection $connection;
|
||||
protected Repository\Comuna $comunaRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->connection = $this->getMockBuilder(Define\Connection::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->comunaRepository = $this->getMockBuilder(Repository\Comuna::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->comunaRepository->method('fetchById')->willReturnCallback(function ($id) {
|
||||
$comuna = new Model\Comuna();
|
||||
$comuna->id = $id;
|
||||
return $comuna;
|
||||
});
|
||||
}
|
||||
|
||||
public function testCreate(): void
|
||||
{
|
||||
$direccionRepository = new Repository\Direccion($this->connection, $this->comunaRepository);
|
||||
|
||||
$faker = Faker\Factory::create();
|
||||
$data = [
|
||||
'calle' => $faker->streetName,
|
||||
'numero' => $faker->randomNumber(),
|
||||
'extra' => $faker->streetSuffix,
|
||||
'comuna' => $faker->randomNumber(),
|
||||
];
|
||||
$direccion = $direccionRepository->create($data);
|
||||
|
||||
$this->assertTrue(!isset($direccion->id));
|
||||
$this->assertEquals($data['calle'], $direccion->calle);
|
||||
$this->assertEquals($data['numero'], $direccion->numero);
|
||||
$this->assertEquals($data['extra'], $direccion->extra);
|
||||
$this->assertEquals($data['comuna'], $direccion->comuna->id);
|
||||
}
|
||||
public function testSave(): void
|
||||
{
|
||||
$direccionRepository = new Repository\Direccion($this->connection, $this->comunaRepository);
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
$direccion = new Model\Direccion();
|
||||
$direccion->calle = $faker->streetName;
|
||||
$direccion->numero = $faker->randomNumber(3);
|
||||
$direccion->extra = $faker->streetSuffix;
|
||||
$direccion->comuna = $this->getMockBuilder(Model\Comuna::class)->getMock();
|
||||
$direccion->comuna->id = $faker->numberBetween(10000, 18000);
|
||||
$direccion = $direccionRepository->save($direccion);
|
||||
|
||||
$this->assertTrue(isset($direccion->id));
|
||||
}
|
||||
}
|
62
app/tests/unit/src/Repository/PersonaTest.php
Normal file
62
app/tests/unit/src/Repository/PersonaTest.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace Incoviba\Test\Repository;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Faker;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class PersonaTest extends TestCase
|
||||
{
|
||||
protected Define\Connection $connection;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->connection = $this->getMockBuilder(Define\Connection::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
public function testCreate(): void
|
||||
{
|
||||
$personaRepository = new Repository\Persona($this->connection);
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
$data = [
|
||||
'rut' => $faker->randomNumber(8),
|
||||
'digito' => $faker->boolean(100 - round(1 / 11 * 100)) ? $faker->randomNumber(1) : 'K',
|
||||
'nombres' => $faker->name(),
|
||||
'apellido_paterno' => $faker->lastName(),
|
||||
'apellido_materno' => $faker->lastName()
|
||||
];
|
||||
$persona = $personaRepository->create($data);
|
||||
|
||||
$this->assertEquals($data['rut'], $persona->rut);
|
||||
$this->assertEquals($data['digito'], $persona->digito);
|
||||
$this->assertEquals($data['nombres'], $persona->nombres);
|
||||
$this->assertEquals($data['apellido_paterno'], $persona->apellidoPaterno);
|
||||
$this->assertEquals($data['apellido_materno'], $persona->apellidoMaterno);
|
||||
}
|
||||
public function testSave(): void
|
||||
{
|
||||
$personaRepository = new Repository\Persona($this->connection);
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
$data = [
|
||||
'rut' => $faker->randomNumber(8),
|
||||
'digito' => $faker->boolean(100 - round(1 / 11 * 100)) ? $faker->randomNumber(1) : 'K',
|
||||
'nombres' => $faker->name(),
|
||||
'apellido_paterno' => $faker->lastName(),
|
||||
'apellido_materno' => $faker->lastName()
|
||||
];
|
||||
$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'];
|
||||
$persona = $personaRepository->save($persona);
|
||||
$this->assertEquals($data['rut'], $persona->rut);
|
||||
}
|
||||
}
|
102
app/tests/unit/src/Repository/Venta/ReservationTest.php
Normal file
102
app/tests/unit/src/Repository/Venta/ReservationTest.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
namespace Incoviba\Test\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Faker;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class ReservationTest extends TestCase
|
||||
{
|
||||
protected Define\Connection $connection;
|
||||
protected Repository\Proyecto $proyectoRepository;
|
||||
protected Repository\Persona $personaRepository;
|
||||
protected Repository\Proyecto\Broker $brokerRepository;
|
||||
protected Repository\Venta\Unidad $unitRepository;
|
||||
protected Repository\Venta\Promotion $promotionRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->connection = $this->getMockBuilder(Define\Connection::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->proyectoRepository = $this->getMockBuilder(Repository\Proyecto::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->proyectoRepository->method('fetchById')->willReturnCallback(function ($id) {
|
||||
$proyecto = new Model\Proyecto();
|
||||
$proyecto->id = $id;
|
||||
return $proyecto;
|
||||
});
|
||||
$this->personaRepository = $this->getMockBuilder(Repository\Persona::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->personaRepository->method('fetchById')->willReturnCallback(function ($rut) {
|
||||
$persona = new Model\Persona();
|
||||
$persona->rut = $rut;
|
||||
return $persona;
|
||||
});
|
||||
$this->brokerRepository = $this->getMockBuilder(Repository\Proyecto\Broker::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->brokerRepository->method('fetchById')->willReturnCallback(function ($rut) {
|
||||
$broker = new Model\Proyecto\Broker();
|
||||
$broker->rut = $rut;
|
||||
return $broker;
|
||||
});
|
||||
$this->unitRepository = $this->getMockBuilder(Repository\Venta\Unidad::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->unitRepository->method('fetchById')->willReturnCallback(function ($id) {
|
||||
$unidad = new Model\Venta\Unidad();
|
||||
$unidad->id = $id;
|
||||
return $unidad;
|
||||
});
|
||||
$this->promotionRepository = $this->getMockBuilder(Repository\Venta\Promotion::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->promotionRepository->method('fetchById')->willReturnCallback(function ($id) {
|
||||
$promotion = new Model\Venta\Promotion();
|
||||
$promotion->id = $id;
|
||||
return $promotion;
|
||||
});
|
||||
}
|
||||
|
||||
public function testCreate(): void
|
||||
{
|
||||
$reservationRepository = new Repository\Venta\Reservation($this->connection, $this->proyectoRepository,
|
||||
$this->personaRepository, $this->brokerRepository, $this->unitRepository, $this->promotionRepository);
|
||||
$faker = Faker\Factory::create();
|
||||
$data = [
|
||||
'project_id' => $faker->numberBetween(1, 10),
|
||||
'buyer_rut' => $faker->randomNumber(8),
|
||||
'date' => $faker->dateTimeBetween('-2 years', 'now')->format('Y-m-d'),
|
||||
];
|
||||
$reservation = $reservationRepository->create($data);
|
||||
|
||||
$this->assertTrue(!isset($reservation->id));
|
||||
$this->assertEquals($data['project_id'], $reservation->project->id);
|
||||
$this->assertEquals($data['buyer_rut'], $reservation->buyer->rut);
|
||||
$this->assertEquals($data['date'], $reservation->date->format('Y-m-d'));
|
||||
}
|
||||
public function testSave(): void
|
||||
{
|
||||
$reservationRepository = new Repository\Venta\Reservation($this->connection, $this->proyectoRepository,
|
||||
$this->personaRepository, $this->brokerRepository, $this->unitRepository, $this->promotionRepository);
|
||||
$faker = Faker\Factory::create();
|
||||
$data = [
|
||||
'project_id' => $faker->numberBetween(1, 10),
|
||||
'buyer_rut' => $faker->randomNumber(8),
|
||||
'date' => $faker->dateTimeBetween('-2 years', 'now')->format('Y-m-d'),
|
||||
];
|
||||
$reservation = new Model\Venta\Reservation();
|
||||
$reservation->project = $this->proyectoRepository->fetchById($data['project_id']);
|
||||
$reservation->buyer = $this->personaRepository->fetchById($data['buyer_rut']);
|
||||
$reservation->date = new DateTimeImmutable($data['date']);
|
||||
$reservation = $reservationRepository->save($reservation);
|
||||
|
||||
$this->assertTrue(isset($reservation->id));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user