feature/cierres (#30)
Reservas agregar y aprobar Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl> Reviewed-on: #30
This commit is contained in:
15
app/tests/extension/ContainerTrait.php
Normal file
15
app/tests/extension/ContainerTrait.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace Tests\Extension;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
trait ContainerTrait
|
||||
{
|
||||
protected ContainerInterface $container;
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
require_once implode(DIRECTORY_SEPARATOR, [dirname(__DIR__, 2), 'setup', 'container.php']);
|
||||
$this->container = buildContainer();
|
||||
}
|
||||
}
|
23
app/tests/extension/Seeds/Bancos.php
Normal file
23
app/tests/extension/Seeds/Bancos.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace Tests\Extension\Seeds;
|
||||
|
||||
use Tests\Extension\AbstractSeed;
|
||||
|
||||
class Bancos extends AbstractSeed
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$count = 10;
|
||||
|
||||
$data = [];
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$data[] = [
|
||||
'nombre' => $this->faker->company,
|
||||
];
|
||||
}
|
||||
|
||||
$this->table('banco')
|
||||
->insertValues($data)
|
||||
->save();
|
||||
}
|
||||
}
|
45
app/tests/extension/Seeds/BrokerContracts.php
Normal file
45
app/tests/extension/Seeds/BrokerContracts.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace Tests\Extension\Seeds;
|
||||
|
||||
use Tests\Extension\AbstractSeed;
|
||||
|
||||
class BrokerContracts extends AbstractSeed
|
||||
{
|
||||
public function getDependencies(): array
|
||||
{
|
||||
return [
|
||||
Brokers::class,
|
||||
Proyectos::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$brokers = $this->loadValues('brokers', columns: 'rut');
|
||||
$projects = $this->loadValues('proyecto', columns: 'id');
|
||||
|
||||
$data = [];
|
||||
foreach ($projects as $project) {
|
||||
$count = $this->faker->numberBetween(1, count($brokers));
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$data []= [
|
||||
'broker_rut' => $brokers[$i],
|
||||
'project_id' => $project,
|
||||
'commission' => $this->faker->randomFloat(4, 0, 1),
|
||||
];
|
||||
}
|
||||
}
|
||||
$this->table('broker_contracts')->insertValues($data)->save();
|
||||
|
||||
$contracts = $this->loadValues('broker_contracts', columns: 'id');
|
||||
$stateData = [];
|
||||
foreach ($contracts as $contract) {
|
||||
$stateData[]= [
|
||||
'contract_id' => $contract,
|
||||
'date' => $this->faker->dateTimeBetween('-1 year'),
|
||||
'type' => 1
|
||||
];
|
||||
}
|
||||
$this->table('broker_contract_states')->insertValues($stateData)->save();
|
||||
}
|
||||
}
|
50
app/tests/extension/Seeds/Brokers.php
Normal file
50
app/tests/extension/Seeds/Brokers.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace Tests\Extension\Seeds;
|
||||
|
||||
use Tests\Extension\AbstractSeed;
|
||||
|
||||
class Brokers extends AbstractSeed
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$addresses = $this->loadValues('direccion', columns: 'id');
|
||||
|
||||
|
||||
|
||||
$count = 10;
|
||||
$contactData = [];
|
||||
for($i = 0; $i < $count; $i++) {
|
||||
$rut = $this->faker->rut(false, false);
|
||||
$contactData[]= [
|
||||
'rut' => $rut,
|
||||
'digit' => $this->faker->digitoVerificador($rut),
|
||||
'name' => $this->faker->name,
|
||||
'email' => $this->faker->email,
|
||||
'phone' => $this->faker->phoneNumber,
|
||||
'address_id' => $this->faker->randomElement($addresses)
|
||||
];
|
||||
}
|
||||
$this->table('broker_contacts')->insertValues($contactData)->save();
|
||||
|
||||
$contacts = $this->loadValues('broker_contacts', columns: 'id');
|
||||
|
||||
$data = [];
|
||||
$brokerData = [];
|
||||
for($i = 0; $i < $count; $i ++) {
|
||||
$rut = $this->faker->rut(false, false);
|
||||
$data[] = [
|
||||
'rut' => $rut,
|
||||
'digit' => $this->faker->digitoVerificador($rut),
|
||||
'name' => $this->faker->word
|
||||
];
|
||||
$brokerData []= [
|
||||
'broker_rut' => $rut,
|
||||
'representante_id' => $this->faker->randomElement($contacts),
|
||||
'legal_name' => $this->faker->company
|
||||
];
|
||||
}
|
||||
|
||||
$this->table('brokers')->insertValues($data)->save();
|
||||
$this->table('broker_data')->insertValues($brokerData)->save();
|
||||
}
|
||||
}
|
@ -9,14 +9,14 @@ class Direcciones extends AbstractSeed
|
||||
{
|
||||
$comunas = $this->loadValues('comuna', columns: 'id');
|
||||
|
||||
$n = 50;
|
||||
$n = 100;
|
||||
$data = [];
|
||||
for ($i = 0; $i < $n; $i++) {
|
||||
$row = [
|
||||
'calle' => $this->faker->streetName,
|
||||
'numero' => $this->faker->randomNumber(5),
|
||||
'comuna' => $this->faker->randomElement($comunas),
|
||||
'extra' => '',
|
||||
'extra' => $this->faker->optional(0.9, '')->words(2, true),
|
||||
];
|
||||
$extraRand = ((int) round(rand() / getrandmax())) === 1;
|
||||
if ($extraRand) {
|
||||
|
@ -5,9 +5,17 @@ use Tests\Extension\AbstractSeed;
|
||||
|
||||
class Inmobiliarias extends AbstractSeed
|
||||
{
|
||||
public function getDependencies(): array
|
||||
{
|
||||
return [
|
||||
Bancos::class
|
||||
];
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$tipos = $this->loadValues('tipo_sociedad', columns: 'id');
|
||||
$bancos = $this->loadValues('banco', columns: 'id');
|
||||
$suffixes = [
|
||||
'Inmobiliaria ',
|
||||
'Administradora ',
|
||||
@ -28,8 +36,10 @@ class Inmobiliarias extends AbstractSeed
|
||||
'dv' => $this->faker->digitoVerificador($rut),
|
||||
'razon' => $razon,
|
||||
'abreviacion' => $abreviacion,
|
||||
'sigla' => $sigla,
|
||||
'cuenta' => $this->faker->randomNumber(8),
|
||||
'banco' => $this->faker->randomElement($bancos),
|
||||
'sociedad' => $this->faker->randomElement($tipos),
|
||||
'sigla' => $sigla,
|
||||
];
|
||||
}
|
||||
$this->table('inmobiliaria')
|
||||
|
55
app/tests/extension/Seeds/Promotions.php
Normal file
55
app/tests/extension/Seeds/Promotions.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace Tests\Extension\Seeds;
|
||||
|
||||
use DateInterval;
|
||||
use Tests\Extension\AbstractSeed;
|
||||
|
||||
class Promotions extends AbstractSeed
|
||||
{
|
||||
public function getDependencies(): array
|
||||
{
|
||||
return [
|
||||
Proyectos::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$projects = $this->loadValues('proyecto', columns: 'id');
|
||||
|
||||
$data = [];
|
||||
$count = $this->faker->numberBetween(1, 10);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$start = $this->faker->dateTimeBetween('-1 year');
|
||||
$end = $this->faker->dateTimeBetween($start, $start->add(new DateInterval('P1Y')));
|
||||
$data[] = [
|
||||
'description' => $this->faker->sentence,
|
||||
'type' => 1,
|
||||
'amount' => $this->faker->randomFloat(2, 0, 1),
|
||||
'start_date' => $start,
|
||||
'end_date' => $end,
|
||||
'valid_until' => $this->faker->dateTimeBetween($end, $end->add(new DateInterval('P1M'))),
|
||||
'state' => 1,
|
||||
];
|
||||
}
|
||||
$this->table('promotions')->insertValues($data)->save();
|
||||
|
||||
$promotions = $this->loadValues('promotions', columns: 'id');
|
||||
|
||||
$data = [];
|
||||
foreach ($projects as $project) {
|
||||
$hasPromo = $this->faker->boolean(10);
|
||||
if (!$hasPromo) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data []= [
|
||||
'promotion_id' => $this->faker->randomElement($promotions),
|
||||
'project_id' => $project,
|
||||
];
|
||||
}
|
||||
if (count($data) > 0) {
|
||||
$this->table('promotion_projects')->insertValues($data)->save();
|
||||
}
|
||||
}
|
||||
}
|
42
app/tests/extension/Seeds/ProyectoTipoUnidad.php
Normal file
42
app/tests/extension/Seeds/ProyectoTipoUnidad.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace Tests\Extension\Seeds;
|
||||
|
||||
use Tests\Extension\AbstractSeed;
|
||||
|
||||
class ProyectoTipoUnidad extends AbstractSeed
|
||||
{
|
||||
public function getDependencies(): array
|
||||
{
|
||||
return [
|
||||
Proyectos::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$projects = $this->loadValues('proyecto', columns: 'id');
|
||||
$types = $this->loadValues('tipo_unidad', columns: 'id');
|
||||
|
||||
$data = [];
|
||||
foreach ($projects as $project) {
|
||||
foreach ($types as $type) {
|
||||
$count = $this->faker->numberBetween(1, 10);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$name = $this->faker->word;
|
||||
$data []= [
|
||||
'proyecto' => $project,
|
||||
'tipo' => $type,
|
||||
'nombre' => $name,
|
||||
'abreviacion' => substr($name, 0, 3),
|
||||
'm2' => $this->faker->randomFloat(2, 10, 100),
|
||||
'logia' => $this->faker->optional(.3, 0)->randomFloat(2, 1, 5),
|
||||
'terraza' => $this->faker->optional(.3, 0)->randomFloat(2, 2, 30),
|
||||
'descripcion' => $this->faker->sentence,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->table('proyecto_tipo_unidad')->insertValues($data)->save();
|
||||
}
|
||||
}
|
@ -27,9 +27,9 @@ class Proyectos extends AbstractSeed
|
||||
'direccion' => $this->faker->randomElement($direcciones),
|
||||
'superficie_sobre_nivel' => $this->faker->randomFloat(2, 1000, 10000),
|
||||
'superficie_bajo_nivel' => $this->faker->randomFloat(2, 0, 5000),
|
||||
'pisos' => $this->faker->randomNumber(2),
|
||||
'subterraneos' => $this->faker->randomNumber(2),
|
||||
'corredor' => $this->faker->randomFloat(4, 0, 1)
|
||||
'pisos' => $this->faker->numberBetween(2, 30),
|
||||
'subterraneos' => $this->faker->numberBetween(0, 5),
|
||||
'corredor' => $this->faker->optional(.6, 0)->randomFloat(4, 0, 1)
|
||||
];
|
||||
}
|
||||
|
||||
|
47
app/tests/extension/Seeds/Unidades.php
Normal file
47
app/tests/extension/Seeds/Unidades.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Tests\Extension\Seeds;
|
||||
|
||||
use Tests\Extension\AbstractSeed;
|
||||
|
||||
class Unidades extends AbstractSeed
|
||||
{
|
||||
public function getDependencies(): array
|
||||
{
|
||||
return [
|
||||
ProyectoTipoUnidad::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$ptus = $this->loadValues('proyecto_tipo_unidad', columns: ['id', 'proyecto', 'tipo', 'm2', 'logia', 'terraza']);
|
||||
|
||||
$data = [];
|
||||
foreach ($ptus as $s => $ptu) {
|
||||
$count = $this->faker->numberBetween(1, 10);
|
||||
$abr = $this->faker->word;
|
||||
$orientation = $this->faker->randomElement(['N', 'NO', 'NP', 'S', 'SO', 'SP', 'P', 'O']);
|
||||
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$data[] = [
|
||||
'proyecto' => $ptu['proyecto'],
|
||||
'tipo' => $ptu['tipo'],
|
||||
'subtipo' => $s,
|
||||
'piso' => $i + 2,
|
||||
'descripcion' => ($i + 2) * 100 + $s,
|
||||
'abreviacion' => $abr,
|
||||
'm2' => $ptu['m2'],
|
||||
'logia' => $ptu['logia'],
|
||||
'cubierta' => 0,
|
||||
'terraza' => $ptu['terraza'],
|
||||
'orientacion' => $orientation,
|
||||
'costo_inmobiliaria' => $this->faker->randomFloat(2, 1000, 3000),
|
||||
'pt' => $ptu['id'],
|
||||
'valor' => $this->faker->randomFloat(2, 1000, 3000),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$this->table('unidad')->insertValues($data)->save();
|
||||
}
|
||||
}
|
92
app/tests/integration/API/Ventas/ReservationTest.php
Normal file
92
app/tests/integration/API/Ventas/ReservationTest.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
namespace Incoviba\Tests\Integration\API\Ventas;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Faker;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Repository;
|
||||
use Tests\Extension\AbstractIntegration;
|
||||
use Tests\Extension\ContainerTrait;
|
||||
use Tests\Extension\Faker\Provider\Rut;
|
||||
|
||||
class ReservationTest extends TestCase
|
||||
{
|
||||
use ContainerTrait;
|
||||
|
||||
public function testAdd(): void
|
||||
{
|
||||
$faker = Faker\Factory::create('es_CL');
|
||||
$faker->addProvider(new Rut($faker));
|
||||
|
||||
$comunas = $this->container->get(Repository\Comuna::class)->fetchAll();
|
||||
$projects = $this->container->get(Repository\Proyecto::class)->fetchAll();
|
||||
$project = $faker->randomElement($projects);
|
||||
$brokers = $this->container->get(Repository\Proyecto\Broker::class)->fetchAll();
|
||||
$units = $this->container->get(Repository\Venta\Unidad::class)->fetchAll();
|
||||
|
||||
$selectedUnits = [];
|
||||
$unitsValue = [];
|
||||
$unitsCount = $faker->numberBetween(1, 3);
|
||||
for ($i = 0; $i < $unitsCount; $i++) {
|
||||
$selectedUnits[] = $faker->randomElement($units)->id;
|
||||
$unitsValue[] = $faker->randomFloat(2, 1000, 10000);
|
||||
}
|
||||
|
||||
$broker = $faker->randomElement($brokers);
|
||||
|
||||
$activePromotions = $this->container->get(Repository\Venta\Promotion::class)->fetchActiveByProject($project->id);
|
||||
|
||||
$promotionsCount = $faker->numberBetween(0, min(3, count($activePromotions)));
|
||||
$promotions = [];
|
||||
for ($i = 0; $i < $promotionsCount; $i++) {
|
||||
$promotions[] = $faker->randomElement($activePromotions)->id;
|
||||
}
|
||||
$rut = $faker->rut(false, false);
|
||||
$data = [
|
||||
'project_id' => $faker->randomElement($projects)->id,
|
||||
'date' => $faker->dateTimeBetween('-2 years', 'now')->format('Y-m-d'),
|
||||
'buyer_rut' => $rut,
|
||||
'buyer_digit' => $faker->digitoVerificador($rut),
|
||||
'buyer_names' => $faker->firstName,
|
||||
'buyer_last_name' => $faker->lastName,
|
||||
'buyer_last_name2' => $faker->lastName,
|
||||
'buyer_email' => $faker->email,
|
||||
'buyer_phone' => $faker->randomNumber(8),
|
||||
'buyer_address_street' => $faker->streetName,
|
||||
'buyer_address_number' => $faker->buildingNumber,
|
||||
'buyer_address_extra' => $faker->streetAddress,
|
||||
'buyer_address_comuna_id' => $faker->randomElement($comunas)->id,
|
||||
'units' => $selectedUnits,
|
||||
'units_value' => $unitsValue,
|
||||
'broker_rut' => $broker ? $broker->rut : '',
|
||||
];
|
||||
if (count($promotions) > 0) {
|
||||
$data['promotions'] = $promotions;
|
||||
}
|
||||
|
||||
$reservation = $this->container->get(Service\Venta\Reservation::class)->add($data);
|
||||
$this->assertInstanceOf(Model\Venta\Reservation::class, $reservation);
|
||||
$this->assertEquals($data['date'], $reservation->date->format('Y-m-d'));
|
||||
$this->assertEquals($data['project_id'], $reservation->project->id);
|
||||
$this->assertEquals($data['buyer_rut'], $reservation->buyer->rut);
|
||||
$this->assertEquals($data['buyer_digit'], $reservation->buyer->digito);
|
||||
$this->assertEquals($data['buyer_names'], $reservation->buyer->nombres);
|
||||
$this->assertEquals($data['buyer_last_name'], $reservation->buyer->apellidoPaterno);
|
||||
$this->assertEquals($data['buyer_last_name2'], $reservation->buyer->apellidoMaterno);
|
||||
$this->assertEquals($data['buyer_email'], $reservation->buyer->datos->email);
|
||||
$this->assertEquals($data['buyer_phone'], $reservation->buyer->datos->telefono);
|
||||
$this->assertEquals($data['buyer_address_street'], $reservation->buyer->datos->direccion->calle);
|
||||
$this->assertEquals($data['buyer_address_number'], $reservation->buyer->datos->direccion->numero);
|
||||
$this->assertEquals($data['buyer_address_extra'], $reservation->buyer->datos->direccion->extra);
|
||||
$this->assertEquals($data['buyer_address_comuna_id'], $reservation->buyer->datos->direccion->comuna->id);
|
||||
if ($broker !== null) {
|
||||
$this->assertEquals($data['broker_rut'], $reservation->broker->rut);
|
||||
}
|
||||
$this->assertEquals(1, $reservation->currentState()->type->value);
|
||||
}
|
||||
}
|
@ -11,17 +11,12 @@ use Incoviba\Common\Implement;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Repository;
|
||||
use Tests\Extension\ContainerTrait;
|
||||
use Tests\Extension\Faker\Provider\Rut;
|
||||
|
||||
class QueueTest extends TestCase
|
||||
{
|
||||
protected ContainerInterface $container;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
require_once implode(DIRECTORY_SEPARATOR, [dirname(__DIR__, 2), 'setup', 'container.php']);
|
||||
$this->container = buildContainer();
|
||||
}
|
||||
use ContainerTrait;
|
||||
|
||||
public function testServiceWorker(): void
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ class ReservationTest extends AbstractModel
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->model = new Reservation();
|
||||
$this->properties = ['buyer', 'date', 'units', 'promotions', 'broker'];
|
||||
$this->properties = ['project', 'buyer', 'date', 'units', 'promotions', 'broker'];
|
||||
$this->methods = ['states', 'currentState', 'addUnit', 'removeUnit', 'findUnit', 'hasUnit'];
|
||||
}
|
||||
}
|
||||
|
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));
|
||||
}
|
||||
}
|
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);
|
||||
}
|
||||
}
|
@ -3,18 +3,22 @@ namespace Tests\Unit\Service;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Faker\Factory;
|
||||
use Incoviba\Service\Valor;
|
||||
use Incoviba\Service;
|
||||
|
||||
class ValorTest extends TestCase
|
||||
{
|
||||
protected Service\UF $ufService;
|
||||
protected static float $staticUF = 35498.76;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->ufService = $this->getMockBuilder(Service\UF::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->ufService->method('get')->willReturn(35000.0);
|
||||
$faker = Factory::create();
|
||||
$this->ufService->method('get')->willReturn(self::$staticUF);
|
||||
}
|
||||
|
||||
public static function cleanDataProvider(): array
|
||||
@ -55,14 +59,14 @@ class ValorTest extends TestCase
|
||||
$result = $valorService->toUF($input, $date);
|
||||
|
||||
$this->assertIsFloat($result);
|
||||
$this->assertEquals($input / 35000, $result);
|
||||
$this->assertEquals($input / self::$staticUF, $result);
|
||||
}
|
||||
|
||||
public static function pesosDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[1000.01, 1000.01*35000, false],
|
||||
[1000, 1000*35000, true],
|
||||
[1000.01, round(1000.01*self::$staticUF), false],
|
||||
[1000, round(1000*self::$staticUF), true],
|
||||
['1000', 1000, false],
|
||||
];
|
||||
}
|
||||
|
65
app/tests/unit/src/Service/Venta/BonoPieTest.php
Normal file
65
app/tests/unit/src/Service/Venta/BonoPieTest.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace Incoviba\Test\Unit\Service\Venta;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Faker;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class BonoPieTest extends TestCase
|
||||
{
|
||||
public function testAdd(): void
|
||||
{
|
||||
$faker = Faker\factory::create();
|
||||
$fecha = $faker->dateTimeBetween('-1 week');
|
||||
$data = [
|
||||
'fecha' => $fecha->format('Y-m-d'),
|
||||
'valor' => $faker->randomFloat(2, 100, 1000),
|
||||
];
|
||||
|
||||
$uf = $faker->randomFloat(2, 20000, 40000);
|
||||
$pago = new Model\Venta\Pago();
|
||||
$pago->id = $faker->randomNumber();
|
||||
$pago->fecha = $fecha;
|
||||
$pago->valor = $data['valor'] * $uf;
|
||||
$pago->uf = $uf;
|
||||
$bonoPie = new Model\Venta\BonoPie();
|
||||
$bonoPie->valor = $data['valor'];
|
||||
$bonoPie->pago = $pago;
|
||||
|
||||
$logger = $this->getMockBuilder(LoggerInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$bonoPieRepository = $this->getMockBuilder(Repository\Venta\BonoPie::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$bonoPieRepository->method('fetchByPago')->willThrowException(new Implement\Exception\EmptyResult('fetchByPago'));
|
||||
$bonoPieRepository->method('create')->willReturn($bonoPie);
|
||||
$bonoPieRepository->method('save')->willReturnCallback(function($bonoPie) use ($faker) {
|
||||
$bonoPie->id = $faker->randomNumber();
|
||||
return $bonoPie;
|
||||
});
|
||||
$bonoPieRepository->method('filterData')->willReturnCallback(function($data) {
|
||||
return array_intersect_key($data, array_flip(['valor', 'pago']));
|
||||
});
|
||||
$valorService = $this->getMockBuilder(Service\Valor::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$valorService->method('toUF')->willReturn($data['valor']);
|
||||
$ufService = $this->getMockBuilder(Service\UF::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$ufService->method('get')->with($fecha)->willReturn($uf);
|
||||
$pagoService = $this->getMockBuilder(Service\Venta\Pago::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$pagoService->method('add')->willReturn($pago);
|
||||
|
||||
$bonoPieService = new Service\Venta\BonoPie($logger, $bonoPieRepository, $valorService, $ufService, $pagoService);
|
||||
|
||||
$this->assertEquals($bonoPie, $bonoPieService->add($data));
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
139
app/tests/unit/src/Service/Venta/ReservationTest.php
Normal file
139
app/tests/unit/src/Service/Venta/ReservationTest.php
Normal file
@ -0,0 +1,139 @@
|
||||
<?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) and !empty($data['broker_rut'])) {
|
||||
$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->stateRepository->method('fetchByReservation')->willReturnCallback(function($reservation_id) {
|
||||
$state = new Model\Venta\Reservation\State();
|
||||
$state->reservation = new Model\Venta\Reservation();
|
||||
$state->reservation->id = $reservation_id;
|
||||
return $state;
|
||||
});
|
||||
$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->personaService->method('getById')->willReturnCallback(function($id) {
|
||||
$persona = new Model\Persona();
|
||||
$persona->rut = $id;
|
||||
return $persona;
|
||||
});
|
||||
$this->brokerService = $this->getMockBuilder(Service\Proyecto\Broker::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->brokerService->method('get')->willReturnCallback(function($id) {
|
||||
$broker = new Model\Proyecto\Broker();
|
||||
$broker->rut = $id;
|
||||
return $broker;
|
||||
});
|
||||
$this->promotionService = $this->getMockBuilder(Service\Venta\Promotion::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->promotionService->method('getById')->willReturnCallback(function($id) {
|
||||
$promotion = new Model\Venta\Promotion();
|
||||
$promotion->id = $id;
|
||||
return $promotion;
|
||||
});
|
||||
$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->unique()->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, 3);
|
||||
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