Fix phpunit

This commit is contained in:
Emili Castells Guasch 2023-04-25 12:19:44 +02:00
parent 47c4f4532a
commit 0c2edc1ee7
2 changed files with 19 additions and 2 deletions

View file

@ -34,6 +34,10 @@ class TestCase extends \PHPUnit\Framework\TestCase
when('get_plugin_data')->justReturn(['Version' => '1.0']); when('get_plugin_data')->justReturn(['Version' => '1.0']);
when('plugin_basename')->justReturn('woocommerce-paypal-payments/woocommerce-paypal-payments.php'); when('plugin_basename')->justReturn('woocommerce-paypal-payments/woocommerce-paypal-payments.php');
when('wc_clean')->returnArg();
when('get_transient')->returnArg();
when('delete_transient')->returnArg();
setUp(); setUp();
} }

View file

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway; namespace WooCommerce\PayPalCommerce\WcGateway\Gateway;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\State; use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\Session\SessionHandler; use WooCommerce\PayPalCommerce\Session\SessionHandler;
@ -39,6 +40,7 @@ class WcGatewayTest extends TestCase
private $paymentTokenRepository; private $paymentTokenRepository;
private $logger; private $logger;
private $apiShopCountry; private $apiShopCountry;
private $orderEndpoint;
public function setUp(): void { public function setUp(): void {
parent::setUp(); parent::setUp();
@ -64,6 +66,7 @@ class WcGatewayTest extends TestCase
['venmo' => 'Venmo', 'paylater' => 'Pay Later', 'blik' => 'BLIK'] ['venmo' => 'Venmo', 'paylater' => 'Pay Later', 'blik' => 'BLIK']
); );
$this->apiShopCountry = 'DE'; $this->apiShopCountry = 'DE';
$this->orderEndpoint = Mockery::mock(OrderEndpoint::class);
$this->onboardingState->shouldReceive('current_state')->andReturn(State::STATE_ONBOARDED); $this->onboardingState->shouldReceive('current_state')->andReturn(State::STATE_ONBOARDED);
@ -95,7 +98,8 @@ class WcGatewayTest extends TestCase
$this->environment, $this->environment,
$this->paymentTokenRepository, $this->paymentTokenRepository,
$this->logger, $this->logger,
$this->apiShopCountry $this->apiShopCountry,
$this->orderEndpoint
); );
} }
@ -136,6 +140,9 @@ class WcGatewayTest extends TestCase
when('WC')->justReturn($woocommerce); when('WC')->justReturn($woocommerce);
$woocommerce->cart = $cart; $woocommerce->cart = $cart;
$cart->shouldReceive('empty_cart'); $cart->shouldReceive('empty_cart');
$session = Mockery::mock(\WC_Session::class);
$woocommerce->session = $session;
$session->shouldReceive('get');
$result = $testee->process_payment($orderId); $result = $testee->process_payment($orderId);
@ -203,7 +210,13 @@ class WcGatewayTest extends TestCase
when('wc_get_checkout_url') when('wc_get_checkout_url')
->justReturn($redirectUrl); ->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( $this->assertEquals(
[ [
'result' => 'failure', 'result' => 'failure',