woocommerce-paypal-payments/tests/PHPUnit/ApiClient/Factory/PaymentsFactoryTest.php

51 lines
1.7 KiB
PHP
Raw Normal View History

2020-08-31 13:38:54 +03:00
<?php
declare(strict_types=1);
2020-09-14 07:51:45 +03:00
namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
2020-08-31 13:38:54 +03:00
2020-09-14 07:51:45 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Entity\Authorization;
2021-10-08 10:23:19 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Entity\Capture;
2020-09-14 07:51:45 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payments;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
2020-08-31 13:38:54 +03:00
use Mockery;
class PaymentsFactoryTest extends TestCase
{
public function testFromPayPalResponse()
{
2020-09-28 11:47:24 +03:00
$authorization = Mockery::mock(Authorization::class);
$authorization->shouldReceive('to_array')->andReturn(['id' => 'foo', 'status' => 'CREATED']);
$capture = Mockery::mock(Capture::class);
$capture->shouldReceive('to_array')->andReturn(['id' => 'capture', 'status' => 'CREATED']);
2020-08-31 13:38:54 +03:00
$authorizationsFactory = Mockery::mock(AuthorizationFactory::class);
2020-09-28 11:47:24 +03:00
$authorizationsFactory->shouldReceive('from_paypal_response')->andReturn($authorization);
$captureFactory = Mockery::mock(CaptureFactory::class);
$captureFactory->shouldReceive('from_paypal_response')->andReturn($capture);
2020-08-31 13:38:54 +03:00
$response = (object)[
2020-09-28 11:47:24 +03:00
'authorizations' => [
(object)['id' => 'foo', 'status' => 'CREATED'],
],
'captures' => [
(object)['id' => 'capture', 'status' => 'CREATED'],
],
2020-08-31 13:38:54 +03:00
];
2020-09-28 11:47:24 +03:00
$testee = new PaymentsFactory($authorizationsFactory, $captureFactory);
2020-09-01 09:47:36 +03:00
$result = $testee->from_paypal_response($response);
2020-08-31 13:38:54 +03:00
$this->assertInstanceOf(Payments::class, $result);
$expectedToArray = [
2020-09-28 11:47:24 +03:00
'authorizations' => [
['id' => 'foo', 'status' => 'CREATED'],
],
'captures' => [
['id' => 'capture', 'status' => 'CREATED'],
],
2020-08-31 13:38:54 +03:00
];
2020-09-01 09:47:36 +03:00
$this->assertEquals($expectedToArray, $result->to_array());
2020-08-31 13:38:54 +03:00
}
}