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