Merge branch 'trunk' into PCP-1393-update-to-vault-v-3

# Conflicts:
#	modules/ppcp-api-client/services.php
#	modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php
#	tests/PHPUnit/WcGateway/Processor/OrderProcessorTest.php
This commit is contained in:
Pedro Silva 2023-11-24 11:20:15 +00:00
commit fb1ceeba76
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
27 changed files with 658 additions and 231 deletions

View file

@ -0,0 +1,52 @@
<?php
namespace WooCommerce\PayPalCommerce\Api;
use Mockery;
use RuntimeException;
use WC_Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ModularTestCase;
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor;
class CreateOrderForWcOrderTest extends ModularTestCase
{
private $orderProcesor;
public function setUp(): void {
parent::setUp();
$this->orderProcesor = Mockery::mock(OrderProcessor::class);
$this->bootstrapModule([
'wcgateway.order-processor' => function () {
return $this->orderProcesor;
},
]);
}
public function testSuccess(): void {
$wcOrder = Mockery::mock(WC_Order::class);
$ret = Mockery::mock(Order::class);
$this->orderProcesor
->expects('create_order')
->with($wcOrder)
->andReturn($ret)
->once();
self::assertEquals($ret, ppcp_create_paypal_order_for_wc_order($wcOrder));
}
public function testFailure(): void {
$wcOrder = Mockery::mock(WC_Order::class);
$this->orderProcesor
->expects('create_order')
->with($wcOrder)
->andThrow(new RuntimeException())
->once();
$this->expectException(RuntimeException::class);
ppcp_create_paypal_order_for_wc_order($wcOrder);
}
}

View file

@ -41,7 +41,9 @@ class ModularTestCase extends TestCase
$wpdb->postmeta = '';
!defined('PAYPAL_API_URL') && define('PAYPAL_API_URL', 'https://api-m.paypal.com');
!defined('PAYPAL_URL') && define( 'PAYPAL_URL', 'https://www.paypal.com' );
!defined('PAYPAL_SANDBOX_API_URL') && define('PAYPAL_SANDBOX_API_URL', 'https://api-m.sandbox.paypal.com');
!defined('PAYPAL_SANDBOX_URL') && define( 'PAYPAL_SANDBOX_URL', 'https://www.sandbox.paypal.com' );
!defined('PAYPAL_INTEGRATION_DATE') && define('PAYPAL_INTEGRATION_DATE', '2020-10-15');
!defined('PPCP_FLAG_SUBSCRIPTION') && define('PPCP_FLAG_SUBSCRIPTION', true);

View file

@ -3,6 +3,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway;
use Exception;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
@ -106,7 +107,11 @@ class WcGatewayTest extends TestCase
$this->paymentTokenRepository,
$this->logger,
$this->apiShopCountry,
$this->orderEndpoint
$this->orderEndpoint,
function ($id) {
return 'checkoutnow=' . $id;
},
'Pay via PayPal'
);
}
@ -204,13 +209,10 @@ class WcGatewayTest extends TestCase
public function testProcessPaymentFails() {
$orderId = 1;
$wcOrder = Mockery::mock(\WC_Order::class);
$lastError = 'some-error';
$error = 'some-error';
$this->orderProcessor
->expects('process')
->andReturnFalse();
$this->orderProcessor
->expects('last_error')
->andReturn($lastError);
->andThrow(new Exception($error));
$this->subscriptionHelper->shouldReceive('has_subscription')->with($orderId)->andReturn(true);
$this->subscriptionHelper->shouldReceive('is_subscription_change_payment')->andReturn(true);
$wcOrder->shouldReceive('update_status')->andReturn(true);
@ -223,7 +225,7 @@ class WcGatewayTest extends TestCase
$this->sessionHandler
->shouldReceive('destroy_session_data');
expect('wc_add_notice')
->with($lastError, 'error');
->with($error, 'error');
$redirectUrl = 'http://example.com/checkout';

View file

@ -3,6 +3,10 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Processor;
use Exception;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\Dictionary;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
@ -142,7 +146,10 @@ class OrderProcessorTest extends TestCase
$logger,
$this->environment,
$subscription_helper,
$order_helper
$order_helper,
Mockery::mock(PurchaseUnitFactory::class),
Mockery::mock(PayerFactory::class),
Mockery::mock(ShippingPreferenceFactory::class)
);
$wcOrder
@ -172,7 +179,9 @@ class OrderProcessorTest extends TestCase
$order_helper->shouldReceive('contains_physical_goods')->andReturn(true);
$this->assertTrue($testee->process($wcOrder));
$testee->process($wcOrder);
$this->expectNotToPerformAssertions();
}
public function testCapture() {
@ -267,7 +276,10 @@ class OrderProcessorTest extends TestCase
$logger,
$this->environment,
$subscription_helper,
$order_helper
$order_helper,
Mockery::mock(PurchaseUnitFactory::class),
Mockery::mock(PayerFactory::class),
Mockery::mock(ShippingPreferenceFactory::class)
);
$wcOrder
@ -292,7 +304,9 @@ class OrderProcessorTest extends TestCase
$order_helper->shouldReceive('contains_physical_goods')->andReturn(true);
$this->assertTrue($testee->process($wcOrder));
$testee->process($wcOrder);
$this->expectNotToPerformAssertions();
}
public function testError() {
@ -374,7 +388,10 @@ class OrderProcessorTest extends TestCase
$logger,
$this->environment,
$subscription_helper,
$order_helper
$order_helper,
Mockery::mock(PurchaseUnitFactory::class),
Mockery::mock(PayerFactory::class),
Mockery::mock(ShippingPreferenceFactory::class)
);
$wcOrder
@ -393,8 +410,8 @@ class OrderProcessorTest extends TestCase
$order_helper->shouldReceive('contains_physical_goods')->andReturn(true);
$this->assertFalse($testee->process($wcOrder));
$this->assertNotEmpty($testee->last_error());
$this->expectException(Exception::class);
$testee->process($wcOrder);
}