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

62 lines
2.2 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;
2023-08-04 14:18:27 +01:00
use WooCommerce\PayPalCommerce\ApiClient\Entity\Refund;
2022-02-09 16:28:27 +02:00
use WooCommerce\PayPalCommerce\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']);
2023-08-04 14:18:27 +01:00
$refund = Mockery::mock(Refund::class);
$refund->shouldReceive('to_array')->andReturn(['id' => 'refund', '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);
2023-08-04 14:18:27 +01:00
$refundFactory = Mockery::mock(RefundFactory::class);
$refundFactory->shouldReceive('from_paypal_response')->andReturn($refund);
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'],
],
2023-08-04 14:18:27 +01:00
'refunds' => [
(object)['id' => 'refund', 'status' => 'CREATED'],
],
2020-08-31 13:38:54 +03:00
];
2023-08-04 14:18:27 +01:00
$testee = new PaymentsFactory($authorizationsFactory, $captureFactory, $refundFactory);
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'],
],
2023-08-04 14:18:27 +01:00
'refunds' => [
['id' => 'refund', '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
}
}