feature/cierres (#25)
Varios cambios Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl> Reviewed-on: #25
This commit is contained in:
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);
|
||||
}
|
||||
}
|
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);
|
||||
}
|
||||
}
|
||||
}
|
81
app/tests/unit/src/Service/ValorTest.php
Normal file
81
app/tests/unit/src/Service/ValorTest.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Service;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Incoviba\Service\Valor;
|
||||
use Incoviba\Service;
|
||||
|
||||
class ValorTest extends TestCase
|
||||
{
|
||||
protected Service\UF $ufService;
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->ufService = $this->getMockBuilder(Service\UF::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->ufService->method('get')->willReturn(35000.0);
|
||||
}
|
||||
|
||||
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 / 35000, $result);
|
||||
}
|
||||
|
||||
public static function pesosDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[1000.01, 1000.01*35000, false],
|
||||
[1000, 1000*35000, 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);
|
||||
}
|
||||
}
|
@ -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 Inventario\Service\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class PagoTest extends TestCase
|
||||
{
|
||||
protected float $uf;
|
||||
protected Model\Venta\Pago $pago;
|
||||
protected Repository\Venta\Pago $pagoRepository;
|
||||
protected Repository\Venta\EstadoPago $estadoPagoRepository;
|
||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository;
|
||||
protected Service\UF $ufService;
|
||||
protected Service\Valor $valorService;
|
||||
protected Service\Queue $queueService;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$fecha = new DateTimeImmutable();
|
||||
$this->uf = 37568.84;
|
||||
|
||||
$tipoEstadoPago = $this->getMockBuilder(Model\Venta\TipoEstadoPago::class)->disableOriginalConstructor()->getMock();
|
||||
$tipoEstadoPago->id = 1;
|
||||
$tipoEstadoPago->descripcion = 'depositado';
|
||||
$estadoPago = $this->getMockBuilder(Model\Venta\EstadoPago::class)->disableOriginalConstructor()->getMock();
|
||||
$estadoPago->id = 1;
|
||||
$estadoPago->tipoEstadoPago = $tipoEstadoPago;
|
||||
$estadoPago->fecha = $fecha;
|
||||
|
||||
$this->pago = $this->getMockBuilder(Model\Venta\Pago::class)->disableOriginalConstructor()->getMock();
|
||||
$this->pago->id = 1;
|
||||
$this->pago->fecha = $fecha;
|
||||
$this->pago->uf = $this->uf;
|
||||
$this->pago->currentEstado = $estadoPago;
|
||||
$this->pagoRepository = $this->getMockBuilder(Repository\Venta\Pago::class)->disableOriginalConstructor()->getMock();
|
||||
$this->pagoRepository->method('fetchById')->willReturn($this->pago);
|
||||
$this->pagoRepository->method('edit')->willReturnCallback(function() {
|
||||
$this->pago->uf = $this->uf;
|
||||
return $this->pago;
|
||||
});
|
||||
$this->estadoPagoRepository = $this->getMockBuilder(Repository\Venta\EstadoPago::class)->disableOriginalConstructor()->getMock();
|
||||
$this->estadoPagoRepository->method('fetchCurrentByPago')->with($this->pago->id)->willReturn($estadoPago);
|
||||
$this->tipoEstadoPagoRepository = $this->getMockBuilder(Repository\Venta\TipoEstadoPago::class)->disableOriginalConstructor()->getMock();
|
||||
$this->ufService = $this->getMockBuilder(Service\UF::class)->disableOriginalConstructor()->getMock();
|
||||
$this->ufService->method('get')->with($fecha)->willReturn($this->uf);
|
||||
$this->valorService = $this->getMockBuilder(Service\Valor::class)->disableOriginalConstructor()->getMock();
|
||||
$this->queueService = $this->getMockBuilder(Service\Queue::class)->disableOriginalConstructor()->getMock();
|
||||
}
|
||||
|
||||
public function testUpdateUF(): void
|
||||
{
|
||||
$this->pago->uf = null;
|
||||
|
||||
$pagoService = new Service\Venta\Pago(
|
||||
$this->pagoRepository,
|
||||
$this->estadoPagoRepository,
|
||||
$this->tipoEstadoPagoRepository,
|
||||
$this->ufService,
|
||||
$this->valorService,
|
||||
$this->queueService
|
||||
);
|
||||
|
||||
$status = $pagoService->updateUF($this->pago->id);
|
||||
$pago = $pagoService->getById($this->pago->id);
|
||||
|
||||
$this->assertTrue($status);
|
||||
$this->assertEquals($pago->uf, $this->uf);
|
||||
}
|
||||
}
|
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