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); } }