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

41 lines
1.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;
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()
{
$authorization = Mockery::mock(Authorization::class);
2020-09-01 09:47:36 +03:00
$authorization->shouldReceive('to_array')->andReturn(['id' => 'foo', 'status' => 'CREATED']);
2020-08-31 13:38:54 +03:00
$authorizationsFactory = Mockery::mock(AuthorizationFactory::class);
2020-09-01 09:47:36 +03:00
$authorizationsFactory->shouldReceive('from_paypal_response')->andReturn($authorization);
2020-08-31 13:38:54 +03:00
$response = (object)[
'authorizations' => [
(object)['id' => 'foo', 'status' => 'CREATED'],
],
];
$testee = new PaymentsFactory($authorizationsFactory);
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 = [
'authorizations' => [
['id' => 'foo', 'status' => 'CREATED'],
],
];
2020-09-01 09:47:36 +03:00
$this->assertEquals($expectedToArray, $result->to_array());
2020-08-31 13:38:54 +03:00
}
}