develop (#45)
Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl> Reviewed-on: #45
This commit is contained in:
59
app/tests/unit/common/Implement/Log/Handler/MySQLTest.php
Normal file
59
app/tests/unit/common/Implement/Log/Handler/MySQLTest.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Common\Implement\Log\Handler;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use PDO;
|
||||
use PDOStatement;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Monolog;
|
||||
use Faker\Factory;
|
||||
use Incoviba\Common\Implement\Log\Handler\MySQL;
|
||||
use Incoviba\Common\Define;
|
||||
|
||||
class MySQLTest extends TestCase
|
||||
{
|
||||
protected Define\Connection $connection;
|
||||
protected function setUp(): void
|
||||
{
|
||||
$pdo = $this->getMockBuilder(PDO::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$pdo->method('prepare')->willReturn($this->getMockBuilder(PDOStatement::class)->getMock());
|
||||
$this->connection = $this->getMockBuilder(Define\Connection::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->connection->method('getPDO')->willReturn($pdo);
|
||||
}
|
||||
|
||||
public function testWrite(): void
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$context = [];
|
||||
$extra = [];
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$context[$faker->word] = $faker->word;
|
||||
$extra[$faker->word] = $faker->word;
|
||||
}
|
||||
$recordArray = [
|
||||
'message' => 'Test message',
|
||||
'context' => $context,
|
||||
'level' => 100,
|
||||
'level_name' => 'DEBUG',
|
||||
'channel' => $faker->word,
|
||||
'datetime' => DateTimeImmutable::createFromMutable($faker->dateTime()),
|
||||
'extra' => $extra,
|
||||
];
|
||||
$record = new Monolog\LogRecord(
|
||||
$recordArray['datetime'],
|
||||
$recordArray['channel'],
|
||||
Monolog\Level::fromName($recordArray['level_name']),
|
||||
$recordArray['message'],
|
||||
$recordArray['context'],
|
||||
$recordArray['extra']);
|
||||
|
||||
$handler = new MySQL($this->connection);
|
||||
$handler->write($record);
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
17
app/tests/unit/src/Model/ProveedorTest.php
Normal file
17
app/tests/unit/src/Model/ProveedorTest.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Model;
|
||||
|
||||
use Incoviba\Model\Inmobiliaria\Proveedor;
|
||||
use Tests\Extension\AbstractModel;
|
||||
use Tests\Extension\testPropertiesTrait;
|
||||
|
||||
class ProveedorTest extends AbstractModel
|
||||
{
|
||||
use testPropertiesTrait;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->model = new Proveedor();
|
||||
$this->properties = ['rut', 'digito', 'nombre', 'razon', 'contacto'];
|
||||
}
|
||||
}
|
17
app/tests/unit/src/Model/Proyecto/Broker/ContactTest.php
Normal file
17
app/tests/unit/src/Model/Proyecto/Broker/ContactTest.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Model\Proyecto\Broker;
|
||||
|
||||
use Incoviba\Model\Proyecto\Broker\Contact;
|
||||
use Tests\Extension\AbstractModel;
|
||||
use Tests\Extension\testPropertiesTrait;
|
||||
|
||||
class ContactTest extends AbstractModel
|
||||
{
|
||||
use testPropertiesTrait;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->model = new Contact();
|
||||
$this->properties = ['name', 'email', 'phone', 'address'];
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Model\Proyecto\Broker\Contract;
|
||||
|
||||
use Incoviba\Model\Proyecto\Broker\Contract\State;
|
||||
use Tests\Extension\AbstractModel;
|
||||
use Tests\Extension\testPropertiesTrait;
|
||||
|
||||
class StateTest extends AbstractModel
|
||||
{
|
||||
use testPropertiesTrait;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->model = new State();
|
||||
$this->properties = ['contract', 'date', 'type'];
|
||||
}
|
||||
}
|
19
app/tests/unit/src/Model/Proyecto/Broker/ContractTest.php
Normal file
19
app/tests/unit/src/Model/Proyecto/Broker/ContractTest.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Model\Proyecto\Broker;
|
||||
|
||||
use Incoviba\Model\Proyecto\Broker\Contract;
|
||||
use Tests\Extension\AbstractModel;
|
||||
use Tests\Extension\testMethodsTrait;
|
||||
use Tests\Extension\testPropertiesTrait;
|
||||
|
||||
class ContractTest extends AbstractModel
|
||||
{
|
||||
use testPropertiesTrait, testMethodsTrait;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->model = new Contract();
|
||||
$this->properties = ['project', 'broker', 'commission'];
|
||||
$this->methods = ['states', 'current', 'promotions'];
|
||||
}
|
||||
}
|
17
app/tests/unit/src/Model/Proyecto/Broker/DataTest.php
Normal file
17
app/tests/unit/src/Model/Proyecto/Broker/DataTest.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Model\Proyecto\Broker;
|
||||
|
||||
use Incoviba\Model\Proyecto\Broker;
|
||||
use Tests\Extension\AbstractModel;
|
||||
use Tests\Extension\testPropertiesTrait;
|
||||
|
||||
class DataTest extends AbstractModel
|
||||
{
|
||||
use testPropertiesTrait;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->model = new Broker\Data();
|
||||
$this->properties = ['broker', 'representative', 'legalName'];
|
||||
}
|
||||
}
|
19
app/tests/unit/src/Model/Proyecto/BrokerTest.php
Normal file
19
app/tests/unit/src/Model/Proyecto/BrokerTest.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Model\Proyecto;
|
||||
|
||||
use Incoviba\Model\Proyecto\Broker;
|
||||
use Tests\Extension\AbstractModel;
|
||||
use Tests\Extension\testMethodsTrait;
|
||||
use Tests\Extension\testPropertiesTrait;
|
||||
|
||||
class BrokerTest extends AbstractModel
|
||||
{
|
||||
use testPropertiesTrait, testMethodsTrait;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->model = new Broker();
|
||||
$this->properties = ['rut', 'digit', 'name'];
|
||||
$this->methods = ['data', 'contracts'];
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
namespace Test\Unit\Model\Venta\MediosPago\Toku;
|
||||
|
||||
use Faker;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\Extension\ObjectHasMethodTrait;
|
||||
use Incoviba\Model\Persona;
|
||||
use Incoviba\Model\Venta\MediosPago\Toku\Customer;
|
||||
|
||||
class CustomerTest extends TestCase
|
||||
{
|
||||
use ObjectHasMethodTrait;
|
||||
|
||||
public static function dataProperties(): array
|
||||
{
|
||||
return [
|
||||
['id'],
|
||||
['persona'],
|
||||
['toku_id']
|
||||
];
|
||||
}
|
||||
#[DataProvider('dataProperties')]
|
||||
public function testProperties(string $propertyName): void
|
||||
{
|
||||
$customer = new Customer();
|
||||
|
||||
$this->assertObjectHasProperty($propertyName, $customer);
|
||||
}
|
||||
|
||||
public static function dataMethods(): array
|
||||
{
|
||||
return [
|
||||
['rut']
|
||||
];
|
||||
}
|
||||
#[DataProvider('dataMethods')]
|
||||
public function testMethods(string $methodName): void
|
||||
{
|
||||
$customer = new Customer();
|
||||
|
||||
$this->assertObjectHasMethod($methodName, $customer);
|
||||
}
|
||||
|
||||
public function testJson(): void
|
||||
{
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
$persona = $this->getMockBuilder(Persona::class)->disableOriginalConstructor()->getMock();
|
||||
$persona->rut = $faker->randomNumber(8);
|
||||
$persona->digito = 'k';
|
||||
|
||||
$toku_id = $faker->ean13();
|
||||
|
||||
$id = $faker->randomNumber(4);
|
||||
|
||||
$customer = new Customer();
|
||||
$customer->id = $id;
|
||||
$customer->persona = $persona;
|
||||
$customer->toku_id = $toku_id;
|
||||
|
||||
$expected = json_encode([
|
||||
'id' => $id,
|
||||
'rut' => implode('', [$persona->rut, strtoupper($persona->digito)]),
|
||||
'toku_id' => $toku_id
|
||||
]);
|
||||
$this->assertJsonStringEqualsJsonString($expected, json_encode($customer));
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Model\Venta\MediosPago\Toku;
|
||||
|
||||
use Faker;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Incoviba\Model;
|
||||
|
||||
class InvoiceTest extends TestCase
|
||||
{
|
||||
public static function dataProperties(): array
|
||||
{
|
||||
return [
|
||||
['id'],
|
||||
['cuota'],
|
||||
['toku_id'],
|
||||
];
|
||||
}
|
||||
#[DataProvider('dataProperties')]
|
||||
public function testProperties(string $propertyName): void
|
||||
{
|
||||
$invoice = new Model\Venta\MediosPago\Toku\Invoice();
|
||||
$this->assertObjectHasProperty($propertyName, $invoice);
|
||||
}
|
||||
|
||||
public function testJson(): void
|
||||
{
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
$cuota = $this->getMockBuilder(Model\Venta\Cuota::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$cuota->id = $faker->randomNumber();
|
||||
|
||||
$toku_id = $faker->ean13();
|
||||
|
||||
$id = $faker->randomNumber();
|
||||
|
||||
$invoice = new Model\Venta\MediosPago\Toku\Invoice();
|
||||
$invoice->id = $id;
|
||||
$invoice->cuota = $cuota;
|
||||
$invoice->toku_id = $toku_id;
|
||||
|
||||
$expected = json_encode([
|
||||
'id' => $id,
|
||||
'cuota_id' => $cuota->id,
|
||||
'toku_id' => $toku_id,
|
||||
]);
|
||||
$this->assertEquals($expected, json_encode($invoice));
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Model\Venta\MediosPago\Toku;
|
||||
|
||||
use Faker;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Incoviba\Model;
|
||||
|
||||
class SubscriptionTest extends TestCase
|
||||
{
|
||||
public static function dataProperties(): array
|
||||
{
|
||||
return [
|
||||
['id'],
|
||||
['venta'],
|
||||
['toku_id'],
|
||||
];
|
||||
}
|
||||
#[DataProvider('dataProperties')]
|
||||
public function testProperties(string $propertyName): void
|
||||
{
|
||||
$subscription = new Model\Venta\MediosPago\Toku\Subscription();
|
||||
$this->assertObjectHasProperty($propertyName, $subscription);
|
||||
}
|
||||
|
||||
public function testJson(): void
|
||||
{
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
$venta = $this->getMockBuilder(Model\Venta::class)->disableOriginalConstructor()->getMock();
|
||||
$venta->id = $faker->randomNumber();
|
||||
|
||||
$toku_id = $faker->ean13();
|
||||
|
||||
$id = $faker->randomNumber();
|
||||
|
||||
$subscription = new Model\Venta\MediosPago\Toku\Subscription();
|
||||
$subscription->id = $id;
|
||||
$subscription->venta = $venta;
|
||||
$subscription->toku_id = $toku_id;
|
||||
|
||||
$expected = json_encode([
|
||||
'id' => $id,
|
||||
'venta_id' => $venta->id,
|
||||
'toku_id' => $toku_id,
|
||||
]);
|
||||
$this->assertEquals($expected, json_encode($subscription));
|
||||
}
|
||||
}
|
19
app/tests/unit/src/Model/Venta/PromotionTest.php
Normal file
19
app/tests/unit/src/Model/Venta/PromotionTest.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Model\Venta;
|
||||
|
||||
use Incoviba\Model\Venta\Promotion;
|
||||
use Tests\Extension\AbstractModel;
|
||||
use Tests\Extension\testMethodsTrait;
|
||||
use Tests\Extension\testPropertiesTrait;
|
||||
|
||||
class PromotionTest extends AbstractModel
|
||||
{
|
||||
use testPropertiesTrait, testMethodsTrait;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->model = new Promotion();
|
||||
$this->properties = ['description', 'amount', 'startDate', 'endDate', 'validUntil', 'type', 'state'];
|
||||
$this->methods = ['projects', 'brokers', 'unitTypes', 'unitLines', 'units', 'value'];
|
||||
}
|
||||
}
|
17
app/tests/unit/src/Model/Venta/Reservation/StateTest.php
Normal file
17
app/tests/unit/src/Model/Venta/Reservation/StateTest.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Model\Venta\Reservation;
|
||||
|
||||
use Incoviba\Model\Venta\Reservation\State;
|
||||
use Tests\Extension\AbstractModel;
|
||||
use Tests\Extension\testPropertiesTrait;
|
||||
|
||||
class StateTest extends AbstractModel
|
||||
{
|
||||
use testPropertiesTrait;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->model = new State();
|
||||
$this->properties = ['reservation', 'date', 'type'];
|
||||
}
|
||||
}
|
19
app/tests/unit/src/Model/Venta/ReservationTest.php
Normal file
19
app/tests/unit/src/Model/Venta/ReservationTest.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Model\Venta;
|
||||
|
||||
use Incoviba\Model\Venta\Reservation;
|
||||
use Tests\Extension\AbstractModel;
|
||||
use Tests\Extension\testMethodsTrait;
|
||||
use Tests\Extension\testPropertiesTrait;
|
||||
|
||||
class ReservationTest extends AbstractModel
|
||||
{
|
||||
use testPropertiesTrait, testMethodsTrait;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->model = new Reservation();
|
||||
$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);
|
||||
}
|
||||
}
|
@ -0,0 +1,139 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Repository\Venta\MediosPago\Toku;
|
||||
|
||||
use Faker;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use PDO;
|
||||
use PHPUnit\Framework\Attributes\Depends;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CustomerTest extends TestCase
|
||||
{
|
||||
protected PDO $pdo;
|
||||
protected Define\Connection $connection;
|
||||
protected Model\Persona $persona;
|
||||
protected Service\Persona $personaService;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$dsn = "mysql:host={$_ENV['DB_HOST']};dbname={$_ENV['DB_DATABASE']}";
|
||||
$this->pdo = new PDO($dsn, $_ENV['DB_USER'], $_ENV['DB_PASSWORD']);
|
||||
|
||||
$this->connection = $this->getMockBuilder(Define\Connection::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->connection->method('getPDO')->willReturn($this->pdo);
|
||||
|
||||
$faker = Faker\Factory::create();
|
||||
$datos = $this->getMockBuilder(Model\Persona\Datos::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$datos->email = $faker->email();
|
||||
$datos->telefono = $faker->randomNumber(9);
|
||||
|
||||
$this->persona = $this->getMockBuilder(Model\Persona::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->persona->rut = $faker->randomNumber(8);
|
||||
$digit = $faker->numberBetween(0, 11);
|
||||
$this->persona->digito = $digit === 11 ? 'k' : $digit;
|
||||
$this->persona->method('datos')->willReturn($datos);
|
||||
|
||||
$this->personaService = $this->getMockBuilder(Service\Persona::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->personaService->method('getById')->willReturn($this->persona);
|
||||
}
|
||||
|
||||
public function testCreate(): void
|
||||
{
|
||||
$repository = new Repository\Venta\MediosPago\Toku\Customer($this->connection, $this->personaService);
|
||||
|
||||
$faker = Faker\Factory::create();
|
||||
$data = [
|
||||
'rut' => implode('', [$this->persona->rut, $this->persona->digito]),
|
||||
'toku_id' => $faker->iban(),
|
||||
];
|
||||
|
||||
$customer = $repository->create($data);
|
||||
$this->assertEquals($this->persona, $customer->persona);
|
||||
$this->assertEquals($data['toku_id'], $customer->toku_id);
|
||||
}
|
||||
public function testSave(): Model\Venta\MediosPago\Toku\Customer
|
||||
{
|
||||
$repository = new Repository\Venta\MediosPago\Toku\Customer($this->connection, $this->personaService);
|
||||
|
||||
$faker = Faker\Factory::create();
|
||||
$data = [
|
||||
'rut' => implode('', [$this->persona->rut, $this->persona->digito]),
|
||||
'toku_id' => $faker->iban(),
|
||||
];
|
||||
$customer = $repository->create($data);
|
||||
$customer = $repository->save($customer);
|
||||
$this->assertNotNull($customer->id);
|
||||
$this->assertEquals($this->persona, $customer->persona);
|
||||
$this->assertEquals($data['toku_id'], $customer->toku_id);
|
||||
|
||||
return $customer;
|
||||
}
|
||||
#[Depends('testSave')]
|
||||
public function testFetch(Model\Venta\MediosPago\Toku\Customer $reference): void
|
||||
{
|
||||
$result = [
|
||||
'id' => $reference->id,
|
||||
'rut' => implode('', [$this->persona->rut, $this->persona->digito]),
|
||||
'toku_id' => $reference->toku_id,
|
||||
];
|
||||
$resultSet = $this->getMockBuilder(\PDOStatement::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$resultSet->method('fetch')->willReturn($result);
|
||||
$this->connection->method('execute')->willReturn($resultSet);
|
||||
|
||||
$repository = new Repository\Venta\MediosPago\Toku\Customer($this->connection, $this->personaService);
|
||||
|
||||
$customer = $repository->fetchById($reference->id);
|
||||
$this->assertInstanceOf(Model\Venta\MediosPago\Toku\Customer::class, $customer);
|
||||
$this->assertEquals($reference->id, $customer->id);
|
||||
$this->assertEquals($this->persona, $customer->persona);
|
||||
$this->assertEquals($reference->toku_id, $customer->toku_id);
|
||||
}
|
||||
#[Depends('testSave')]
|
||||
public function testFetchByRut(Model\Venta\MediosPago\Toku\Customer $reference): void
|
||||
{
|
||||
$result = [
|
||||
'id' => $reference->id,
|
||||
'rut' => implode('', [$this->persona->rut, $this->persona->digito]),
|
||||
'toku_id' => $reference->toku_id,
|
||||
];
|
||||
$resultSet = $this->getMockBuilder(\PDOStatement::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$resultSet->method('fetch')->willReturn($result);
|
||||
$this->connection->method('execute')->willReturn($resultSet);
|
||||
|
||||
$repository = new Repository\Venta\MediosPago\Toku\Customer($this->connection, $this->personaService);
|
||||
|
||||
$customer = $repository->fetchByRut($this->persona->rut);
|
||||
$this->assertEquals($reference->id, $customer->id);
|
||||
$this->assertEquals($this->persona, $customer->persona);
|
||||
$this->assertEquals($reference->toku_id, $customer->toku_id);
|
||||
}
|
||||
#[Depends('testSave')]
|
||||
public function testFetchByTokuId(Model\Venta\MediosPago\Toku\Customer $reference): void
|
||||
{
|
||||
$result = [
|
||||
'id' => $reference->id,
|
||||
'rut' => implode('', [$this->persona->rut, $this->persona->digito]),
|
||||
'toku_id' => $reference->toku_id,
|
||||
];
|
||||
$resultSet = $this->getMockBuilder(\PDOStatement::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$resultSet->method('fetch')->willReturn($result);
|
||||
$this->connection->method('execute')->willReturn($resultSet);
|
||||
$repository = new Repository\Venta\MediosPago\Toku\Customer($this->connection, $this->personaService);
|
||||
|
||||
$customer = $repository->fetchByTokuId($reference->toku_id);
|
||||
$this->assertEquals($reference->id, $customer->id);
|
||||
$this->assertEquals($this->persona, $customer->persona);
|
||||
$this->assertEquals($reference->toku_id, $customer->toku_id);
|
||||
}
|
||||
}
|
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Repository\Venta\MediosPago\Toku;
|
||||
|
||||
use Faker;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use PDO;
|
||||
use PHPUnit\Framework\Attributes\Depends;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class InvoiceTest extends TestCase
|
||||
{
|
||||
protected Define\Connection $connection;
|
||||
protected PDO $pdo;
|
||||
protected Model\Venta\Cuota $cuota;
|
||||
protected Repository\Venta\Cuota $cuotaRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$dsn = "mysql:host={$_ENV['DB_HOST']};dbname={$_ENV['DB_DATABASE']}";
|
||||
$this->pdo = new PDO($dsn, $_ENV['DB_USER'], $_ENV['DB_PASSWORD']);
|
||||
|
||||
$this->connection = $this->getMockBuilder(Define\Connection::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->connection->method('getPDO')->willReturn($this->pdo);
|
||||
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
$this->cuota = $this->getMockBuilder(Model\Venta\Cuota::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->cuota->id = $faker->randomNumber();
|
||||
|
||||
$this->cuotaRepository = $this->getMockBuilder(Repository\Venta\Cuota::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->cuotaRepository->method('fetchById')->willReturn($this->cuota);
|
||||
}
|
||||
|
||||
public function testCreate(): void
|
||||
{
|
||||
$repository = new Repository\Venta\MediosPago\Toku\Invoice($this->connection, $this->cuotaRepository);
|
||||
|
||||
$faker = Faker\Factory::create();
|
||||
$data = [
|
||||
'cuota_id' => $this->cuota->id,
|
||||
'toku_id' => $faker->ean13(),
|
||||
];
|
||||
|
||||
$invoice = $repository->create($data);
|
||||
|
||||
$this->assertEquals($this->cuota->id, $invoice->cuota->id);
|
||||
$this->assertEquals($data['toku_id'], $invoice->toku_id);
|
||||
}
|
||||
public function testSave(): Model\Venta\MediosPago\Toku\Invoice
|
||||
{
|
||||
$repository = new Repository\Venta\MediosPago\Toku\Invoice($this->connection, $this->cuotaRepository);
|
||||
|
||||
$faker = Faker\Factory::create();
|
||||
$data = [
|
||||
'cuota_id' => $this->cuota->id,
|
||||
'toku_id' => $faker->ean13(),
|
||||
];
|
||||
|
||||
$invoice = $repository->create($data);
|
||||
$invoice = $repository->save($invoice);
|
||||
$this->assertNotNull($invoice->id);
|
||||
$this->assertEquals($this->cuota->id, $invoice->cuota->id);
|
||||
$this->assertEquals($data['toku_id'], $invoice->toku_id);
|
||||
|
||||
return $invoice;
|
||||
}
|
||||
#[Depends('testSave')]
|
||||
public function testFetch(Model\Venta\MediosPago\Toku\Invoice $reference): void
|
||||
{
|
||||
$result = [
|
||||
'id' => $reference->id,
|
||||
'cuota_id' => $this->cuota->id,
|
||||
'toku_id' => $reference->toku_id,
|
||||
];
|
||||
$resultSet = $this->getMockBuilder(\PDOStatement::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$resultSet->method('fetch')->willReturn($result);
|
||||
$this->connection->method('execute')->willReturn($resultSet);
|
||||
|
||||
$repository = new Repository\Venta\MediosPago\Toku\Invoice($this->connection, $this->cuotaRepository);
|
||||
|
||||
$invoice = $repository->fetchById($reference->id);
|
||||
$this->assertInstanceOf(Model\Venta\MediosPago\Toku\Invoice::class, $invoice);
|
||||
$this->assertEquals($reference->id, $invoice->id);
|
||||
$this->assertEquals($this->cuota->id, $invoice->cuota->id);
|
||||
$this->assertEquals($reference->toku_id, $invoice->toku_id);
|
||||
}
|
||||
#[Depends('testSave')]
|
||||
public function testFetchByCuota(Model\Venta\MediosPago\Toku\Invoice $reference): void
|
||||
{
|
||||
$result = [
|
||||
'id' => $reference->id,
|
||||
'cuota_id' => $this->cuota->id,
|
||||
'toku_id' => $reference->toku_id,
|
||||
];
|
||||
$resultSet = $this->getMockBuilder(\PDOStatement::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$resultSet->method('fetch')->willReturn($result);
|
||||
$this->connection->method('execute')->willReturn($resultSet);
|
||||
|
||||
$repository = new Repository\Venta\MediosPago\Toku\Invoice($this->connection, $this->cuotaRepository);
|
||||
|
||||
$invoice = $repository->fetchByCuota($this->cuota->id);
|
||||
$this->assertEquals($reference->id, $invoice->id);
|
||||
$this->assertEquals($this->cuota->id, $invoice->cuota->id);
|
||||
$this->assertEquals($reference->toku_id, $invoice->toku_id);
|
||||
}
|
||||
#[Depends('testSave')]
|
||||
public function testFetchByTokuId(Model\Venta\MediosPago\Toku\Invoice $reference): void
|
||||
{
|
||||
$result = [
|
||||
'id' => $reference->id,
|
||||
'cuota_id' => $this->cuota->id,
|
||||
'toku_id' => $reference->toku_id,
|
||||
];
|
||||
$resultSet = $this->getMockBuilder(\PDOStatement::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$resultSet->method('fetch')->willReturn($result);
|
||||
$this->connection->method('execute')->willReturn($resultSet);
|
||||
|
||||
$repository = new Repository\Venta\MediosPago\Toku\Invoice($this->connection, $this->cuotaRepository);
|
||||
|
||||
$invoice = $repository->fetchByTokuId($reference->toku_id);
|
||||
$this->assertEquals($reference->id, $invoice->id);
|
||||
$this->assertEquals($this->cuota->id, $invoice->cuota->id);
|
||||
$this->assertEquals($reference->toku_id, $invoice->toku_id);
|
||||
}
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Repository\Venta\MediosPago\Toku;
|
||||
|
||||
use Faker;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use PDO;
|
||||
use PHPUnit\Framework\Attributes\Depends;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SubscriptionTest extends TestCase
|
||||
{
|
||||
protected PDO $pdo;
|
||||
protected Define\Connection $connection;
|
||||
protected Model\Venta $venta;
|
||||
protected Repository\Venta $ventaRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$dsn = "mysql:host={$_ENV['DB_HOST']};dbname={$_ENV['DB_DATABASE']}";
|
||||
$this->pdo = new PDO($dsn, $_ENV['DB_USER'], $_ENV['DB_PASSWORD']);
|
||||
|
||||
$this->connection = $this->getMockBuilder(Define\Connection::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->connection->method('getPDO')->willReturn($this->pdo);
|
||||
|
||||
$faker = Faker\Factory::create();
|
||||
$this->venta = $this->getMockBuilder(Model\Venta::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->venta->id = $faker->randomNumber();
|
||||
|
||||
$this->ventaRepository = $this->getMockBuilder(Repository\Venta::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->ventaRepository->method('fetchById')->willReturn($this->venta);
|
||||
}
|
||||
|
||||
public function testCreate(): void
|
||||
{
|
||||
$repository = new Repository\Venta\MediosPago\Toku\Subscription($this->connection, $this->ventaRepository);
|
||||
|
||||
$faker = Faker\Factory::create();
|
||||
$data = [
|
||||
'venta_id' => $this->venta->id,
|
||||
'toku_id' => $faker->ean13(),
|
||||
];
|
||||
|
||||
$subscription = $repository->create($data);
|
||||
$this->assertEquals($this->venta->id, $subscription->venta->id);
|
||||
$this->assertEquals($data['toku_id'], $subscription->toku_id);
|
||||
}
|
||||
public function testSave(): Model\Venta\MediosPago\Toku\Subscription
|
||||
{
|
||||
$repository = new Repository\Venta\MediosPago\Toku\Subscription($this->connection, $this->ventaRepository);
|
||||
|
||||
$faker = Faker\Factory::create();
|
||||
$data = [
|
||||
'venta_id' => $this->venta->id,
|
||||
'toku_id' => $faker->ean13(),
|
||||
];
|
||||
|
||||
$subscription = $repository->create($data);
|
||||
$subscription = $repository->save($subscription);
|
||||
$this->assertNotNull($subscription->id);
|
||||
$this->assertEquals($this->venta->id, $subscription->venta->id);
|
||||
$this->assertEquals($data['toku_id'], $subscription->toku_id);
|
||||
|
||||
return $subscription;
|
||||
}
|
||||
#[Depends('testSave')]
|
||||
public function testFetch(Model\Venta\MediosPago\Toku\Subscription $reference): void
|
||||
{
|
||||
$result = [
|
||||
'id' => $reference->id,
|
||||
'venta_id' => $this->venta->id,
|
||||
'toku_id' => $reference->toku_id,
|
||||
];
|
||||
|
||||
$resultSet = $this->getMockBuilder(\PDOStatement::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$resultSet->method('fetch')->willReturn($result);
|
||||
$this->connection->method('execute')->willReturn($resultSet);
|
||||
|
||||
$repository = new Repository\Venta\MediosPago\Toku\Subscription($this->connection, $this->ventaRepository);
|
||||
$subscription = $repository->fetchById($reference->id);
|
||||
$this->assertInstanceOf(Model\Venta\MediosPago\Toku\Subscription::class, $subscription);
|
||||
$this->assertEquals($reference->id, $subscription->id);
|
||||
$this->assertEquals($this->venta->id, $subscription->venta->id);
|
||||
$this->assertEquals($reference->toku_id, $subscription->toku_id);
|
||||
}
|
||||
#[Depends('testSave')]
|
||||
public function testFetchByVenta(Model\Venta\MediosPago\Toku\Subscription $reference): void
|
||||
{
|
||||
$result = [
|
||||
'id' => $reference->id,
|
||||
'venta_id' => $this->venta->id,
|
||||
'toku_id' => $reference->toku_id,
|
||||
];
|
||||
|
||||
$resultSet = $this->getMockBuilder(\PDOStatement::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$resultSet->method('fetch')->willReturn($result);
|
||||
$this->connection->method('execute')->willReturn($resultSet);
|
||||
|
||||
$repository = new Repository\Venta\MediosPago\Toku\Subscription($this->connection, $this->ventaRepository);
|
||||
$subscription = $repository->fetchByVenta($this->venta->id);
|
||||
$this->assertEquals($reference->id, $subscription->id);
|
||||
$this->assertEquals($this->venta->id, $subscription->venta->id);
|
||||
$this->assertEquals($reference->toku_id, $subscription->toku_id);
|
||||
}
|
||||
#[Depends('testSave')]
|
||||
public function testFetchByTokuId(Model\Venta\MediosPago\Toku\Subscription $reference): void
|
||||
{
|
||||
$result = [
|
||||
'id' => $reference->id,
|
||||
'venta_id' => $this->venta->id,
|
||||
'toku_id' => $reference->toku_id,
|
||||
];
|
||||
|
||||
$resultSet = $this->getMockBuilder(\PDOStatement::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$resultSet->method('fetch')->willReturn($result);
|
||||
$this->connection->method('execute')->willReturn($resultSet);
|
||||
|
||||
$repository = new Repository\Venta\MediosPago\Toku\Subscription($this->connection, $this->ventaRepository);
|
||||
$subscription = $repository->fetchByTokuId($reference->toku_id);
|
||||
$this->assertEquals($reference->id, $subscription->id);
|
||||
$this->assertEquals($this->venta->id, $subscription->venta->id);
|
||||
$this->assertEquals($reference->toku_id, $subscription->toku_id);
|
||||
}
|
||||
}
|
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);
|
||||
}
|
||||
}
|
101
app/tests/unit/src/Service/MQTT/BeanstalkdTest.php
Normal file
101
app/tests/unit/src/Service/MQTT/BeanstalkdTest.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
namespace Incoviba\Test\Service\MQTT;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use xobotyi\beansclient\BeansClient;
|
||||
use xobotyi\beansclient\Connection;
|
||||
use xobotyi\beansclient\Exception\JobException;
|
||||
use xobotyi\beansclient\Job;
|
||||
use Incoviba\Exception\MQTT\MissingJob;
|
||||
use Incoviba\Service\MQTT\Beanstalkd;
|
||||
|
||||
class BeanstalkdTest extends TestCase
|
||||
{
|
||||
protected LoggerInterface $logger;
|
||||
protected BeansClient $client;
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
|
||||
$this->client = $this->getMockBuilder(BeansClient::class)->disableOriginalConstructor()->getMock();
|
||||
}
|
||||
|
||||
public function testExists(): void
|
||||
{
|
||||
$stats = ['current-jobs-ready' => 1];
|
||||
$this->client->method('watchTube')->willReturn($this->client);
|
||||
$this->client->method('statsTube')->willReturn($stats);
|
||||
$service = new Beanstalkd($this->logger, $this->client);
|
||||
$this->assertTrue($service->exists());
|
||||
}
|
||||
public function testNotExists(): void
|
||||
{
|
||||
$stats = ['current-jobs-ready' => 0];
|
||||
$this->client->method('watchTube')->willReturn($this->client);
|
||||
$this->client->method('statsTube')->willReturn($stats);
|
||||
$service = new Beanstalkd($this->logger, $this->client);
|
||||
$this->assertFalse($service->exists());
|
||||
}
|
||||
public function testGet(): void
|
||||
{
|
||||
$jobData = [
|
||||
'id' => 1,
|
||||
'configuration' => [
|
||||
'type' => 'service',
|
||||
],
|
||||
'created_at' => '2020-01-01 00:00:00',
|
||||
];
|
||||
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
|
||||
$connection->method('isActive')->willReturn(true);
|
||||
$this->client->method('getConnection')->willReturn($connection);
|
||||
$this->client->method('watchTube')->willReturn($this->client);
|
||||
$this->client->method('statsTube')->willReturn(['current-jobs-ready' => 1]);
|
||||
$job = new Job($this->client, 1, 'ready', json_encode($jobData));
|
||||
$this->client->method('reserve')->willReturn($job);
|
||||
$service = new Beanstalkd($this->logger, $this->client);
|
||||
$this->assertEquals(json_encode($jobData), $service->get());
|
||||
}
|
||||
public function testGetException(): void
|
||||
{
|
||||
$this->client->method('watchTube')->willReturn($this->client);
|
||||
$this->client->method('statsTube')->willReturn(['current-jobs-ready' => 0]);
|
||||
$service = new Beanstalkd($this->logger, $this->client);
|
||||
$this->expectException(MissingJob::class);
|
||||
$service->get();
|
||||
|
||||
$this->client->method('statsTube')->willReturn(['current-jobs-ready' => 1]);
|
||||
$exception = new JobException();
|
||||
$this->client->method('reserve')->willThrowException($exception);
|
||||
$this->expectException(MissingJob::class);
|
||||
$service->get();
|
||||
}
|
||||
public function testSet(): void
|
||||
{
|
||||
$this->client->method('useTube')->willReturn($this->client);
|
||||
$this->client->method('put');
|
||||
$service = new Beanstalkd($this->logger, $this->client);
|
||||
$service->set('test');
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
public function testSetException(): void
|
||||
{
|
||||
$this->client->method('useTube')->willReturn($this->client);
|
||||
$exception = new JobException();
|
||||
$this->client->method('put')->willThrowException($exception);
|
||||
$service = new Beanstalkd($this->logger, $this->client);
|
||||
$service->set('test');
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
public function testRemove(): void
|
||||
{
|
||||
$this->client->method('useTube')->willReturn($this->client);
|
||||
$this->client->method('delete')->willReturn(true);
|
||||
$service = new Beanstalkd($this->logger, $this->client);
|
||||
$service->remove(1);
|
||||
$this->assertTrue(true);
|
||||
|
||||
$this->client->method('delete')->willReturn(false);
|
||||
$service->remove(1);
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
69
app/tests/unit/src/Service/MQTTTest.php
Normal file
69
app/tests/unit/src/Service/MQTTTest.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
namespace Incoviba\Test\Service;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use xobotyi\beansclient\BeansClient;
|
||||
use Incoviba\Exception\MQTT\MissingClient;
|
||||
use Incoviba\Service\MQTT;
|
||||
use Incoviba\Service\MQTT\Beanstalkd;
|
||||
|
||||
class MQTTTest extends TestCase
|
||||
{
|
||||
public function testRegisterAndClientExistsAndGet(): void
|
||||
{
|
||||
$mqtt = new MQTT();
|
||||
$beanstalkd = $this->getMockBuilder(Beanstalkd::class)->disableOriginalConstructor()->getMock();
|
||||
$mqtt->register('beanstalkd', $beanstalkd);
|
||||
$this->assertTrue($mqtt->clientExists('beanstalkd'));
|
||||
}
|
||||
public function testGetClient(): void
|
||||
{
|
||||
$mqtt = new MQTT();
|
||||
$logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
|
||||
$client = $this->getMockBuilder(BeansClient::class)->disableOriginalConstructor()->getMock();
|
||||
$beanstalkd = new Beanstalkd($logger, $client);
|
||||
$mqtt->register('beanstalkd', $beanstalkd);
|
||||
$this->assertEquals($beanstalkd, $mqtt->getClient('beanstalkd'));
|
||||
}
|
||||
public function testGetClientException(): void
|
||||
{
|
||||
$mqtt = new MQTT();
|
||||
$this->expectException(MissingClient::class);
|
||||
$mqtt->getClient('test');
|
||||
}
|
||||
public function testExists(): void
|
||||
{
|
||||
$mqtt = new MQTT();
|
||||
$beanstalkd = $this->getMockBuilder(Beanstalkd::class)->disableOriginalConstructor()->getMock();
|
||||
$beanstalkd->method('exists')->willReturn(true);
|
||||
$mqtt->register('beanstalkd', $beanstalkd);
|
||||
$this->assertTrue($mqtt->exists('beanstalkd'));
|
||||
}
|
||||
public function testGet(): void
|
||||
{
|
||||
$mqtt = new MQTT();
|
||||
$beanstalkd = $this->getMockBuilder(Beanstalkd::class)->disableOriginalConstructor()->getMock();
|
||||
$beanstalkd->method('get')->willReturn('test');
|
||||
$mqtt->register('beanstalkd', $beanstalkd);
|
||||
$this->assertEquals('test', $mqtt->get('beanstalkd'));
|
||||
}
|
||||
public function testSet(): void
|
||||
{
|
||||
$mqtt = new MQTT();
|
||||
$beanstalkd = $this->getMockBuilder(Beanstalkd::class)->disableOriginalConstructor()->getMock();
|
||||
$beanstalkd->method('set');
|
||||
$mqtt->register('beanstalkd', $beanstalkd);
|
||||
$mqtt->set('test', 0, 'beanstalkd');
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
public function testRemove(): void
|
||||
{
|
||||
$mqtt = new MQTT();
|
||||
$beanstalkd = $this->getMockBuilder(Beanstalkd::class)->disableOriginalConstructor()->getMock();
|
||||
$beanstalkd->method('remove');
|
||||
$mqtt->register('beanstalkd', $beanstalkd);
|
||||
$mqtt->remove(0, 'beanstalkd');
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
66
app/tests/unit/src/Service/Money/SIITest.php
Normal file
66
app/tests/unit/src/Service/Money/SIITest.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Service\Money;
|
||||
|
||||
use PDO;
|
||||
use PDOStatement;
|
||||
use GuzzleHttp\Client;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Common\Define;
|
||||
|
||||
class SIITest extends TestCase
|
||||
{
|
||||
protected Client $client;
|
||||
protected Service\UF $ufService;
|
||||
protected Service\Valor $valorService;
|
||||
protected \PDO $pdo;
|
||||
protected Define\Connection $connection;
|
||||
protected \PDOStatement $statement;
|
||||
protected Repository\UF $ufRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->client = new Client(['base_uri' => 'https://www.sii.cl/valores_y_fechas/']);
|
||||
|
||||
$this->pdo = $this->getMockBuilder(PDO::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->pdo->method('beginTransaction')->willReturn(true);
|
||||
$this->pdo->method('commit')->willReturn(true);
|
||||
#$this->pdo->method('rollBack')->willReturn(null);
|
||||
|
||||
$this->statement = $this->getMockBuilder(PDOStatement::class)->getMock();
|
||||
$this->statement->method('fetchAll')->willReturn([]);
|
||||
|
||||
$this->connection = $this->getMockBuilder(Define\Connection::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->connection->method('getPDO')->willReturn($this->pdo);
|
||||
$this->connection->method('query')->willReturn($this->statement);
|
||||
$this->connection->method('execute')->willReturn($this->statement);
|
||||
|
||||
$this->ufRepository = $this->getMockBuilder(Repository\UF::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->ufRepository->method('getConnection')->willReturn($this->connection);
|
||||
$this->ufRepository->method('getTable')->willReturn('uf');
|
||||
}
|
||||
|
||||
public function testGet(): void
|
||||
{
|
||||
$provider = new Service\Money\SII($this->client, $this->ufRepository);
|
||||
|
||||
$date = new \DateTimeImmutable('2025-05-05');
|
||||
$expected = 39107.9;
|
||||
|
||||
$this->assertEquals($expected, $provider->get(Service\Money::UF, $date));
|
||||
}
|
||||
public function testGetNoValid(): void
|
||||
{
|
||||
$provider = new Service\Money\SII($this->client, $this->ufRepository);
|
||||
|
||||
$date = (new \DateTimeImmutable())->add(new \DateInterval("P1Y"));
|
||||
|
||||
$this->expectException(EmptyResponse::class);
|
||||
$provider->get(Service\Money::UF, $date);
|
||||
}
|
||||
}
|
124
app/tests/unit/src/Service/PersonaTest.php
Normal file
124
app/tests/unit/src/Service/PersonaTest.php
Normal file
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
namespace Incoviba\Test\Service;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Faker;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use Tests\Extension\Faker\Provider\Rut;
|
||||
|
||||
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');
|
||||
$faker->addProvider(new Rut($faker));
|
||||
$rut = $faker->rut(false, false);
|
||||
$data = [
|
||||
'rut' => $rut,
|
||||
'digito' => $faker->digitoVerificador($rut),
|
||||
'nombres' => $faker->name(),
|
||||
'apellido_paterno' => $faker->lastName(),
|
||||
'apellido_materno' => $faker->lastName(),
|
||||
];
|
||||
$persona = $personaService->add($data);
|
||||
$this->assertEquals($data['rut'], $persona->rut);
|
||||
}
|
||||
public function testGetById(): void
|
||||
{
|
||||
$faker = Faker\Factory::create('es_ES');
|
||||
$faker->addProvider(new Rut($faker));
|
||||
$direccion = $this->getMockBuilder(Model\Direccion::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$direccion->id = $faker->randomNumber(2);
|
||||
$datos = new Model\Venta\Datos();
|
||||
$datos->direccion = $direccion;
|
||||
$datos->telefono = $faker->randomNumber(8);
|
||||
$datos->email = $faker->email();
|
||||
$datos->sexo = $faker->randomElement(['M', 'F']);
|
||||
$rut = $faker->rut(false, false);
|
||||
$propietario = new Model\Venta\Propietario();
|
||||
$propietario->rut = $rut;
|
||||
$propietario->dv = $faker->digitoVerificador($rut);
|
||||
$propietario->nombres = $faker->name();
|
||||
$propietario->apellidos['paterno'] = $faker->lastName();
|
||||
$propietario->apellidos['materno'] = $faker->lastName();
|
||||
$propietario->datos = $datos;
|
||||
$propietarioRepository = $this->getMockBuilder(Repository\Venta\Propietario::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$personaRepository = $this->getMockBuilder(Repository\Persona::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$personaRepository->method('fetchById')->willThrowException(new Implement\Exception\EmptyResult(''));
|
||||
$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;
|
||||
});
|
||||
$personaRepository->method('save')->willReturnArgument(0);
|
||||
$datosPersona = new Model\Persona\Datos();
|
||||
$datosPersona->direccion = $direccion;
|
||||
$datosPersona->telefono = $datos->telefono;
|
||||
$datosPersona->email = $datos->email;
|
||||
$datosPersona->sexo = $datos->sexo;
|
||||
$datosPersonaRepository = $this->getMockBuilder(Repository\Persona\Datos::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$datosPersonaRepository->method('fetchByPersona')->willReturn($datosPersona);
|
||||
$propietarioRepository->method('fetchById')->willReturn($propietario);
|
||||
$direccionService = $this->getMockBuilder(Service\Direccion::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$direccionService->method('add')->willReturn($direccion);
|
||||
$personaService = new Service\Persona($this->logger, $personaRepository, $datosPersonaRepository,
|
||||
$propietarioRepository, $direccionService);
|
||||
$persona = $personaService->getById($rut);
|
||||
$this->assertEquals($rut, $persona->rut);
|
||||
$this->assertEquals($propietario->dv, $persona->digito);
|
||||
$this->assertEquals($propietario->nombres, $persona->nombres);
|
||||
$this->assertEquals($propietario->apellidos['paterno'], $persona->apellidoPaterno);
|
||||
$this->assertEquals($propietario->apellidos['materno'], $persona->apellidoMaterno);
|
||||
$this->assertEquals($datos->direccion, $persona->datos->direccion);
|
||||
$this->assertEquals($datos->telefono, $persona->datos->telefono);
|
||||
$this->assertEquals($datos->email, $persona->datos->email);
|
||||
$this->assertEquals($datos->sexo, $persona->datos->sexo);
|
||||
}
|
||||
}
|
66
app/tests/unit/src/Service/QueueTest.php
Normal file
66
app/tests/unit/src/Service/QueueTest.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace Incoviba\Test\Service;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Incoviba\Service\Job;
|
||||
use Incoviba\Service\Queue;
|
||||
use Incoviba\Service\Worker;
|
||||
use Incoviba\Model;
|
||||
|
||||
class QueueTest extends TestCase
|
||||
{
|
||||
protected LoggerInterface $logger;
|
||||
protected Job $jobService;
|
||||
protected Worker $defaultWorker;
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->logger = $this->getMockBuilder(LoggerInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->jobService = $this->getMockBuilder(Job::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->defaultWorker = $this->getMockBuilder(Worker::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
public function testRegister(): void
|
||||
{
|
||||
$queue = new Queue($this->logger, $this->jobService, $this->defaultWorker);
|
||||
$worker = $this->getMockBuilder(Worker::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$queue->register('test', $worker);
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
public function testEnqueue(): void
|
||||
{
|
||||
$queue = new Queue($this->logger, $this->jobService, $this->defaultWorker);
|
||||
$jobData = ['test' => 'test'];
|
||||
$result = $queue->enqueue($jobData);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $queue->push($jobData);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
public function testRun(): void
|
||||
{
|
||||
$queue = new Queue($this->logger, $this->jobService, $this->defaultWorker);
|
||||
$result = $queue->run();
|
||||
$this->assertTrue($result);
|
||||
|
||||
|
||||
$jobData = [
|
||||
'type' => 'test',
|
||||
];
|
||||
$job = new Model\Job();
|
||||
$job->id = 1;
|
||||
$job->configuration = $jobData;
|
||||
$this->jobService->method('isPending')->willReturn(true);
|
||||
$this->jobService->method('get')->willReturn($job);
|
||||
$result = $queue->run();
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
}
|
66
app/tests/unit/src/Service/UFTest.php
Normal file
66
app/tests/unit/src/Service/UFTest.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace Incoviba\Test\Service;
|
||||
|
||||
use DateInterval;
|
||||
use DateTimeImmutable;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Faker;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class UFTest extends TestCase
|
||||
{
|
||||
protected array $dateMap;
|
||||
protected array $ufMap;
|
||||
protected Service\Redis $redisService;
|
||||
protected Service\Money $moneyService;
|
||||
protected Repository\UF $ufRepository;
|
||||
protected LoggerInterface $logger;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$faker = Faker\Factory::create();
|
||||
$today = new DateTimeImmutable($faker->dateTime->format('Y-m-1'));
|
||||
|
||||
$this->dateMap = [
|
||||
$today->sub(new DateInterval("P1M")), // Case: Date past
|
||||
$today, // Case: Date === "Today" (1st of month)
|
||||
new DateTimeImmutable($today->format('Y-m-8')), // Case: Date 8th of month (before 9th)
|
||||
new DateTimeImmutable($today->format('Y-m-15')), // Case: Date 15th of month (after 9th)
|
||||
$today->add(new DateInterval("P1M")), // Case: Date one month from now
|
||||
];
|
||||
$this->ufMap = [
|
||||
$faker->randomFloat(2, 10000, 20000), // 1st value
|
||||
$faker->randomFloat(2, 25000, 38000), // 2nd value
|
||||
$faker->randomFloat(2, 38000, 39000), // 3rd value (before 9th)
|
||||
0.0, // no value (after 9th)
|
||||
0.0 // no value
|
||||
];
|
||||
|
||||
$this->redisService = $this->getMockBuilder(Service\Redis::class)->disableOriginalConstructor()->getMock();
|
||||
$emptyRedis = $this->getMockBuilder(EmptyRedis::class)->disableOriginalConstructor()->getMock();
|
||||
$this->redisService->method('get')->willThrowException($emptyRedis);
|
||||
$this->moneyService = $this->getMockBuilder(Service\Money::class)->disableOriginalConstructor()->getMock();
|
||||
$this->moneyService->method('getUF')->willReturnCallback(function($date) {
|
||||
return $this->ufMap[array_search($date, $this->dateMap)];
|
||||
});
|
||||
$this->ufRepository = $this->getMockBuilder(Repository\UF::class)->disableOriginalConstructor()->getMock();
|
||||
$emptyResult = $this->getMockBuilder(EmptyResult::class)->disableOriginalConstructor()->getMock();
|
||||
$this->ufRepository->method('fetchByFecha')->willThrowException($emptyResult);
|
||||
$this->logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$service = new Service\UF($this->redisService, $this->moneyService, $this->ufRepository, $this->logger);
|
||||
|
||||
foreach ($this->dateMap as $i => $date) {
|
||||
$uf = $service->get($date);
|
||||
|
||||
$this->assertEquals($this->ufMap[$i], $uf);
|
||||
}
|
||||
}
|
||||
}
|
85
app/tests/unit/src/Service/ValorTest.php
Normal file
85
app/tests/unit/src/Service/ValorTest.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
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();
|
||||
$faker = Factory::create();
|
||||
$this->ufService->method('get')->willReturn(self::$staticUF);
|
||||
}
|
||||
|
||||
public static function cleanDataProvider(): array
|
||||
{
|
||||
return [
|
||||
['1.003.000,01', 1003000.01],
|
||||
['4,273.84', 4273.84],
|
||||
[443.75, 443.75],
|
||||
['443.75', 443.75]
|
||||
];
|
||||
}
|
||||
|
||||
#[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 static function ufsDataProvider(): array
|
||||
{
|
||||
return [
|
||||
['1000000', 28.57143],
|
||||
[443.75, 443.75]
|
||||
];
|
||||
}
|
||||
|
||||
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 / self::$staticUF, $result);
|
||||
}
|
||||
|
||||
public static function pesosDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[1000.01, round(1000.01*self::$staticUF), false],
|
||||
[1000, round(1000*self::$staticUF), 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);
|
||||
}
|
||||
}
|
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));
|
||||
}
|
||||
}
|
@ -0,0 +1,198 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Service\Venta\MediosPago\Toku;
|
||||
|
||||
use Faker;
|
||||
use GuzzleHttp\Client;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use PDO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
class CustomerTest extends TestCase
|
||||
{
|
||||
protected Client $client;
|
||||
protected Model\Venta\MediosPago\Toku\Customer $customer;
|
||||
protected Repository\Venta\MediosPago\Toku\Customer $customerRepository;
|
||||
protected array $getData;
|
||||
protected array $postData;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$dsn = "mysql:host={$_ENV['DB_HOST']};dbname={$_ENV['DB_DATABASE']}";
|
||||
$pdo = new PDO($dsn, $_ENV['DB_USER'], $_ENV['DB_PASSWORD']);
|
||||
|
||||
$connection = $this->getMockBuilder(Define\Connection::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$connection->method('getPDO')->willReturn($pdo);
|
||||
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
$datos = $this->getMockBuilder(Model\Persona\Datos::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$datos->email = $faker->email();
|
||||
$datos->telefono = $faker->randomNumber(8);
|
||||
|
||||
$persona = $this->getMockBuilder(Model\Persona::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$persona->rut = $faker->randomNumber();
|
||||
$persona->digito = $faker->randomNumber();
|
||||
$persona->nombres = $faker->firstName();
|
||||
$persona->apellidoPaterno = $faker->lastName();
|
||||
$persona->apellidoMaterno = $faker->lastName();
|
||||
$persona->method('datos')->willReturn($datos);
|
||||
$persona->method('nombreCompleto')->willReturn(implode(' ', [
|
||||
$persona->nombres,
|
||||
$persona->apellidoPaterno,
|
||||
$persona->apellidoMaterno
|
||||
]));
|
||||
|
||||
$this->customer = $this->getMockBuilder(Model\Venta\MediosPago\Toku\Customer::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->customer->id = $faker->randomNumber();
|
||||
$this->customer->persona = $persona;
|
||||
$this->customer->toku_id = $faker->ean13();
|
||||
$this->customer->method('rut')->willReturn(implode('', [
|
||||
$persona->rut,
|
||||
strtoupper($persona->digito)
|
||||
]));
|
||||
$this->customer->method('jsonSerialize')->willReturn([
|
||||
'id' => $this->customer->id,
|
||||
'rut' => $this->customer->rut(),
|
||||
'toku_id' => $this->customer->toku_id
|
||||
]);
|
||||
|
||||
$this->customerRepository = $this->getMockBuilder(Repository\Venta\MediosPago\Toku\Customer::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->customerRepository->method('fetchById')->willReturn($this->customer);
|
||||
$this->customerRepository->method('fetchByRut')->willReturn($this->customer);
|
||||
$this->customerRepository->method('fetchByTokuId')->willReturn($this->customer);
|
||||
|
||||
$this->getData = [
|
||||
'id' => $this->customer->id,
|
||||
'external_id' => $this->customer->rut(),
|
||||
'government_id' => $this->customer->rut(),
|
||||
'email' => $persona->datos()->email,
|
||||
'name' => $persona->nombreCompleto(),
|
||||
'phone_number' => $persona->datos()->telefono,
|
||||
'silenced_until' => null,
|
||||
'default_agent' => null,
|
||||
'agent_phone_number' => null,
|
||||
'pac_mandate_id' => null,
|
||||
'send_mail' => false,
|
||||
'default_receipt_type' => 'bill',
|
||||
'rfc' => null,
|
||||
'tax_zip_code' => null,
|
||||
'fiscal_regime' => null,
|
||||
'secondary_emails' => [],
|
||||
'metadata' => []
|
||||
];
|
||||
|
||||
$getBody = $this->getMockBuilder(StreamInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$getBody->method('getContents')->willReturn(json_encode($this->getData));
|
||||
|
||||
$getResponse = $this->getMockBuilder(ResponseInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$getResponse->method('getStatusCode')->willReturn(200);
|
||||
$getResponse->method('getBody')->willReturn($getBody);
|
||||
|
||||
$this->postData = [
|
||||
'id' => $this->customer->id,
|
||||
'external_id' => $this->customer->rut(),
|
||||
'government_id' => $this->customer->rut(),
|
||||
'email' => $persona->datos()->email,
|
||||
'name' => $persona->nombreCompleto(),
|
||||
'phone_number' => $persona->datos()->telefono,
|
||||
'silenced_until' => null,
|
||||
'default_agent' => null,
|
||||
'agent_phone_number' => null,
|
||||
'pac_mandate_id' => null,
|
||||
'send_mail' => false,
|
||||
'default_receipt_type' => null,
|
||||
'rfc' => null,
|
||||
'tax_zip_code' => null,
|
||||
'fiscal_regime' => null,
|
||||
'secondary_emails' => [],
|
||||
'metadata' => []
|
||||
];
|
||||
|
||||
$postBody = $this->getMockBuilder(StreamInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$postBody->method('getContents')->willReturn(json_encode($this->postData));
|
||||
|
||||
$postResponse = $this->getMockBuilder(ResponseInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$postResponse->method('getStatusCode')->willReturn(200);
|
||||
$postResponse->method('getBody')->willReturn($postBody);
|
||||
|
||||
$deleteBody = $this->getMockBuilder(StreamInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$deleteBody->method('getContents')->willReturn('Customer Deleted');
|
||||
|
||||
$deleteResponse = $this->getMockBuilder(ResponseInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$deleteResponse->method('getStatusCode')->willReturn(204);
|
||||
$deleteResponse->method('getBody')->willReturn($deleteBody);
|
||||
|
||||
$this->client = $this->getMockBuilder(Client::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->client->method('get')->willReturn($getResponse);
|
||||
$this->client->method('post')->willReturn($postResponse);
|
||||
$this->client->method('put')->willReturn($postResponse);
|
||||
$this->client->method('delete')->willReturn($deleteResponse);
|
||||
}
|
||||
|
||||
public function testGetById(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku\Customer($this->client, $this->customerRepository);
|
||||
|
||||
$this->assertEquals(json_decode(json_encode($this->customer), true), $service->getById($this->customer->id));
|
||||
}
|
||||
public function testGetByExternalId(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku\Customer($this->client, $this->customerRepository);
|
||||
|
||||
$this->assertEquals(json_decode(json_encode($this->customer), true), $service->getByExternalId($this->customer->rut()));
|
||||
}
|
||||
public function testGet(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku\Customer($this->client, $this->customerRepository);
|
||||
|
||||
$this->assertArrayIsEqualToArrayIgnoringListOfKeys($this->getData, $service->get($this->customer->toku_id), []);
|
||||
}
|
||||
public function testAdd(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku\Customer($this->client, $this->customerRepository);
|
||||
|
||||
$sendData = [
|
||||
'rut' => $this->postData['government_id'],
|
||||
'nombreCompleto' => $this->postData['name'],
|
||||
'email' => $this->postData['email'],
|
||||
'telefono' => $this->postData['phone_number']
|
||||
];
|
||||
$this->assertTrue($service->add($sendData));
|
||||
}
|
||||
public function testEdit(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku\Customer($this->client, $this->customerRepository);
|
||||
|
||||
$sendData = [
|
||||
'rut' => $this->postData['government_id'],
|
||||
'nombreCompleto' => $this->postData['name'],
|
||||
'email' => $this->postData['email'],
|
||||
'telefono' => $this->postData['phone_number']
|
||||
];
|
||||
$this->assertTrue($service->edit($this->customer->toku_id, $sendData));
|
||||
}
|
||||
public function testDelete(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku\Customer($this->client, $this->customerRepository);
|
||||
|
||||
$this->expectNotToPerformAssertions();
|
||||
$service->delete($this->customer->toku_id);
|
||||
}
|
||||
}
|
265
app/tests/unit/src/Service/Venta/MediosPago/Toku/InvoiceTest.php
Normal file
265
app/tests/unit/src/Service/Venta/MediosPago/Toku/InvoiceTest.php
Normal file
@ -0,0 +1,265 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Service\Venta\MediosPago\Toku;
|
||||
|
||||
use Faker;
|
||||
use GuzzleHttp\Client;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use PDO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
class InvoiceTest extends TestCase
|
||||
{
|
||||
protected Client $client;
|
||||
protected Model\Venta\MediosPago\Toku\Invoice $invoice;
|
||||
protected Repository\Venta\MediosPago\Toku\Invoice $invoiceRepository;
|
||||
protected Model\Venta\Cuota $cuota;
|
||||
protected Service\Venta\Pago $pagoService;
|
||||
protected Service\UF $ufService;
|
||||
protected array $getData;
|
||||
protected array $saveData;
|
||||
protected \DateTimeInterface $fechaUF2;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$dsn = "mysql:host={$_ENV['DB_HOST']};dbname={$_ENV['DB_DATABASE']}";
|
||||
$pdo = new PDO($dsn, $_ENV['DB_USER'], $_ENV['DB_PASSWORD']);
|
||||
|
||||
$connection = $this->getMockBuilder(Define\Connection::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$connection->method('getPDO')->willReturn($pdo);
|
||||
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
$customer = $this->getMockBuilder(Model\Venta\MediosPago\Toku\Customer::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$customer->id = $faker->randomNumber();
|
||||
$customer->toku_id = $faker->ean13();
|
||||
$venta = $this->getMockBuilder(Model\Venta::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$venta->id = $faker->randomNumber();
|
||||
$subscription = $this->getMockBuilder(Model\Venta\MediosPago\Toku\Subscription::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$subscription->id = $faker->randomNumber();
|
||||
$subscription->venta = $venta;
|
||||
$subscription->toku_id = $faker->ean13();
|
||||
|
||||
$fechaUF1 = $faker->dateTimeInInterval('-3 years', '-1 weeks');
|
||||
$this->fechaUF2 = $faker->dateTimeInInterval('-1 month', 'now');
|
||||
$uf1 = $faker->randomFloat(2, 30000, 40000);
|
||||
$uf2 = $faker->randomFloat(2, 30000, 40000);
|
||||
|
||||
$this->ufService = $this->getMockBuilder(Service\UF::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->ufService->method('get')->willReturnCallback(function(\DateTimeInterface $dateTime) use ($fechaUF1, $uf1, $uf2, $faker) {
|
||||
return match ($dateTime->format('Y-m-d H:i:s')) {
|
||||
$fechaUF1->format('Y-m-d H:i:s') => $uf1,
|
||||
$this->fechaUF2->format('Y-m-d H:i:s') => $uf2,
|
||||
default => $faker->randomFloat(2, 30000, 40000)
|
||||
};
|
||||
});
|
||||
|
||||
$pago = $this->getMockBuilder(Model\Venta\Pago::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$pago->fecha = $fechaUF1;
|
||||
$pago->valor = $faker->randomNumber(6, true);
|
||||
$pago->uf = $uf1;
|
||||
$pago->method('valor')->willReturn($pago->valor / $uf1);
|
||||
$this->cuota = $this->getMockBuilder(Model\Venta\Cuota::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->cuota->id = $faker->randomNumber();
|
||||
$this->cuota->numero = $faker->randomNumber(2);
|
||||
$this->cuota->pago = $pago;
|
||||
|
||||
$this->invoice = $this->getMockBuilder(Model\Venta\MediosPago\Toku\Invoice::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->invoice->id = $faker->randomNumber();
|
||||
$this->invoice->cuota = $this->cuota;
|
||||
$this->invoice->toku_id = $faker->ean13();
|
||||
$this->invoice->method('jsonSerialize')->willReturn([
|
||||
'id' => $this->invoice->id,
|
||||
'cuota_id' => $this->cuota->id,
|
||||
'toku_id' => $this->invoice->toku_id
|
||||
]);
|
||||
|
||||
$this->invoiceRepository = $this->getMockBuilder(Repository\Venta\MediosPago\Toku\Invoice::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->invoiceRepository->method('fetchById')->willReturn($this->invoice);
|
||||
$this->invoiceRepository->method('fetchByCuota')->willReturn($this->invoice);
|
||||
$this->invoiceRepository->method('fetchByTokuId')->willReturn($this->invoice);
|
||||
|
||||
$this->getData = [
|
||||
'customer' => $customer->toku_id,
|
||||
'product_id' => $subscription->venta->id,
|
||||
'subscription' => $subscription->toku_id,
|
||||
'is_paid' => false,
|
||||
'due_date' => $this->cuota->pago->fecha->format('Y-m-d'),
|
||||
'is_void' => false,
|
||||
'amount' => $this->cuota->pago->valor,
|
||||
'link_payment' => '',
|
||||
'metadata' => [
|
||||
'numero' => $this->cuota->numero,
|
||||
'valor' => $this->cuota->pago->valor,
|
||||
'UF' => $this->cuota->pago->valor()
|
||||
],
|
||||
'receipt_type' => null,
|
||||
'id_receipt' => null,
|
||||
'source' => null,
|
||||
'disable_automatic_payment' => false,
|
||||
'currency_code' => 'CLP',
|
||||
'invoice_external_id' => $this->cuota->id,
|
||||
'id' => $this->invoice->toku_id,
|
||||
];
|
||||
|
||||
$getBody = $this->getMockBuilder(StreamInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$getBody->method('getContents')->willReturn(json_encode($this->getData));
|
||||
|
||||
$getResponse = $this->getMockBuilder(ResponseInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$getResponse->method('getBody')->willReturn($getBody);
|
||||
$getResponse->method('getStatusCode')->willReturn(200);
|
||||
|
||||
$this->postData = [
|
||||
'customer' => $customer->toku_id,
|
||||
'product_id' => $subscription->venta->id,
|
||||
'subscription' => $subscription->toku_id,
|
||||
'is_paid' => false,
|
||||
'due_date' => $this->cuota->pago->fecha->format('Y-m-d'),
|
||||
'is_void' => false,
|
||||
'amount' => $this->cuota->pago->valor,
|
||||
'link_payment' => '',
|
||||
'metadata' => [
|
||||
'numero' => $this->cuota->numero,
|
||||
'valor' => $this->cuota->pago->valor,
|
||||
'UF' => $this->cuota->pago->valor()
|
||||
],
|
||||
'receipt_type' => null,
|
||||
'id_receipt' => null,
|
||||
'source' => null,
|
||||
'disable_automatic_payment' => false,
|
||||
'currency_code' => 'CLF',
|
||||
'invoice_external_id' => $this->cuota->id,
|
||||
'id' => $this->invoice->toku_id,
|
||||
];
|
||||
|
||||
$postBody = $this->getMockBuilder(StreamInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$postBody->method('getContents')->willReturn(json_encode($this->postData));
|
||||
|
||||
$postResponse = $this->getMockBuilder(ResponseInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$postResponse->method('getBody')->willReturn($postBody);
|
||||
$postResponse->method('getStatusCode')->willReturn(200);
|
||||
|
||||
$deleteBody = $this->getMockBuilder(StreamInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$deleteBody->method('getContents')->willReturn("Invoice deleted");
|
||||
|
||||
$deleteResponse = $this->getMockBuilder(ResponseInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$deleteResponse->method('getBody')->willReturn($deleteBody);
|
||||
$deleteResponse->method('getStatusCode')->willReturn(204);
|
||||
|
||||
$this->client = $this->getMockBuilder(Client::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->client->method('get')->willReturn($getResponse);
|
||||
$this->client->method('post')->willReturn($postResponse);
|
||||
$this->client->method('put')->willReturn($postResponse);
|
||||
$this->client->method('delete')->willReturn($deleteResponse);
|
||||
|
||||
$this->pagoService = $this->getMockBuilder(Service\Venta\Pago::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->pagoService->method('depositar')->willReturn(true);
|
||||
}
|
||||
|
||||
public function testGetById(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository, $this->pagoService, $this->ufService);
|
||||
|
||||
$this->assertEquals(json_decode(json_encode($this->invoice), true), $service->getById($this->cuota->id));
|
||||
}
|
||||
public function testGetByExternalId(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository, $this->pagoService, $this->ufService);
|
||||
|
||||
$this->assertEquals(json_decode(json_encode($this->invoice), true), $service->getByExternalId($this->invoice->toku_id));
|
||||
}
|
||||
public function testGet(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository, $this->pagoService, $this->ufService);
|
||||
|
||||
$this->assertEquals($this->getData, $service->get($this->invoice->toku_id));
|
||||
}
|
||||
public function testAdd(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository, $this->pagoService, $this->ufService);
|
||||
|
||||
$sendData = [
|
||||
'customer' => $this->postData['customer'],
|
||||
'product_id' => $this->postData['product_id'],
|
||||
'subscription' => $this->postData['subscription'],
|
||||
'cuota' => $this->cuota
|
||||
];
|
||||
|
||||
$this->assertTrue($service->add($sendData));
|
||||
}
|
||||
public function testEdit(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository, $this->pagoService, $this->ufService);
|
||||
|
||||
$sendData = [
|
||||
'customer' => $this->postData['customer'],
|
||||
'product_id' => $this->postData['product_id'],
|
||||
'subscription' => $this->postData['subscription'],
|
||||
'cuota' => $this->cuota
|
||||
];
|
||||
|
||||
$this->assertTrue($service->edit($this->invoice->toku_id, $sendData));
|
||||
}
|
||||
public function testDelete(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository, $this->pagoService, $this->ufService);
|
||||
|
||||
$this->expectNotToPerformAssertions();
|
||||
$service->delete($this->invoice->toku_id);
|
||||
}
|
||||
public function testUpdate(): void
|
||||
{
|
||||
$faker = Faker\Factory::create();
|
||||
$uf2 = $this->ufService->get($this->fechaUF2);
|
||||
$valor = round($this->cuota->pago->valor() * $uf2);
|
||||
$request = [
|
||||
'id' => $faker->ean13(),
|
||||
'event_type' => 'payment_intent.succeeded',
|
||||
'payment_intent' => [
|
||||
'id' => $faker->ean13(),
|
||||
'invoice' => $this->invoice->toku_id,
|
||||
'customer' => $this->getData['customer'],
|
||||
'id_account' => $faker->ean13(),
|
||||
'gateway' => 'khipu_transfer',
|
||||
'amount' => $valor,
|
||||
'status' => 'AUTHORIZED',
|
||||
'payment_method' => $faker->ean13(),
|
||||
'transaction_date' => $this->fechaUF2->format('Y-m-d H:i:s.u'),
|
||||
'card_detail' => null,
|
||||
'buy_order' => $faker->ean8(),
|
||||
'child_buy_order' => null,
|
||||
'authorization_code' => null,
|
||||
'payment_type_code' => null,
|
||||
'response_code' => null,
|
||||
'toku_response_code' => null,
|
||||
'installments_number' => null,
|
||||
'mc_order_id' => null,
|
||||
]
|
||||
];
|
||||
|
||||
$service = new Service\Venta\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository, $this->pagoService, $this->ufService);
|
||||
|
||||
$this->assertTrue($service->update($request['payment_intent']['invoice'], $request['payment_intent']));
|
||||
}
|
||||
}
|
@ -0,0 +1,190 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Service\Venta\MediosPago\Toku;
|
||||
|
||||
use Faker;
|
||||
use GuzzleHttp\Client;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use PDO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
class SubscriptionTest extends TestCase
|
||||
{
|
||||
protected Client $client;
|
||||
protected Model\Venta\MediosPago\Toku\Subscription $subscription;
|
||||
protected Repository\Venta\MediosPago\Toku\Subscription $subscriptionRepository;
|
||||
protected Model\Venta $venta;
|
||||
protected array $getData;
|
||||
protected array $postData;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$dsn = "mysql:host={$_ENV['DB_HOST']};dbname={$_ENV['DB_DATABASE']}";
|
||||
$pdo = new PDO($dsn, $_ENV['DB_USER'], $_ENV['DB_PASSWORD']);
|
||||
|
||||
$connection = $this->getMockBuilder(Define\Connection::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$connection->method('getPDO')->willReturn($pdo);
|
||||
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
$customer = $this->getMockBuilder(Model\Venta\MediosPago\Toku\Customer::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$customer->id = $faker->randomNumber();
|
||||
|
||||
$pie = $this->getMockBuilder(Model\Venta\Pie::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$pie->valor = $faker->randomFloat();
|
||||
$formaPago = $this->getMockBuilder(Model\Venta\FormaPago::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$formaPago->pie = $pie;
|
||||
$proyecto = $this->getMockBuilder(Model\Proyecto::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$proyecto->descripcion = $faker->sentence();
|
||||
$summary = implode(' - ', [
|
||||
$faker->randomNumber(4),
|
||||
'E' . $faker->randomNumber(3),
|
||||
'B' . $faker->randomNumber(3),
|
||||
]);
|
||||
$propiedad = $this->getMockBuilder(Model\Venta\Propiedad::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$propiedad->method('summary')->willReturn($summary);
|
||||
$this->venta = $this->getMockBuilder(Model\Venta::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->venta->id = $faker->randomNumber();
|
||||
$this->venta->method('formaPago')->willReturn($formaPago);
|
||||
$this->venta->method('proyecto')->willReturn($proyecto);
|
||||
$this->venta->method('propiedad')->willReturn($propiedad);
|
||||
|
||||
$this->subscription = $this->getMockBuilder(Model\Venta\MediosPago\Toku\Subscription::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->subscription->id = $faker->randomNumber();
|
||||
$this->subscription->venta = $this->venta;
|
||||
$this->subscription->toku_id = $faker->ean13();
|
||||
$this->subscription->method('jsonSerialize')->willReturn([
|
||||
'id' => $this->subscription->id,
|
||||
'venta_id' => $this->venta->id,
|
||||
'toku_id' => $this->subscription->toku_id,
|
||||
]);
|
||||
|
||||
$this->subscriptionRepository = $this->getMockBuilder(Repository\Venta\MediosPago\Toku\Subscription::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->subscriptionRepository->method('fetchById')->willReturn($this->subscription);
|
||||
$this->subscriptionRepository->method('fetchByVenta')->willReturn($this->subscription);
|
||||
$this->subscriptionRepository->method('fetchByTokuId')->willReturn($this->subscription);
|
||||
|
||||
$this->getData = [
|
||||
'id' => $this->subscription->toku_id,
|
||||
'customer' => $customer->id,
|
||||
'product_id' => $this->venta->id,
|
||||
'pac_mandate_id' => null,
|
||||
'is_recurring' => false,
|
||||
'amount' => $pie->valor,
|
||||
'due_day' => null,
|
||||
'receipt_product_code' => null,
|
||||
'metadata' => [
|
||||
'proyecto' => $proyecto->descripcion,
|
||||
'propiedad' => $propiedad->summary(),
|
||||
]
|
||||
];
|
||||
|
||||
$getBody = $this->getMockBuilder(StreamInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$getBody->method('getContents')->willReturn(json_encode($this->getData));
|
||||
|
||||
$getResponse = $this->getMockBuilder(ResponseInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$getResponse->method('getStatusCode')->willReturn(200);
|
||||
$getResponse->method('getBody')->willReturn($getBody);
|
||||
|
||||
$this->postData = [
|
||||
'id' => $this->subscription->toku_id,
|
||||
'customer' => $customer->id,
|
||||
'product_id' => $this->venta->id,
|
||||
'pac_mandate_id' => null,
|
||||
'is_recurring' => false,
|
||||
'amount' => $pie->valor,
|
||||
'due_day' => null,
|
||||
'metadata' => [
|
||||
'proyecto' => $proyecto->descripcion,
|
||||
'propiedad' => $propiedad->summary(),
|
||||
]
|
||||
];
|
||||
|
||||
$postBody = $this->getMockBuilder(StreamInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$postBody->method('getContents')->willReturn(json_encode($this->postData));
|
||||
|
||||
$postResponse = $this->getMockBuilder(ResponseInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$postResponse->method('getStatusCode')->willReturn(200);
|
||||
$postResponse->method('getBody')->willReturn($postBody);
|
||||
|
||||
$deleteBody = $this->getMockBuilder(StreamInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$deleteBody->method('getContents')->willReturn('Subscription deleted');
|
||||
$deleteResponse = $this->getMockBuilder(ResponseInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$deleteResponse->method('getStatusCode')->willReturn(204);
|
||||
$deleteResponse->method('getBody')->willReturn($deleteBody);
|
||||
|
||||
$this->client = $this->getMockBuilder(Client::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->client->method('get')->willReturn($getResponse);
|
||||
$this->client->method('post')->willReturn($postResponse);
|
||||
$this->client->method('put')->willReturn($postResponse);
|
||||
$this->client->method('delete')->willReturn($deleteResponse);
|
||||
}
|
||||
|
||||
public function testGetById(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku\Subscription($this->client, $this->subscriptionRepository);
|
||||
|
||||
$this->assertEquals(json_decode(json_encode($this->subscription), true), $service->getById($this->subscription->toku_id));
|
||||
}
|
||||
public function testGetByExternalId(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku\Subscription($this->client, $this->subscriptionRepository);
|
||||
|
||||
$this->assertEquals(json_decode(json_encode($this->subscription), true), $service->getByExternalId($this->subscription->toku_id));
|
||||
}
|
||||
public function testGet(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku\Subscription($this->client, $this->subscriptionRepository);
|
||||
|
||||
$this->assertArrayIsEqualToArrayIgnoringListOfKeys($this->getData, $service->get($this->subscription->toku_id), []);
|
||||
}
|
||||
public function testAdd(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku\Subscription($this->client, $this->subscriptionRepository);
|
||||
|
||||
$sendData = [
|
||||
'customer' => $this->postData['customer'],
|
||||
'product_id' => $this->postData['product_id'],
|
||||
'venta' => $this->venta
|
||||
];
|
||||
$this->assertTrue($service->add($sendData));
|
||||
}
|
||||
public function testEdit(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku\Subscription($this->client, $this->subscriptionRepository);
|
||||
|
||||
$sendData = [
|
||||
'customer' => $this->postData['customer'],
|
||||
'product_id' => $this->postData['product_id'],
|
||||
'venta' => $this->venta
|
||||
];
|
||||
$this->assertTrue($service->edit($this->subscription->toku_id, $sendData));
|
||||
}
|
||||
public function testDelete(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku\Subscription($this->client, $this->subscriptionRepository);
|
||||
|
||||
$this->expectNotToPerformAssertions();
|
||||
$service->delete($this->subscription->toku_id);
|
||||
}
|
||||
}
|
339
app/tests/unit/src/Service/Venta/MediosPago/TokuTest.php
Normal file
339
app/tests/unit/src/Service/Venta/MediosPago/TokuTest.php
Normal file
@ -0,0 +1,339 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Service\Venta\MediosPago;
|
||||
|
||||
use Faker;
|
||||
use Incoviba\Exception\InvalidResult;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class TokuTest extends TestCase
|
||||
{
|
||||
protected LoggerInterface $logger;
|
||||
protected Service\Venta\MediosPago\Toku\Customer $customerService;
|
||||
protected Service\Venta\MediosPago\Toku\Subscription $subscriptionService;
|
||||
protected Service\Venta\MediosPago\Toku\Invoice $invoiceService;
|
||||
protected Model\Venta\MediosPago\Toku\Customer $customer;
|
||||
protected Model\Venta\MediosPago\Toku\Subscription $subscription;
|
||||
protected Model\Venta\MediosPago\Toku\Invoice $invoice;
|
||||
protected Model\Persona $persona;
|
||||
protected Model\Venta $venta;
|
||||
protected Model\Venta\Cuota $cuota;
|
||||
protected Model\Venta\Pago $pago;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
$this->logger = $this->getMockBuilder(LoggerInterface::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
|
||||
$datos = $this->getMockBuilder(Model\Persona\Datos::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$datos->email = $faker->email();
|
||||
$datos->telefono = $faker->randomNumber(9);
|
||||
$this->persona = $this->getMockBuilder(Model\Persona::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->persona->rut = $faker->randomNumber();
|
||||
$this->persona->digito = 'K';
|
||||
$this->persona->nombres = $faker->firstName();
|
||||
$this->persona->apellidoPaterno = $faker->lastName();
|
||||
$this->persona->apellidoMaterno = $faker->lastName();
|
||||
$this->persona->method('datos')->willReturn($datos);
|
||||
$this->persona->method('__get')->with('dv')->willReturn($this->persona->digito);
|
||||
$this->customer = $this->getMockBuilder(Model\Venta\MediosPago\Toku\Customer::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->customer->id = $faker->randomNumber();
|
||||
$this->customer->persona = $this->persona;
|
||||
$this->customer->toku_id = $faker->ean13();
|
||||
$this->customer->method('rut')->willReturn(implode('', [
|
||||
$this->persona->rut,
|
||||
strtoupper($this->persona->digito)
|
||||
]));
|
||||
|
||||
$pie = $this->getMockBuilder(Model\Venta\Pie::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$pie->valor = $faker->randomFloat();
|
||||
$formaPago = $this->getMockBuilder(Model\Venta\FormaPago::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$formaPago->pie = $pie;
|
||||
$proyecto = $this->getMockBuilder(Model\Proyecto::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$proyecto->descripcion = $faker->sentence();
|
||||
$summary = implode(' - ', [
|
||||
$faker->randomNumber(4),
|
||||
'E' . $faker->randomNumber(3),
|
||||
'B' . $faker->randomNumber(3),
|
||||
]);
|
||||
$propiedad = $this->getMockBuilder(Model\Venta\Propiedad::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$propiedad->method('summary')->willReturn($summary);
|
||||
$datos2 = $this->getMockBuilder(Model\Venta\Datos::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$datos2->email = $datos->email;
|
||||
$datos2->telefono = $datos->telefono;
|
||||
$propietario = $this->getMockBuilder(Model\Venta\Propietario::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$propietario->rut = $this->persona->rut;
|
||||
$propietario->dv = $this->persona->dv;
|
||||
$propietario->nombres = $this->persona->nombres;
|
||||
$propietario->apellidos = ['paterno' => $this->persona->apellidoPaterno, 'materno' => $this->persona->apellidoMaterno];
|
||||
$propietario->datos = $datos2;
|
||||
$this->venta = $this->getMockBuilder(Model\Venta::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->venta->id = $faker->randomNumber();
|
||||
$this->venta->method('formaPago')->willReturn($formaPago);
|
||||
$this->venta->method('proyecto')->willReturn($proyecto);
|
||||
$this->venta->method('propiedad')->willReturn($propiedad);
|
||||
$this->venta->method('propietario')->willReturn($propietario);
|
||||
$this->subscription = $this->getMockBuilder(Model\Venta\MediosPago\Toku\Subscription::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->subscription->id = $faker->randomNumber();
|
||||
$this->subscription->venta = $this->venta;
|
||||
$this->subscription->toku_id = $faker->ean13();
|
||||
|
||||
$this->pago = $this->getMockBuilder(Model\Venta\Pago::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->pago->fecha = $faker->dateTime();
|
||||
$this->pago->valor = $faker->randomNumber(6);
|
||||
$this->pago->method('valor')->willReturn($faker->randomFloat(3, 10, 500));
|
||||
$this->cuota = $this->getMockBuilder(Model\Venta\Cuota::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->cuota->id = $faker->randomNumber();
|
||||
$this->cuota->numero = $faker->randomNumber(2);
|
||||
$this->cuota->pago = $this->pago;
|
||||
$pie->method('cuotas')->willReturn([$this->cuota]);
|
||||
$this->invoice = $this->getMockBuilder(Model\Venta\MediosPago\Toku\Invoice::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->invoice->id = $faker->randomNumber();
|
||||
$this->invoice->cuota = $this->cuota;
|
||||
$this->invoice->toku_id = $faker->ean13();
|
||||
|
||||
$customerArray = [
|
||||
'id' => $this->customer->id,
|
||||
'rut' => $this->customer->rut(),
|
||||
'toku_id' => $this->customer->toku_id
|
||||
];
|
||||
$this->customerService = $this->getMockBuilder(Service\Venta\MediosPago\Toku\Customer::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->customerService->method('getById')->willReturn($customerArray);
|
||||
$this->customerService->method('getByExternalId')->willReturn($customerArray);
|
||||
$this->customerService->method('get')->willReturn([
|
||||
'id' => $this->customer->toku_id,
|
||||
'goverment_id' => $this->customer->rut(),
|
||||
'external_id' => $this->customer->rut(),
|
||||
'name' => implode(' ', [$this->persona->nombres, $this->persona->apellidoPaterno, $this->persona->apellidoMaterno]),
|
||||
'mail' => $this->persona->datos()->email,
|
||||
'phone_number' => $this->persona->datos()->telefono,
|
||||
'silenced_until' => null,
|
||||
'default_agent' => 'contacto@incoviba.cl',
|
||||
'agent_phone_number' => null,
|
||||
'pac_mandate_id' => null,
|
||||
'send_mail' => false,
|
||||
'default_receipt_type' => null,
|
||||
'rfc' => null,
|
||||
'tax_zip_code' => null,
|
||||
'fiscal_regime' => null,
|
||||
'secondary_emails' => [],
|
||||
'metadata' => []
|
||||
]);
|
||||
$this->customerService->method('add')->willReturn(true);
|
||||
$this->customerService->method('edit')->willReturn(true);
|
||||
$this->customerService->method('delete');
|
||||
|
||||
$this->subscriptionService = $this->getMockBuilder(Service\Venta\MediosPago\Toku\Subscription::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->subscriptionService->method('getById')->willReturn([
|
||||
'id' => $this->subscription->id,
|
||||
'venta_id' => $this->venta->id,
|
||||
'toku_id' => $this->subscription->toku_id,
|
||||
]);
|
||||
$this->subscriptionService->method('get')->willReturn([
|
||||
'id' => $this->subscription->toku_id,
|
||||
'customer' => $this->customer->toku_id,
|
||||
'product_id' => $this->venta->id,
|
||||
'pac_mandate_id' => null,
|
||||
'is_recurring' => false,
|
||||
'amount' => $pie->valor,
|
||||
'due_day' => null,
|
||||
'receipt_product_code' => null,
|
||||
'metadata' => [
|
||||
'proyecto' => $proyecto->descripcion,
|
||||
'propiedad' => $propiedad->summary(),
|
||||
]
|
||||
]);
|
||||
$this->subscriptionService->method('add')->willReturn(true);
|
||||
$this->subscriptionService->method('edit')->willReturn(true);
|
||||
$this->subscriptionService->method('delete');
|
||||
|
||||
$invoiceArray = [
|
||||
'id' => $this->invoice->id,
|
||||
'cuota_id' => $this->cuota->id,
|
||||
'toku_id' => $this->invoice->toku_id,
|
||||
];
|
||||
$this->invoiceService = $this->getMockBuilder(Service\Venta\MediosPago\Toku\Invoice::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->invoiceService->method('getById')->willReturn($invoiceArray);
|
||||
$this->invoiceService->method('getByExternalId')->willReturn($invoiceArray);
|
||||
$this->invoiceService->method('get')->willReturn([
|
||||
'id' => $this->invoice->toku_id,
|
||||
'customer' => $this->customer->toku_id,
|
||||
'product_id' => $this->venta->id,
|
||||
'subscription' => $this->subscription->toku_id,
|
||||
'is_paid' => false,
|
||||
'due_date' => $this->pago->fecha->format('Y-m-d'),
|
||||
'is_void' => false,
|
||||
'amount' => $this->pago->valor(),
|
||||
'link_payment' => '',
|
||||
'metadata' => [
|
||||
'numero' => $this->cuota->numero,
|
||||
'valor' => $this->cuota->pago->valor,
|
||||
'UF' => $this->cuota->pago->valor(),
|
||||
],
|
||||
'receipt_type' => null,
|
||||
'id_receipt' => null,
|
||||
'source' => null,
|
||||
'disable_automatic_payment' => false,
|
||||
'currency_code' => 'CLF',
|
||||
'invoice_external_id' => $this->cuota->id,
|
||||
]);
|
||||
$this->invoiceService->method('add')->willReturn(true);
|
||||
$this->invoiceService->method('edit')->willReturn(true);
|
||||
$this->invoiceService->method('delete');
|
||||
$this->invoiceService->method('update')->willReturn(true);
|
||||
}
|
||||
|
||||
public function testSendCustomer(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku($this->logger);
|
||||
$service->register(Service\Venta\MediosPago\Toku::CUSTOMER, $this->customerService);
|
||||
|
||||
$expected = [
|
||||
'id' => $this->customer->id,
|
||||
'rut' => $this->customer->rut(),
|
||||
'toku_id' => $this->customer->toku_id
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $service->sendPersona($this->persona));
|
||||
}
|
||||
public function testSendSubscription(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku($this->logger);
|
||||
$service->register(Service\Venta\MediosPago\Toku::CUSTOMER, $this->customerService);
|
||||
$service->register(Service\Venta\MediosPago\Toku::SUBSCRIPTION, $this->subscriptionService);
|
||||
|
||||
$expected = [
|
||||
'id' => $this->subscription->id,
|
||||
'venta_id' => $this->venta->id,
|
||||
'toku_id' => $this->subscription->toku_id,
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $service->sendVenta($this->venta));
|
||||
}
|
||||
public function testSendInvoice(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku($this->logger);
|
||||
$service->register(Service\Venta\MediosPago\Toku::CUSTOMER, $this->customerService);
|
||||
$service->register(Service\Venta\MediosPago\Toku::SUBSCRIPTION, $this->subscriptionService);
|
||||
$service->register(Service\Venta\MediosPago\Toku::INVOICE, $this->invoiceService);
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'id' => $this->invoice->id,
|
||||
'cuota_id' => $this->cuota->id,
|
||||
'toku_id' => $this->invoice->toku_id,
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $service->sendCuotas($this->venta));
|
||||
}
|
||||
public function testUpdatePago(): void
|
||||
{
|
||||
$service = new Service\Venta\MediosPago\Toku($this->logger);
|
||||
$service->register(Service\Venta\MediosPago\Toku::CUSTOMER, $this->customerService);
|
||||
$service->register(Service\Venta\MediosPago\Toku::INVOICE, $this->invoiceService);
|
||||
|
||||
$faker = Faker\Factory::create();
|
||||
$request = [
|
||||
'id' => $faker->ean13(),
|
||||
'event_type' => 'payment_intent.succeeded',
|
||||
'payment_intent' => [
|
||||
'id' => $faker->ean13(),
|
||||
'invoice' => $this->invoice->toku_id,
|
||||
'customer' => $this->customer->toku_id,
|
||||
'id_account' => $faker->ean13(),
|
||||
'gateway' => 'khipu_transfer',
|
||||
'amount' => $this->pago->valor,
|
||||
'status' => 'AUTHORIZED',
|
||||
'payment_method' => $faker->ean13(),
|
||||
'transaction_date' => $faker->dateTime(),
|
||||
'card_detail' => null,
|
||||
'buy_order' => $faker->ean8(),
|
||||
'child_buy_order' => null,
|
||||
'authorization_code' => null,
|
||||
'payment_type_code' => null,
|
||||
'response_code' => null,
|
||||
'toku_response_code' => null,
|
||||
'installments_number' => null,
|
||||
'mc_order_id' => null,
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertTrue($service->updatePago($request['payment_intent']));
|
||||
}
|
||||
public function testUpdatePagoException(): void
|
||||
{
|
||||
|
||||
$emptyResponse = $this->getMockBuilder(InvalidResult::class)
|
||||
->setConstructorArgs(['message' => "No existe Customer para toku_id {$this->customer->toku_id}"])->getMock();
|
||||
|
||||
$customerService = clone($this->customerService);
|
||||
$customerService->method('getByExternalId')->willThrowException($emptyResponse);
|
||||
|
||||
$service = new Service\Venta\MediosPago\Toku($this->logger);
|
||||
$service->register(Service\Venta\MediosPago\Toku::CUSTOMER, $customerService);
|
||||
$service->register(Service\Venta\MediosPago\Toku::INVOICE, $this->invoiceService);
|
||||
|
||||
$faker = Faker\Factory::create();
|
||||
$request = [
|
||||
'id' => $faker->ean13(),
|
||||
'event_type' => 'payment_intent.succeeded',
|
||||
'payment_intent' => [
|
||||
'id' => $faker->ean13(),
|
||||
'invoice' => $this->invoice->toku_id,
|
||||
'customer' => $this->customer->toku_id,
|
||||
'id_account' => $faker->ean13(),
|
||||
'gateway' => 'khipu_transfer',
|
||||
'amount' => $this->pago->valor,
|
||||
'status' => 'AUTHORIZED',
|
||||
'payment_method' => $faker->ean13(),
|
||||
'transaction_date' => $faker->dateTime(),
|
||||
'card_detail' => null,
|
||||
'buy_order' => $faker->ean8(),
|
||||
'child_buy_order' => null,
|
||||
'authorization_code' => null,
|
||||
'payment_type_code' => null,
|
||||
'response_code' => null,
|
||||
'toku_response_code' => null,
|
||||
'installments_number' => null,
|
||||
'mc_order_id' => null,
|
||||
]
|
||||
];
|
||||
|
||||
$this->expectException(InvalidResult::class);
|
||||
$service->updatePago($request['payment_intent']);
|
||||
|
||||
$emptyResponse = $this->getMockBuilder(InvalidResult::class)
|
||||
->setConstructorArgs(['message' => "No existe Invoice para toku_id {$this->invoice->toku_id}"])->getMock();
|
||||
$invoiceService = clone($this->invoiceService);
|
||||
$invoiceService->method('getByExternalId')->willThrowException($emptyResponse);
|
||||
|
||||
$service = new Service\Venta\MediosPago\Toku($this->logger);
|
||||
$service->register(Service\Venta\MediosPago\Toku::CUSTOMER, $this->customerService);
|
||||
$service->register(Service\Venta\MediosPago\Toku::INVOICE, $invoiceService);
|
||||
|
||||
$this->expectException(InvalidResult::class);
|
||||
$service->updatePago($request['payment_intent']);
|
||||
}
|
||||
}
|
73
app/tests/unit/src/Service/Venta/PagoTest.php
Normal file
73
app/tests/unit/src/Service/Venta/PagoTest.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace Incoviba\Test\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);
|
||||
}
|
||||
}
|
164
app/tests/unit/src/Service/Venta/Precio/EstadoTest.php
Normal file
164
app/tests/unit/src/Service/Venta/Precio/EstadoTest.php
Normal file
@ -0,0 +1,164 @@
|
||||
<?php
|
||||
namespace Incoviba\Test\Unit\Service\Venta\Precio;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Faker;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class EstadoTest extends TestCase
|
||||
{
|
||||
protected LoggerInterface $logger;
|
||||
protected Repository\Venta\Precio $precioRepository;
|
||||
protected Repository\Venta\EstadoPrecio $estadoPrecioRepository;
|
||||
protected Repository\Venta\TipoEstadoPrecio $tipoEstadoPrecioRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->logger = $this->getMockBuilder(LoggerInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->precioRepository = $this->getMockBuilder(Repository\Venta\Precio::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->estadoPrecioRepository = $this->getMockBuilder(Repository\Venta\EstadoPrecio::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->tipoEstadoPrecioRepository = $this->getMockBuilder(Repository\Venta\TipoEstadoPrecio::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
public function testUpdatePrice(): void
|
||||
{
|
||||
$uniqueElements = 1000;
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
$tipoEstadoPrecio = $this->getMockBuilder(Model\Venta\TipoEstadoPrecio::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$tipoEstadoPrecio->id = $faker->unique()->numberBetween(1, $uniqueElements);
|
||||
$tipoEstadoPrecio->descripcion = 'vigente';
|
||||
|
||||
$tipoEstadoPrecioRepository = $this->getMockBuilder(Repository\Venta\TipoEstadoPrecio::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$tipoEstadoPrecioRepository->method('fetchByDescripcion')->with('vigente')->willReturn($tipoEstadoPrecio);
|
||||
|
||||
$unidad = $this->getMockBuilder(Model\Venta\Unidad::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$unidad->id = $faker->unique()->numberBetween(1, $uniqueElements);
|
||||
|
||||
$precio = $this->getMockBuilder(Model\Venta\Precio::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$precio->id = $faker->unique()->numberBetween(1, $uniqueElements);
|
||||
$precio->unidad = $unidad;
|
||||
|
||||
$estadoPrecio = $this->getMockBuilder(Model\Venta\EstadoPrecio::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$estadoPrecio->id = $faker->unique()->numberBetween(1, $uniqueElements);
|
||||
$estadoPrecio->precio = $precio;
|
||||
$estadoPrecio->tipoEstadoPrecio = $tipoEstadoPrecio;
|
||||
$estadoPrecioRepository = $this->getMockBuilder(Repository\Venta\EstadoPrecio::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$estadoPrecioRepository->method('create')->willReturn($estadoPrecio);
|
||||
$estadoPrecioRepository->method('save')->willReturnArgument(0);
|
||||
|
||||
$date = $faker->dateTimeBetween('-6 months');
|
||||
|
||||
$estadoPrecioService = new Service\Venta\Precio\Estado($this->logger, $this->precioRepository,
|
||||
$estadoPrecioRepository, $tipoEstadoPrecioRepository);
|
||||
|
||||
$estadoPrecioService->updatePrice($precio, $date);
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
public function testReplacePrices(): void
|
||||
{
|
||||
$uniqueElements = 1000;
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
$tipoEstadoPrecio1 = $this->getMockBuilder(Model\Venta\TipoEstadoPrecio::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$tipoEstadoPrecio1->id = $faker->unique()->numberBetween(1, $uniqueElements);
|
||||
$tipoEstadoPrecio1->descripcion = 'vigente';
|
||||
|
||||
$tipoEstadoPrecio = $this->getMockBuilder(Model\Venta\TipoEstadoPrecio::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$tipoEstadoPrecio->id = $faker->unique()->numberBetween(1, $uniqueElements);
|
||||
$tipoEstadoPrecio->descripcion = 'reemplazado';
|
||||
|
||||
$this->tipoEstadoPrecioRepository->method('fetchByDescripcion')
|
||||
->willReturnCallback(function($descripcion) use ($tipoEstadoPrecio, $tipoEstadoPrecio1) {
|
||||
return match ($descripcion) {
|
||||
'vigente' => $tipoEstadoPrecio1,
|
||||
'reemplazado' => $tipoEstadoPrecio,
|
||||
};
|
||||
});
|
||||
|
||||
$unidad = $this->getMockBuilder(Model\Venta\Unidad::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$unidad->id = $faker->unique()->numberBetween(1, $uniqueElements);
|
||||
|
||||
$preciosCount = $faker->numberBetween(1, 10);
|
||||
$precios = [];
|
||||
$estados = [];
|
||||
for ($i = 0; $i < $preciosCount; $i++) {
|
||||
$precio = $this->getMockBuilder(Model\Venta\Precio::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$precio->id = $faker->unique()->numberBetween(1, $uniqueElements);
|
||||
$precios []= $precio;
|
||||
$estado = $this->getMockBuilder(Model\Venta\EstadoPrecio::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$estado->id = $faker->unique()->numberBetween(1, $uniqueElements);
|
||||
$estado->precio = $precio;
|
||||
$estado->tipoEstadoPrecio = $tipoEstadoPrecio1;
|
||||
$estados []= $estado;
|
||||
}
|
||||
$this->precioRepository->method('fetchByUnidad')->with($unidad->id)->willReturn($precios);
|
||||
$this->estadoPrecioRepository->method('fetchCurrentByPrecio')->willReturnCallback(function($precio_id) use ($estados) {
|
||||
$idx = array_search($precio_id, array_map(fn($estado) => $estado->precio->id, $estados));
|
||||
return $estados[$idx];
|
||||
});
|
||||
|
||||
$newEstados = [];
|
||||
foreach ($precios as $precio) {
|
||||
$estado = $this->getMockBuilder(Model\Venta\EstadoPrecio::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$estado->id = $faker->unique()->numberBetween(1, $uniqueElements);
|
||||
$estado->precio = $precio;
|
||||
$estado->tipoEstadoPrecio = $tipoEstadoPrecio;
|
||||
$newEstados []= $estado;
|
||||
}
|
||||
$this->estadoPrecioRepository->method('create')->willReturnCallback(function($data) use ($newEstados) {
|
||||
$idx = array_search($data['precio'], array_map(fn($estado) => $estado->precio->id, $newEstados));
|
||||
return $newEstados[$idx];
|
||||
});
|
||||
$this->estadoPrecioRepository->method('save')->willReturnArgument(0);
|
||||
|
||||
$precio = $this->getMockBuilder(Model\Venta\Precio::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$precio->id = $faker->unique()->numberBetween(1, $uniqueElements);
|
||||
$precio->unidad = $unidad;
|
||||
|
||||
$date = $faker->dateTimeBetween('-6 months');
|
||||
|
||||
$estadoPrecioService = new Service\Venta\Precio\Estado($this->logger, $this->precioRepository,
|
||||
$this->estadoPrecioRepository, $this->tipoEstadoPrecioRepository);
|
||||
|
||||
$estadoPrecioService->replacePrices($unidad, $date, $precio);
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
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);
|
||||
}
|
||||
}
|
46
app/tests/unit/src/Service/Worker/ServiceTest.php
Normal file
46
app/tests/unit/src/Service/Worker/ServiceTest.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Service\Worker;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Model;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class ServiceTest extends TestCase
|
||||
{
|
||||
protected Model\Job $job;
|
||||
protected ContainerInterface $container;
|
||||
protected LoggerInterface $logger;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$pagoService = $this->getMockBuilder(Service\Venta\Pago::class)->disableOriginalConstructor()->getMock();
|
||||
$pagoService->method('updateUF')->willReturn(true);
|
||||
$this->logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
|
||||
$this->container = $this->getMockBuilder(ContainerInterface::class)->disableOriginalConstructor()->getMock();
|
||||
$this->container->method('get')->willReturnMap([
|
||||
[LoggerInterface::class, $this->logger],
|
||||
[Service\Queue::class, $this->getMockBuilder(Service\Queue::class)->disableOriginalConstructor()->getMock()],
|
||||
[Service\UF::class, $this->getMockBuilder(Service\UF::class)->disableOriginalConstructor()->getMock()],
|
||||
[Service\Venta\Pago::class, $pagoService],
|
||||
]);
|
||||
}
|
||||
|
||||
public function testExecute(): void
|
||||
{
|
||||
$configuration = [
|
||||
'type' => 'service',
|
||||
'service' => Service\Venta\Pago::class,
|
||||
'method' => 'updateUF',
|
||||
'params' => ['pago_id' => 1]
|
||||
];
|
||||
$job = $this->getMockBuilder(Model\Job::class)->disableOriginalConstructor()->getMock();
|
||||
$job->configuration = $configuration;
|
||||
|
||||
$service = new Service\Worker\Service($this->container, $this->logger);
|
||||
$result = $service->execute($job);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user