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\AuthorizationStatus;
|
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
2022-02-09 16:28:27 +02:00
|
|
|
use WooCommerce\PayPalCommerce\TestCase;
|
2020-08-31 13:38:54 +03:00
|
|
|
|
|
|
|
class AuthorizationFactoryTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testFromPayPalRequestDefault()
|
|
|
|
{
|
|
|
|
$response = (object)[
|
|
|
|
'id' => 'foo',
|
|
|
|
'status' => 'CAPTURED',
|
|
|
|
];
|
2024-01-31 16:51:33 +04:00
|
|
|
$fraudProcessorResponseFactory = \Mockery::mock(FraudProcessorResponseFactory::class);
|
2020-08-31 13:38:54 +03:00
|
|
|
|
2024-01-31 16:51:33 +04:00
|
|
|
$testee = new AuthorizationFactory($fraudProcessorResponseFactory);
|
2020-09-01 09:47:36 +03:00
|
|
|
$result = $testee->from_paypal_response($response);
|
2020-08-31 13:38:54 +03:00
|
|
|
|
|
|
|
$this->assertInstanceOf(Authorization::class, $result);
|
|
|
|
|
|
|
|
$this->assertEquals('foo', $result->id());
|
|
|
|
$this->assertInstanceOf(AuthorizationStatus::class, $result->status());
|
|
|
|
|
|
|
|
$this->assertEquals('CAPTURED', $result->status()->name());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testReturnExceptionIdIsMissing()
|
|
|
|
{
|
|
|
|
$this->expectException(RuntimeException::class);
|
|
|
|
$response = (object)[
|
|
|
|
'status' => 'CAPTURED',
|
|
|
|
];
|
|
|
|
|
2024-01-31 16:51:33 +04:00
|
|
|
$fraudProcessorResponseFactory = \Mockery::mock(FraudProcessorResponseFactory::class);
|
|
|
|
|
|
|
|
$testee = new AuthorizationFactory($fraudProcessorResponseFactory);
|
2020-09-01 09:47:36 +03:00
|
|
|
$testee->from_paypal_response($response);
|
2020-08-31 13:38:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testReturnExceptionStatusIsMissing()
|
|
|
|
{
|
|
|
|
$this->expectException(RuntimeException::class);
|
|
|
|
$response = (object)[
|
|
|
|
'id' => 'foo',
|
|
|
|
];
|
|
|
|
|
2024-01-31 16:51:33 +04:00
|
|
|
$fraudProcessorResponseFactory = \Mockery::mock(FraudProcessorResponseFactory::class);
|
|
|
|
|
|
|
|
$testee = new AuthorizationFactory($fraudProcessorResponseFactory);
|
2020-09-01 09:47:36 +03:00
|
|
|
$testee->from_paypal_response($response);
|
2020-08-31 13:38:54 +03:00
|
|
|
}
|
|
|
|
}
|