woocommerce-paypal-payments/tests/PHPUnit/ApiClient/Factory/PaymentsFactoryTest.php
2020-08-31 13:38:54 +03:00

40 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\ApiClient\Factory;
use Inpsyde\PayPalCommerce\ApiClient\Entity\Authorization;
use Inpsyde\PayPalCommerce\ApiClient\Entity\Payments;
use Inpsyde\PayPalCommerce\ApiClient\TestCase;
use Mockery;
class PaymentsFactoryTest extends TestCase
{
public function testFromPayPalResponse()
{
$authorization = Mockery::mock(Authorization::class);
$authorization->shouldReceive('toArray')->andReturn(['id' => 'foo', 'status' => 'CREATED']);
$authorizationsFactory = Mockery::mock(AuthorizationFactory::class);
$authorizationsFactory->shouldReceive('fromPayPalRequest')->andReturn($authorization);
$response = (object)[
'authorizations' => [
(object)['id' => 'foo', 'status' => 'CREATED'],
],
];
$testee = new PaymentsFactory($authorizationsFactory);
$result = $testee->fromPayPalResponse($response);
$this->assertInstanceOf(Payments::class, $result);
$expectedToArray = [
'authorizations' => [
['id' => 'foo', 'status' => 'CREATED'],
],
];
$this->assertEquals($expectedToArray, $result->toArray());
}
}