mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Fix unit tests
This commit is contained in:
parent
12b9905c60
commit
804ff8e526
3 changed files with 192 additions and 35 deletions
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
|
||||
|
||||
use Hamcrest\Matchers;
|
||||
use Requests_Utility_CaseInsensitiveDictionary;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
|
||||
use Woocommerce\PayPalCommerce\ApiClient\Entity\Capture;
|
||||
|
@ -22,13 +23,19 @@ use WooCommerce\PayPalCommerce\ApiClient\Repository\ApplicationContextRepository
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
|
||||
use Mockery;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use function Brain\Monkey\Functions\expect;
|
||||
use function Brain\Monkey\Functions\when;
|
||||
|
||||
class OrderEndpointTest extends TestCase
|
||||
{
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
when('wc_print_r')->returnArg();
|
||||
}
|
||||
|
||||
public function testOrderDefault()
|
||||
{
|
||||
expect('wp_json_encode')->andReturnUsing('json_encode');
|
||||
|
@ -51,10 +58,14 @@ class OrderEndpointTest extends TestCase
|
|||
$intent = 'CAPTURE';
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->shouldNotReceive('log');
|
||||
$logger->shouldReceive('debug');
|
||||
$applicationContextRepository = Mockery::mock(ApplicationContextRepository::class);
|
||||
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
|
||||
$paypalRequestIdRepository
|
||||
->expects('get_for_order_id')->with($orderId)->andReturn('uniqueRequestId');
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
|
||||
$testee = new OrderEndpoint(
|
||||
$host,
|
||||
$bearer,
|
||||
|
@ -66,7 +77,10 @@ class OrderEndpointTest extends TestCase
|
|||
$paypalRequestIdRepository
|
||||
);
|
||||
|
||||
$rawResponse = ['body' => '{"is_correct":true}'];
|
||||
$rawResponse = [
|
||||
'body' => '{"is_correct":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
expect('wp_remote_get')
|
||||
->andReturnUsing(function ($url, $args) use ($rawResponse, $host, $orderId) {
|
||||
if ($url !== $host . 'v2/checkout/orders/' . $orderId) {
|
||||
|
@ -103,10 +117,14 @@ class OrderEndpointTest extends TestCase
|
|||
$intent = 'CAPTURE';
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->shouldReceive('log');
|
||||
$logger->shouldReceive('debug');
|
||||
$applicationContextRepository = Mockery::mock(ApplicationContextRepository::class);
|
||||
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
|
||||
$paypalRequestIdRepository
|
||||
->expects('get_for_order_id')->with($orderId)->andReturn('uniqueRequestId');
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
|
||||
$testee = new OrderEndpoint(
|
||||
$host,
|
||||
$bearer,
|
||||
|
@ -118,7 +136,10 @@ class OrderEndpointTest extends TestCase
|
|||
$paypalRequestIdRepository
|
||||
);
|
||||
|
||||
$rawResponse = ['body' => '{"is_correct":true}'];
|
||||
$rawResponse = [
|
||||
'body' => '{"is_correct":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
expect('wp_remote_get')->andReturn($rawResponse);
|
||||
expect('is_wp_error')->with($rawResponse)->andReturn(true);
|
||||
|
||||
|
@ -140,9 +161,15 @@ class OrderEndpointTest extends TestCase
|
|||
$orderFactory = Mockery::mock(OrderFactory::class);
|
||||
$patchCollectionFactory = Mockery::mock(PatchCollectionFactory::class);
|
||||
$intent = 'CAPTURE';
|
||||
$rawResponse = ['body' => '{"some_error":true}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"some_error":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->shouldReceive('log');
|
||||
$logger->shouldReceive('debug');
|
||||
$applicationContextRepository = Mockery::mock(ApplicationContextRepository::class);
|
||||
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
|
||||
$paypalRequestIdRepository
|
||||
|
@ -176,8 +203,12 @@ class OrderEndpointTest extends TestCase
|
|||
$orderToCapture = Mockery::mock(Order::class);
|
||||
$orderToCapture->expects('status')->andReturn($orderToCaptureStatus);
|
||||
$orderToCapture->expects('id')->andReturn($orderId);
|
||||
|
||||
$rawResponse = ['body' => '{"is_correct":true}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"is_correct":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
$expectedOrder = Mockery::mock(Order::class);
|
||||
$host = 'https://example.com/';
|
||||
$token = Mockery::mock(Token::class);
|
||||
|
@ -202,6 +233,7 @@ class OrderEndpointTest extends TestCase
|
|||
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->shouldNotReceive('log');
|
||||
$logger->shouldReceive('debug');
|
||||
$applicationContextRepository = Mockery::mock(ApplicationContextRepository::class);
|
||||
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
|
||||
$paypalRequestIdRepository
|
||||
|
@ -307,6 +339,7 @@ class OrderEndpointTest extends TestCase
|
|||
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->shouldReceive('log');
|
||||
$logger->shouldReceive('debug');
|
||||
$applicationContextRepository = Mockery::mock(ApplicationContextRepository::class);
|
||||
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
|
||||
$paypalRequestIdRepository
|
||||
|
@ -321,8 +354,12 @@ class OrderEndpointTest extends TestCase
|
|||
$applicationContextRepository,
|
||||
$paypalRequestIdRepository
|
||||
);
|
||||
|
||||
$rawResponse = ['body' => '{"is_error":true}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"is_error":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
expect('wp_remote_get')->andReturn($rawResponse);
|
||||
expect('is_wp_error')->with($rawResponse)->andReturn(true);
|
||||
$this->expectException(RuntimeException::class);
|
||||
|
@ -351,6 +388,7 @@ class OrderEndpointTest extends TestCase
|
|||
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->shouldReceive('log');
|
||||
$logger->shouldReceive('debug');
|
||||
$applicationContextRepository = Mockery::mock(ApplicationContextRepository::class);
|
||||
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
|
||||
$paypalRequestIdRepository
|
||||
|
@ -366,7 +404,12 @@ class OrderEndpointTest extends TestCase
|
|||
$paypalRequestIdRepository
|
||||
);
|
||||
|
||||
$rawResponse = ['body' => '{"some_error":true}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"some_error":true}',
|
||||
'headers' => $headers
|
||||
];
|
||||
expect('wp_remote_get')->andReturn($rawResponse);
|
||||
expect('is_wp_error')->with($rawResponse)->andReturn(false);
|
||||
expect('wp_remote_retrieve_response_code')->with($rawResponse)->andReturn(500);
|
||||
|
@ -396,6 +439,7 @@ class OrderEndpointTest extends TestCase
|
|||
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->shouldNotReceive('log');
|
||||
$logger->shouldReceive('debug');
|
||||
$applicationContextRepository = Mockery::mock(ApplicationContextRepository::class);
|
||||
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
|
||||
$paypalRequestIdRepository
|
||||
|
@ -415,8 +459,12 @@ class OrderEndpointTest extends TestCase
|
|||
)->makePartial();
|
||||
$orderToExpect = Mockery::mock(Order::class);
|
||||
$testee->expects('order')->with($orderId)->andReturn($orderToExpect);
|
||||
|
||||
$rawResponse = ['body' => '{"some_error": "' . ErrorResponse::ORDER_ALREADY_CAPTURED . '"}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"some_error": "' . ErrorResponse::ORDER_ALREADY_CAPTURED . '"}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
expect('wp_remote_get')->andReturn($rawResponse);
|
||||
expect('is_wp_error')->with($rawResponse)->andReturn(false);
|
||||
expect('wp_remote_retrieve_response_code')->with($rawResponse)->andReturn(500);
|
||||
|
@ -436,8 +484,12 @@ class OrderEndpointTest extends TestCase
|
|||
->shouldReceive('purchase_units')
|
||||
->andReturn([]);
|
||||
$orderToCompare = Mockery::mock(Order::class);
|
||||
|
||||
$rawResponse = ['body' => '{"is_correct":true}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"is_correct":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
$expectedOrder = Mockery::mock(Order::class);
|
||||
$host = 'https://example.com/';
|
||||
$token = Mockery::mock(Token::class);
|
||||
|
@ -464,6 +516,7 @@ class OrderEndpointTest extends TestCase
|
|||
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->shouldNotReceive('log');
|
||||
$logger->shouldReceive('debug');
|
||||
$applicationContextRepository = Mockery::mock(ApplicationContextRepository::class);
|
||||
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
|
||||
$paypalRequestIdRepository
|
||||
|
@ -533,8 +586,12 @@ class OrderEndpointTest extends TestCase
|
|||
->shouldReceive('purchase_units')
|
||||
->andReturn([]);
|
||||
$orderToCompare = Mockery::mock(Order::class);
|
||||
|
||||
$rawResponse = ['body' => '{"has_error":true}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"has_error":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
$expectedOrder = Mockery::mock(Order::class);
|
||||
$host = 'https://example.com/';
|
||||
$token = Mockery::mock(Token::class);
|
||||
|
@ -561,6 +618,7 @@ class OrderEndpointTest extends TestCase
|
|||
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->shouldReceive('log');
|
||||
$logger->shouldReceive('debug');
|
||||
$applicationContextRepository = Mockery::mock(ApplicationContextRepository::class);
|
||||
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
|
||||
$paypalRequestIdRepository
|
||||
|
@ -624,8 +682,12 @@ class OrderEndpointTest extends TestCase
|
|||
->shouldReceive('purchase_units')
|
||||
->andReturn([]);
|
||||
$orderToCompare = Mockery::mock(Order::class);
|
||||
|
||||
$rawResponse = ['body' => '{"is_correct":true}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"is_correct":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
$expectedOrder = Mockery::mock(Order::class);
|
||||
$host = 'https://example.com/';
|
||||
$token = Mockery::mock(Token::class);
|
||||
|
@ -652,6 +714,7 @@ class OrderEndpointTest extends TestCase
|
|||
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->shouldReceive('log');
|
||||
$logger->shouldReceive('debug');
|
||||
|
||||
$applicationContextRepository = Mockery::mock(ApplicationContextRepository::class);
|
||||
$paypalRequestIdRepository = Mockery::mock(PayPalRequestIdRepository::class);
|
||||
|
@ -748,7 +811,12 @@ class OrderEndpointTest extends TestCase
|
|||
public function testCreateForPurchaseUnitsDefault()
|
||||
{
|
||||
expect('wp_json_encode')->andReturnUsing('json_encode');
|
||||
$rawResponse = ['body' => '{"success":true}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"success":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
$host = 'https://example.com/';
|
||||
$bearer = Mockery::mock(Bearer::class);
|
||||
$token = Mockery::mock(Token::class);
|
||||
|
@ -772,6 +840,7 @@ class OrderEndpointTest extends TestCase
|
|||
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->shouldNotReceive('log');
|
||||
$logger->shouldReceive('debug');
|
||||
$applicationContext = Mockery::mock(ApplicationContext::class);
|
||||
$applicationContext
|
||||
->expects('to_array')
|
||||
|
@ -844,7 +913,12 @@ class OrderEndpointTest extends TestCase
|
|||
public function testCreateForPurchaseUnitsWithPayer()
|
||||
{
|
||||
expect('wp_json_encode')->andReturnUsing('json_encode');
|
||||
$rawResponse = ['body' => '{"success":true}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"success":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
$host = 'https://example.com/';
|
||||
$token = Mockery::mock(Token::class);
|
||||
$token
|
||||
|
@ -868,6 +942,7 @@ class OrderEndpointTest extends TestCase
|
|||
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->shouldNotReceive('log');
|
||||
$logger->shouldReceive('debug');
|
||||
$applicationContext = Mockery::mock(ApplicationContext::class);
|
||||
$applicationContext
|
||||
->expects('to_array')
|
||||
|
@ -928,7 +1003,12 @@ class OrderEndpointTest extends TestCase
|
|||
public function testCreateForPurchaseUnitsIsWpError()
|
||||
{
|
||||
expect('wp_json_encode')->andReturnUsing('json_encode');
|
||||
$rawResponse = ['body' => '{"success":true}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"success":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
$host = 'https://example.com/';
|
||||
$token = Mockery::mock(Token::class);
|
||||
$token
|
||||
|
@ -943,6 +1023,7 @@ class OrderEndpointTest extends TestCase
|
|||
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->shouldReceive('log');
|
||||
$logger->shouldReceive('debug');
|
||||
$applicationContext = Mockery::mock(ApplicationContext::class);
|
||||
$applicationContext
|
||||
->expects('to_array')
|
||||
|
@ -1006,7 +1087,12 @@ class OrderEndpointTest extends TestCase
|
|||
public function testCreateForPurchaseUnitsIsNot201()
|
||||
{
|
||||
expect('wp_json_encode')->andReturnUsing('json_encode');
|
||||
$rawResponse = ['body' => '{"has_error":true}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"has_error":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
$host = 'https://example.com/';
|
||||
$token = Mockery::mock(Token::class);
|
||||
$token
|
||||
|
@ -1021,6 +1107,7 @@ class OrderEndpointTest extends TestCase
|
|||
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->shouldReceive('log');
|
||||
$logger->shouldReceive('debug');
|
||||
$applicationContext = Mockery::mock(ApplicationContext::class);
|
||||
$applicationContext
|
||||
->expects('to_array')
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Requests_Utility_CaseInsensitiveDictionary;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Token;
|
||||
|
@ -48,7 +49,12 @@ class PaymentTokenEndpointTest extends TestCase
|
|||
{
|
||||
$id = 1;
|
||||
$token = Mockery::mock(Token::class);
|
||||
$rawResponse = ['body' => '{"payment_tokens":[{"id": "123abc"}]}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"payment_tokens":[{"id": "123abc"}]}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
$paymentToken = Mockery::mock(PaymentToken::class);
|
||||
$paymentToken->shouldReceive('id')
|
||||
->andReturn('foo');
|
||||
|
@ -65,6 +71,8 @@ class PaymentTokenEndpointTest extends TestCase
|
|||
$this->factory->shouldReceive('from_paypal_response')
|
||||
->andReturn($paymentToken);
|
||||
|
||||
$this->logger->shouldReceive('debug');
|
||||
|
||||
$result = $this->sut->for_user($id);
|
||||
$this->assertInstanceOf(PaymentToken::class, $result[0]);
|
||||
|
||||
|
@ -74,7 +82,9 @@ class PaymentTokenEndpointTest extends TestCase
|
|||
{
|
||||
$id = 1;
|
||||
$token = Mockery::mock(Token::class);
|
||||
$rawResponse = [];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = ['headers' => $headers,];
|
||||
$this->bearer->shouldReceive('bearer')
|
||||
->andReturn($token);
|
||||
$token->shouldReceive('token')
|
||||
|
@ -84,6 +94,7 @@ class PaymentTokenEndpointTest extends TestCase
|
|||
expect('wp_remote_get')->andReturn($rawResponse);
|
||||
expect('is_wp_error')->with($rawResponse)->andReturn(true);
|
||||
$this->logger->shouldReceive('log');
|
||||
$this->logger->shouldReceive('debug');
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->sut->for_user($id);
|
||||
|
@ -93,7 +104,12 @@ class PaymentTokenEndpointTest extends TestCase
|
|||
{
|
||||
$id = 1;
|
||||
$token = Mockery::mock(Token::class);
|
||||
$rawResponse = ['body' => '{"some_error":true}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"some_error":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
$this->bearer->shouldReceive('bearer')
|
||||
->andReturn($token);
|
||||
$token->shouldReceive('token')
|
||||
|
@ -105,6 +121,7 @@ class PaymentTokenEndpointTest extends TestCase
|
|||
expect('is_wp_error')->with($rawResponse)->andReturn(false);
|
||||
expect('wp_remote_retrieve_response_code')->with($rawResponse)->andReturn(500);
|
||||
$this->logger->shouldReceive('log');
|
||||
$this->logger->shouldReceive('debug');
|
||||
|
||||
$this->expectException(PayPalApiException::class);
|
||||
$this->sut->for_user($id);
|
||||
|
@ -114,7 +131,12 @@ class PaymentTokenEndpointTest extends TestCase
|
|||
{
|
||||
$id = 1;
|
||||
$token = Mockery::mock(Token::class);
|
||||
$rawResponse = ['body' => '{"payment_tokens":[]}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"payment_tokens":[]}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
$this->bearer->shouldReceive('bearer')
|
||||
->andReturn($token);
|
||||
$token->shouldReceive('token')
|
||||
|
@ -126,6 +148,7 @@ class PaymentTokenEndpointTest extends TestCase
|
|||
expect('is_wp_error')->with($rawResponse)->andReturn(false);
|
||||
expect('wp_remote_retrieve_response_code')->with($rawResponse)->andReturn(200);
|
||||
$this->logger->shouldReceive('log');
|
||||
$this->logger->shouldReceive('debug');
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->sut->for_user($id);
|
||||
|
@ -133,7 +156,7 @@ class PaymentTokenEndpointTest extends TestCase
|
|||
|
||||
public function testDeleteToken()
|
||||
{
|
||||
$paymentToken = $paymentToken = Mockery::mock(PaymentToken::class);
|
||||
$paymentToken = Mockery::mock(PaymentToken::class);
|
||||
$paymentToken->shouldReceive('id')
|
||||
->andReturn('foo');
|
||||
$token = Mockery::mock(Token::class);
|
||||
|
@ -142,9 +165,14 @@ class PaymentTokenEndpointTest extends TestCase
|
|||
$token->shouldReceive('token')
|
||||
->andReturn('bearer');
|
||||
|
||||
expect('wp_remote_get')->andReturn();
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
expect('wp_remote_get')->andReturn([
|
||||
'headers' => $headers,
|
||||
]);
|
||||
expect('is_wp_error')->andReturn(false);
|
||||
expect('wp_remote_retrieve_response_code')->andReturn(204);
|
||||
$this->logger->shouldReceive('debug');
|
||||
|
||||
$this->sut->delete_token($paymentToken);
|
||||
}
|
||||
|
@ -160,9 +188,14 @@ class PaymentTokenEndpointTest extends TestCase
|
|||
$token->shouldReceive('token')
|
||||
->andReturn('bearer');
|
||||
|
||||
expect('wp_remote_get')->andReturn();
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
expect('wp_remote_get')->andReturn([
|
||||
'headers' => $headers,
|
||||
]);
|
||||
expect('is_wp_error')->andReturn(true);
|
||||
$this->logger->shouldReceive('log');
|
||||
$this->logger->shouldReceive('debug');
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->sut->delete_token($paymentToken);
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
|
||||
|
||||
use Requests_Utility_CaseInsensitiveDictionary;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Authorization;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\ErrorResponseCollection;
|
||||
|
@ -40,8 +41,14 @@ class PaymentsEndpointTest extends TestCase
|
|||
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->shouldNotReceive('log');
|
||||
$logger->shouldReceive('debug');
|
||||
|
||||
$rawResponse = ['body' => '{"is_correct":true}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"is_correct":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
|
||||
$testee = new PaymentsEndpoint(
|
||||
$host,
|
||||
|
@ -88,8 +95,14 @@ class PaymentsEndpointTest extends TestCase
|
|||
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->shouldReceive('log');
|
||||
$logger->shouldReceive('debug');
|
||||
|
||||
$rawResponse = ['body' => '{"is_correct":true}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"is_correct":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
|
||||
$testee = new PaymentsEndpoint(
|
||||
$host,
|
||||
|
@ -119,10 +132,16 @@ class PaymentsEndpointTest extends TestCase
|
|||
|
||||
$authorizationFactory = Mockery::mock(AuthorizationFactory::class);
|
||||
|
||||
$rawResponse = ['body' => '{"some_error":true}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"some_error":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->shouldReceive('log');
|
||||
$logger->shouldReceive('debug');
|
||||
|
||||
$testee = new PaymentsEndpoint(
|
||||
$host,
|
||||
|
@ -161,8 +180,14 @@ class PaymentsEndpointTest extends TestCase
|
|||
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->shouldNotReceive('log');
|
||||
$logger->shouldReceive('debug');
|
||||
|
||||
$rawResponse = ['body' => '{"is_correct":true}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"is_correct":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
|
||||
$testee = new PaymentsEndpoint(
|
||||
$host,
|
||||
|
@ -212,8 +237,14 @@ class PaymentsEndpointTest extends TestCase
|
|||
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->expects('log');
|
||||
$logger->expects('debug');
|
||||
|
||||
$rawResponse = ['body' => '{"is_correct":true}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"is_correct":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
|
||||
$testee = new PaymentsEndpoint(
|
||||
$host,
|
||||
|
@ -243,10 +274,16 @@ class PaymentsEndpointTest extends TestCase
|
|||
|
||||
$authorizationFactory = Mockery::mock(AuthorizationFactory::class);
|
||||
|
||||
$rawResponse = ['body' => '{"some_error":true}'];
|
||||
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
|
||||
$headers->shouldReceive('getAll');
|
||||
$rawResponse = [
|
||||
'body' => '{"some_error":true}',
|
||||
'headers' => $headers,
|
||||
];
|
||||
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
$logger->expects('log');
|
||||
$logger->expects('debug');
|
||||
|
||||
$testee = new PaymentsEndpoint(
|
||||
$host,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue