From 0c2edc1ee7aa82373c42f67e5d30fa6a7539ffdf Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Tue, 25 Apr 2023 12:19:44 +0200 Subject: [PATCH] Fix phpunit --- tests/PHPUnit/TestCase.php | 4 ++++ .../PHPUnit/WcGateway/Gateway/WcGatewayTest.php | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/PHPUnit/TestCase.php b/tests/PHPUnit/TestCase.php index f13497885..1efbdcec4 100644 --- a/tests/PHPUnit/TestCase.php +++ b/tests/PHPUnit/TestCase.php @@ -34,6 +34,10 @@ class TestCase extends \PHPUnit\Framework\TestCase when('get_plugin_data')->justReturn(['Version' => '1.0']); when('plugin_basename')->justReturn('woocommerce-paypal-payments/woocommerce-paypal-payments.php'); + when('wc_clean')->returnArg(); + when('get_transient')->returnArg(); + when('delete_transient')->returnArg(); + setUp(); } diff --git a/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php b/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php index 26107abd0..7fbcd52cf 100644 --- a/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php +++ b/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\WcGateway\Gateway; use Psr\Log\LoggerInterface; +use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint; use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Onboarding\State; use WooCommerce\PayPalCommerce\Session\SessionHandler; @@ -39,6 +40,7 @@ class WcGatewayTest extends TestCase private $paymentTokenRepository; private $logger; private $apiShopCountry; + private $orderEndpoint; public function setUp(): void { parent::setUp(); @@ -64,6 +66,7 @@ class WcGatewayTest extends TestCase ['venmo' => 'Venmo', 'paylater' => 'Pay Later', 'blik' => 'BLIK'] ); $this->apiShopCountry = 'DE'; + $this->orderEndpoint = Mockery::mock(OrderEndpoint::class); $this->onboardingState->shouldReceive('current_state')->andReturn(State::STATE_ONBOARDED); @@ -95,7 +98,8 @@ class WcGatewayTest extends TestCase $this->environment, $this->paymentTokenRepository, $this->logger, - $this->apiShopCountry + $this->apiShopCountry, + $this->orderEndpoint ); } @@ -136,6 +140,9 @@ class WcGatewayTest extends TestCase when('WC')->justReturn($woocommerce); $woocommerce->cart = $cart; $cart->shouldReceive('empty_cart'); + $session = Mockery::mock(\WC_Session::class); + $woocommerce->session = $session; + $session->shouldReceive('get'); $result = $testee->process_payment($orderId); @@ -203,7 +210,13 @@ class WcGatewayTest extends TestCase when('wc_get_checkout_url') ->justReturn($redirectUrl); - $result = $testee->process_payment($orderId); + $woocommerce = Mockery::mock(\WooCommerce::class); + when('WC')->justReturn($woocommerce); + $session = Mockery::mock(\WC_Session::class); + $woocommerce->session = $session; + $session->shouldReceive('get'); + + $result = $testee->process_payment($orderId); $this->assertEquals( [ 'result' => 'failure',