Merge branch 'trunk' into pcp-401-custom-order-id

This commit is contained in:
Alex P 2021-11-23 12:51:26 +02:00
commit 6e6b4c4b40
18 changed files with 201 additions and 205 deletions

View file

@ -11,6 +11,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use Mockery;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use function Brain\Monkey\Functions\expect;
use function Brain\Monkey\Functions\when;
@ -20,6 +21,7 @@ class IdentityTokenTest extends TestCase
private $bearer;
private $logger;
private $prefix;
private $settings;
private $sut;
public function setUp(): void
@ -30,7 +32,9 @@ class IdentityTokenTest extends TestCase
$this->bearer = Mockery::mock(Bearer::class);
$this->logger = Mockery::mock(LoggerInterface::class);
$this->prefix = 'prefix';
$this->sut = new IdentityToken($this->host, $this->bearer, $this->logger, $this->prefix);
$this->settings = Mockery::mock(Settings::class);
$this->sut = new IdentityToken($this->host, $this->bearer, $this->logger, $this->prefix, $this->settings);
}
public function testGenerateForCustomerReturnsToken()
@ -46,6 +50,8 @@ class IdentityTokenTest extends TestCase
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
$headers->shouldReceive('getAll');
$this->logger->shouldReceive('debug');
$this->settings->shouldReceive('has')->andReturn(true);
$this->settings->shouldReceive('get')->andReturn(true);
$rawResponse = [
'body' => '{"client_token":"abc123", "expires_in":3600}',
@ -96,6 +102,8 @@ class IdentityTokenTest extends TestCase
when('wc_print_r')->returnArg();
$this->logger->shouldReceive('log');
$this->logger->shouldReceive('debug');
$this->settings->shouldReceive('has')->andReturn(true);
$this->settings->shouldReceive('get')->andReturn(true);
$this->expectException(RuntimeException::class);
$this->sut->generate_for_customer(1);
@ -120,6 +128,8 @@ class IdentityTokenTest extends TestCase
when('wc_print_r')->returnArg();
$this->logger->shouldReceive('log');
$this->logger->shouldReceive('debug');
$this->settings->shouldReceive('has')->andReturn(true);
$this->settings->shouldReceive('get')->andReturn(true);
$this->expectException(PayPalApiException::class);
$this->sut->generate_for_customer(1);

View file

@ -26,6 +26,7 @@ class PurchaseUnitFactoryTest extends TestCase
$wcOrder = Mockery::mock(\WC_Order::class);
$wcOrder->expects('get_order_number')->andReturn($this->wcOrderNumber);
$wcOrder->expects('get_id')->andReturn($this->wcOrderId);
$wcOrder->expects('get_meta')->andReturn('');
$amount = Mockery::mock(Amount::class);
$amountFactory = Mockery::mock(AmountFactory::class);
$amountFactory
@ -90,6 +91,7 @@ class PurchaseUnitFactoryTest extends TestCase
$wcOrder = Mockery::mock(\WC_Order::class);
$wcOrder->expects('get_order_number')->andReturn($this->wcOrderNumber);
$wcOrder->expects('get_id')->andReturn($this->wcOrderId);
$wcOrder->expects('get_meta')->andReturn('');
$amount = Mockery::mock(Amount::class);
$amountFactory = Mockery::mock(AmountFactory::class);
$amountFactory
@ -145,6 +147,7 @@ class PurchaseUnitFactoryTest extends TestCase
$wcOrder = Mockery::mock(\WC_Order::class);
$wcOrder->expects('get_order_number')->andReturn($this->wcOrderNumber);
$wcOrder->expects('get_id')->andReturn($this->wcOrderId);
$wcOrder->expects('get_meta')->andReturn('');
$amount = Mockery::mock(Amount::class);
$amountFactory = Mockery::mock(AmountFactory::class);
$amountFactory

View file

@ -42,7 +42,7 @@ class WcGatewayTest extends TestCase
$orderId = 1;
$wcOrder = Mockery::mock(\WC_Order::class);
$wcOrder->shouldReceive('get_customer_id')->andReturn(1);
$wcOrder->shouldReceive('get_meta')->andReturn('');
$settingsRenderer = Mockery::mock(SettingsRenderer::class);
$orderProcessor = Mockery::mock(OrderProcessor::class);
$orderProcessor
@ -106,6 +106,12 @@ class WcGatewayTest extends TestCase
when('wc_get_checkout_url')
->justReturn('test');
$woocommerce = Mockery::mock(\WooCommerce::class);
$cart = Mockery::mock(\WC_Cart::class);
when('WC')->justReturn($woocommerce);
$woocommerce->cart = $cart;
$cart->shouldReceive('empty_cart');
$result = $testee->process_payment($orderId);
$this->assertIsArray($result);

View file

@ -88,8 +88,6 @@ class OrderProcessorTest extends TestCase
$sessionHandler
->expects('order')
->andReturn($currentOrder);
$sessionHandler
->expects('destroy_session_data');
$orderEndpoint = Mockery::mock(OrderEndpoint::class);
$orderEndpoint
@ -129,15 +127,6 @@ class OrderProcessorTest extends TestCase
$this->environment
);
$cart = Mockery::mock(\WC_Cart::class);
$cart
->expects('empty_cart');
$woocommerce = Mockery::mock(\WooCommerce::class);
when('WC')
->justReturn($woocommerce);
$woocommerce->cart = $cart;
$wcOrder
->expects('update_meta_data')
->with(
@ -211,8 +200,6 @@ class OrderProcessorTest extends TestCase
$sessionHandler
->expects('order')
->andReturn($currentOrder);
$sessionHandler
->expects('destroy_session_data');
$orderEndpoint = Mockery::mock(OrderEndpoint::class);
$orderEndpoint
->expects('patch_order_with')
@ -234,21 +221,8 @@ class OrderProcessorTest extends TestCase
->shouldReceive('has')
->andReturnFalse();
$cart = Mockery::mock(\WC_Cart::class);
$cart
->shouldReceive('empty_cart');
$woocommerce = Mockery::Mock(\Woocommerce::class);
$woocommerce
->shouldReceive('__get')
->with('cart')
->set('cart', $cart);
when('WC')
->justReturn($woocommerce);
$logger = Mockery::mock(LoggerInterface::class);
$testee = new OrderProcessor(
$sessionHandler,
$orderEndpoint,
@ -260,15 +234,6 @@ class OrderProcessorTest extends TestCase
$this->environment
);
$cart = Mockery::mock(\WC_Cart::class);
$cart
->expects('empty_cart');
$woocommerce = Mockery::mock(\WooCommerce::class);
$woocommerce->cart = $cart;
when('WC')
->justReturn($woocommerce);
$wcOrder
->expects('update_meta_data')
->with(