Fix phpunit tests

This commit is contained in:
dinamiko 2021-06-04 11:57:25 +02:00
parent 064fab6e64
commit 35c959718e
4 changed files with 44 additions and 18 deletions

View file

@ -231,11 +231,7 @@ class OrderEndpoint {
$response = $this->request( $url, $args );
if ( is_wp_error( $response ) ) {
$error = new RuntimeException(
sprintf(
// translators: %s is the error message.
__( 'Could not create order: %s', 'woocommerce-paypal-payments' ),
$response->get_error_message()
)
__( 'Could not create order.', 'woocommerce-paypal-payments' )
);
$this->logger->log(
'warning',

View file

@ -24,7 +24,7 @@ class PurchaseUnitFactoryTest extends TestCase
$wcOrderId = 1;
$wcOrder = Mockery::mock(\WC_Order::class);
$wcOrder
->expects('get_id')->andReturn($wcOrderId);
->expects('get_order_number')->andReturn($wcOrderId);
$amount = Mockery::mock(Amount::class);
$amountFactory = Mockery::mock(AmountFactory::class);
$amountFactory
@ -88,7 +88,7 @@ class PurchaseUnitFactoryTest extends TestCase
{
$wcOrder = Mockery::mock(\WC_Order::class);
$wcOrder
->expects('get_id')->andReturn(1);
->expects('get_order_number')->andReturn(1);
$amount = Mockery::mock(Amount::class);
$amountFactory = Mockery::mock(AmountFactory::class);
$amountFactory
@ -143,7 +143,7 @@ class PurchaseUnitFactoryTest extends TestCase
{
$wcOrder = Mockery::mock(\WC_Order::class);
$wcOrder
->expects('get_id')->andReturn(1);
->expects('get_order_number')->andReturn(1);
$amount = Mockery::mock(Amount::class);
$amountFactory = Mockery::mock(AmountFactory::class);
$amountFactory

View file

@ -2,8 +2,10 @@
namespace WooCommerce\PayPalCommerce\WcGateway\Assets;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
use WooCommerce\PayPalCommerce\TestCase;
use function Brain\Monkey\Functions\when;
use Mockery;
class SettingsPagesAssetsTest extends TestCase
{
@ -11,8 +13,9 @@ class SettingsPagesAssetsTest extends TestCase
{
$moduleUrl = 'http://example.com/wp-content/plugins/woocommerce-paypal-payments/modules/ppcp-wc-gateway';
$modulePath = '/var/www/html/wp-content/plugins/woocommerce-paypal-payments/modules/ppcp-wc-gateway';
$bearer = Mockery::mock(Bearer::class);
$testee = new SettingsPageAssets($moduleUrl, $modulePath);
$testee = new SettingsPageAssets($moduleUrl, $modulePath, $bearer);
when('is_admin')
->justReturn(true);

View file

@ -6,6 +6,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
use WooCommerce\PayPalCommerce\TestCase;
use WooCommerce\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
@ -20,7 +21,6 @@ use function Brain\Monkey\Functions\when;
class WcGatewayTest extends TestCase
{
public function testProcessPaymentSuccess() {
expect('is_admin')->andReturn(false);
@ -48,6 +48,15 @@ class WcGatewayTest extends TestCase
$state = Mockery::mock(State::class);
$state
->shouldReceive('current_state')->andReturn(State::STATE_ONBOARDED);
$subscriptionHelper = Mockery::mock(SubscriptionHelper::class);
$subscriptionHelper
->shouldReceive('has_subscription')
->with($orderId)
->andReturn(true);
$subscriptionHelper
->shouldReceive('is_subscription_change_payment')
->andReturn(true);
$testee = new PayPalGateway(
$settingsRenderer,
$orderProcessor,
@ -57,7 +66,8 @@ class WcGatewayTest extends TestCase
$sessionHandler,
$refundProcessor,
$state,
$transactionUrlProvider
$transactionUrlProvider,
$subscriptionHelper
);
expect('wc_get_order')
@ -93,7 +103,9 @@ class WcGatewayTest extends TestCase
$transactionUrlProvider = Mockery::mock(TransactionUrlProvider::class);
$state
->shouldReceive('current_state')->andReturn(State::STATE_ONBOARDED);
$testee = new PayPalGateway(
$subscriptionHelper = Mockery::mock(SubscriptionHelper::class);
$testee = new PayPalGateway(
$settingsRenderer,
$orderProcessor,
$authorizedPaymentsProcessor,
@ -102,7 +114,8 @@ class WcGatewayTest extends TestCase
$sessionHandler,
$refundProcessor,
$state,
$transactionUrlProvider
$transactionUrlProvider,
$subscriptionHelper
);
expect('wc_get_order')
@ -152,6 +165,10 @@ class WcGatewayTest extends TestCase
$transactionUrlProvider = Mockery::mock(TransactionUrlProvider::class);
$state
->shouldReceive('current_state')->andReturn(State::STATE_ONBOARDED);
$subscriptionHelper = Mockery::mock(SubscriptionHelper::class);
$subscriptionHelper->shouldReceive('has_subscription')->with($orderId)->andReturn(true);
$subscriptionHelper->shouldReceive('is_subscription_change_payment')->andReturn(true);
$testee = new PayPalGateway(
$settingsRenderer,
$orderProcessor,
@ -161,7 +178,8 @@ class WcGatewayTest extends TestCase
$sessionHandler,
$refundProcessor,
$state,
$transactionUrlProvider
$transactionUrlProvider,
$subscriptionHelper
);
expect('wc_get_order')
@ -174,7 +192,7 @@ class WcGatewayTest extends TestCase
when('wc_get_checkout_url')
->justReturn($redirectUrl);
$result = $testee->process_payment($orderId);
$this->assertEquals(
[
@ -222,6 +240,8 @@ class WcGatewayTest extends TestCase
$transactionUrlProvider = Mockery::mock(TransactionUrlProvider::class);
$state
->shouldReceive('current_state')->andReturn(State::STATE_ONBOARDED);
$subscriptionHelper = Mockery::mock(SubscriptionHelper::class);
$testee = new PayPalGateway(
$settingsRenderer,
$orderProcessor,
@ -231,7 +251,8 @@ class WcGatewayTest extends TestCase
$sessionHandler,
$refundProcessor,
$state,
$transactionUrlProvider
$transactionUrlProvider,
$subscriptionHelper
);
$this->assertTrue($testee->capture_authorized_payment($wcOrder));
@ -276,6 +297,8 @@ class WcGatewayTest extends TestCase
$transactionUrlProvider = Mockery::mock(TransactionUrlProvider::class);
$state
->shouldReceive('current_state')->andReturn(State::STATE_ONBOARDED);
$subscriptionHelper = Mockery::mock(SubscriptionHelper::class);
$testee = new PayPalGateway(
$settingsRenderer,
$orderProcessor,
@ -285,7 +308,8 @@ class WcGatewayTest extends TestCase
$sessionHandler,
$refundProcessor,
$state,
$transactionUrlProvider
$transactionUrlProvider,
$subscriptionHelper
);
$this->assertTrue($testee->capture_authorized_payment($wcOrder));
@ -324,6 +348,8 @@ class WcGatewayTest extends TestCase
$transactionUrlProvider = Mockery::mock(TransactionUrlProvider::class);
$state
->shouldReceive('current_state')->andReturn(State::STATE_ONBOARDED);
$subscriptionHelper = Mockery::mock(SubscriptionHelper::class);
$testee = new PayPalGateway(
$settingsRenderer,
$orderProcessor,
@ -333,7 +359,8 @@ class WcGatewayTest extends TestCase
$sessionHandler,
$refundProcessor,
$state,
$transactionUrlProvider
$transactionUrlProvider,
$subscriptionHelper
);
$this->assertFalse($testee->capture_authorized_payment($wcOrder));