Servicios para Toku
This commit is contained in:
182
app/tests/unit/src/Service/MediosPago/Toku/CustomerTest.php
Normal file
182
app/tests/unit/src/Service/MediosPago/Toku/CustomerTest.php
Normal file
@ -0,0 +1,182 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Service\MediosPago\Toku;
|
||||
|
||||
use PDO;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Faker;
|
||||
use GuzzleHttp\Client;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
|
||||
class CustomerTest extends TestCase
|
||||
{
|
||||
protected Client $client;
|
||||
protected Model\MediosPago\Toku\Customer $customer;
|
||||
protected Repository\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);
|
||||
|
||||
$this->customer = $this->getMockBuilder(Model\MediosPago\Toku\Customer::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->customer->id = $faker->randomNumber();
|
||||
$this->customer->persona = $persona;
|
||||
$this->customer->toku_id = $faker->ean13();
|
||||
$this->customer->method('jsonSerialize')->willReturn([
|
||||
'id' => $this->customer->id,
|
||||
'rut' => implode('', [$persona->rut, $persona->digito]),
|
||||
'toku_id' => $this->customer->toku_id
|
||||
]);
|
||||
|
||||
$this->customerRepository = $this->getMockBuilder(Repository\MediosPago\Toku\Customer::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->customerRepository->method('fetchById')->willReturn($this->customer);
|
||||
$this->customerRepository->method('fetchByRut')->willReturn($this->customer);
|
||||
|
||||
$this->getData = [
|
||||
'id' => $this->customer->id,
|
||||
'external_id' => implode('', [$persona->rut, $persona->digito]),
|
||||
'government_id' => implode('', [$persona->rut, $persona->digito]),
|
||||
'email' => $persona->datos()->email,
|
||||
'name' => implode(' ', [$persona->nombres, $persona->apellidoPaterno, $persona->apellidoMaterno]),
|
||||
'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' => implode('', [$persona->rut, $persona->digito]),
|
||||
'government_id' => implode('', [$persona->rut, $persona->digito]),
|
||||
'email' => $persona->datos()->email,
|
||||
'name' => implode(' ', [$persona->nombres, $persona->apellidoPaterno, $persona->apellidoMaterno]),
|
||||
'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\MediosPago\Toku\Customer($this->client, $this->customerRepository);
|
||||
|
||||
$this->assertEquals(json_decode(json_encode($this->customer), true), $service->getById($this->customer->id));
|
||||
}
|
||||
public function testGet(): void
|
||||
{
|
||||
$service = new Service\MediosPago\Toku\Customer($this->client, $this->customerRepository);
|
||||
|
||||
$this->assertArrayIsEqualToArrayIgnoringListOfKeys($this->getData, $service->get($this->customer->toku_id), []);
|
||||
}
|
||||
public function testAdd(): void
|
||||
{
|
||||
$service = new Service\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\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\MediosPago\Toku\Customer($this->client, $this->customerRepository);
|
||||
|
||||
$this->expectNotToPerformAssertions();
|
||||
$service->delete($this->customer->toku_id);
|
||||
}
|
||||
}
|
200
app/tests/unit/src/Service/MediosPago/Toku/InvoiceTest.php
Normal file
200
app/tests/unit/src/Service/MediosPago/Toku/InvoiceTest.php
Normal file
@ -0,0 +1,200 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Service\MediosPago\Toku;
|
||||
|
||||
use PDO;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Faker;
|
||||
use GuzzleHttp\Client;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
|
||||
class InvoiceTest extends TestCase
|
||||
{
|
||||
protected Client $client;
|
||||
protected Model\MediosPago\Toku\Invoice $invoice;
|
||||
protected Repository\MediosPago\Toku\Invoice $invoiceRepository;
|
||||
protected Model\Venta\Cuota $cuota;
|
||||
protected array $getData;
|
||||
protected array $saveData;
|
||||
|
||||
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\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\MediosPago\Toku\Subscription::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$subscription->id = $faker->randomNumber();
|
||||
$subscription->venta = $venta;
|
||||
$subscription->toku_id = $faker->ean13();
|
||||
|
||||
$pago = $this->getMockBuilder(Model\Venta\Pago::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$pago->fecha = $faker->dateTime();
|
||||
$pago->valor = $faker->randomNumber(6, true);
|
||||
$pago->method('valor')->willReturn($faker->randomFloat(3, true));
|
||||
$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\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\MediosPago\Toku\Invoice::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->invoiceRepository->method('fetchById')->willReturn($this->invoice);
|
||||
$this->invoiceRepository->method('fetchByCuota')->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);
|
||||
}
|
||||
|
||||
public function testGetById(): void
|
||||
{
|
||||
$service = new Service\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository);
|
||||
$this->assertEquals(json_decode(json_encode($this->invoice), true), $service->getById($this->invoice->toku_id));
|
||||
}
|
||||
public function testGet(): void
|
||||
{
|
||||
$service = new Service\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository);
|
||||
|
||||
$this->assertEquals($this->getData, $service->get($this->invoice->toku_id));
|
||||
}
|
||||
public function testAdd(): void
|
||||
{
|
||||
$service = new Service\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository);
|
||||
|
||||
$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\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository);
|
||||
|
||||
$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\MediosPago\Toku\Invoice($this->client, $this->invoiceRepository);
|
||||
|
||||
$this->expectNotToPerformAssertions();
|
||||
$service->delete($this->invoice->toku_id);
|
||||
}
|
||||
}
|
183
app/tests/unit/src/Service/MediosPago/Toku/SubscriptionTest.php
Normal file
183
app/tests/unit/src/Service/MediosPago/Toku/SubscriptionTest.php
Normal file
@ -0,0 +1,183 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Service\MediosPago\Toku;
|
||||
|
||||
use PDO;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Faker;
|
||||
use GuzzleHttp\Client;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
|
||||
class SubscriptionTest extends TestCase
|
||||
{
|
||||
protected Client $client;
|
||||
protected Model\MediosPago\Toku\Subscription $subscription;
|
||||
protected Repository\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\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\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\MediosPago\Toku\Subscription::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->subscriptionRepository->method('fetchById')->willReturn($this->subscription);
|
||||
$this->subscriptionRepository->method('fetchByVenta')->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\MediosPago\Toku\Subscription($this->client, $this->subscriptionRepository);
|
||||
|
||||
$this->assertEquals(json_decode(json_encode($this->subscription), true), $service->getById($this->subscription->toku_id));
|
||||
}
|
||||
public function testGet(): void
|
||||
{
|
||||
$service = new Service\MediosPago\Toku\Subscription($this->client, $this->subscriptionRepository);
|
||||
|
||||
$this->assertArrayIsEqualToArrayIgnoringListOfKeys($this->getData, $service->get($this->subscription->toku_id), []);
|
||||
}
|
||||
public function testAdd(): void
|
||||
{
|
||||
$service = new Service\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\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\MediosPago\Toku\Subscription($this->client, $this->subscriptionRepository);
|
||||
|
||||
$this->expectNotToPerformAssertions();
|
||||
$service->delete($this->subscription->toku_id);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user