mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Fix tests
This commit is contained in:
parent
5f0c59cd8d
commit
8b94dda4d6
4 changed files with 40 additions and 7 deletions
|
@ -6,6 +6,7 @@ namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Item;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\Helper\CurrencyGetterStub;
|
||||
use WooCommerce\PayPalCommerce\TestCase;
|
||||
use Mockery;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
|
@ -15,6 +16,7 @@ use function Brain\Monkey\Functions\when;
|
|||
class AmountFactoryTest extends TestCase
|
||||
{
|
||||
private $currency = 'EUR';
|
||||
private $currencyGetter;
|
||||
|
||||
private $itemFactory;
|
||||
private $moneyFactory;
|
||||
|
@ -26,7 +28,8 @@ class AmountFactoryTest extends TestCase
|
|||
|
||||
$this->itemFactory = Mockery::mock(ItemFactory::class);
|
||||
$this->moneyFactory = new MoneyFactory();
|
||||
$this->testee = new AmountFactory($this->itemFactory, $this->moneyFactory, $this->currency);
|
||||
$this->currencyGetter = new CurrencyGetterStub($this->currency);
|
||||
$this->testee = new AmountFactory($this->itemFactory, $this->moneyFactory, $this->currencyGetter);
|
||||
}
|
||||
|
||||
public function testFromWcCartDefault()
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
|
|||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Item;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\Helper\CurrencyGetterStub;
|
||||
use WooCommerce\PayPalCommerce\TestCase;
|
||||
use function Brain\Monkey\Functions\expect;
|
||||
use function Brain\Monkey\Functions\when;
|
||||
|
@ -12,9 +13,16 @@ use Mockery;
|
|||
|
||||
class ItemFactoryTest extends TestCase
|
||||
{
|
||||
private $currency = 'EUR';
|
||||
private $currency;
|
||||
|
||||
public function testFromCartDefault()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->currency = new CurrencyGetterStub();
|
||||
}
|
||||
|
||||
public function testFromCartDefault()
|
||||
{
|
||||
$testee = new ItemFactory($this->currency);
|
||||
|
||||
|
@ -169,7 +177,7 @@ class ItemFactoryTest extends TestCase
|
|||
$order = Mockery::mock(\WC_Order::class);
|
||||
$order
|
||||
->expects('get_currency')
|
||||
->andReturn($this->currency);
|
||||
->andReturn($this->currency->get());
|
||||
$order
|
||||
->expects('get_items')
|
||||
->andReturn([$item]);
|
||||
|
@ -228,7 +236,7 @@ class ItemFactoryTest extends TestCase
|
|||
$order = Mockery::mock(\WC_Order::class);
|
||||
$order
|
||||
->expects('get_currency')
|
||||
->andReturn($this->currency);
|
||||
->andReturn($this->currency->get());
|
||||
$order
|
||||
->expects('get_items')
|
||||
->andReturn([$item]);
|
||||
|
@ -357,7 +365,7 @@ class ItemFactoryTest extends TestCase
|
|||
'quantity' => 1,
|
||||
'unit_amount' => (object) [
|
||||
'value' => 1,
|
||||
'currency_code' => $this->currency,
|
||||
'currency_code' => $this->currency->get(),
|
||||
],
|
||||
'category' => Item::DIGITAL_GOODS,
|
||||
];
|
||||
|
|
21
tests/PHPUnit/Helper/CurrencyGetterStub.php
Normal file
21
tests/PHPUnit/Helper/CurrencyGetterStub.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Helper;
|
||||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\CurrencyGetter;
|
||||
|
||||
class CurrencyGetterStub extends CurrencyGetter
|
||||
{
|
||||
private string $currency;
|
||||
|
||||
public function __construct(string $currency = 'EUR')
|
||||
{
|
||||
$this->currency = $currency;
|
||||
}
|
||||
|
||||
public function get(): string
|
||||
{
|
||||
return $this->currency;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Assets;
|
|||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingAgreementsEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Helper\CurrencyGetterStub;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper;
|
||||
use WooCommerce\PayPalCommerce\TestCase;
|
||||
|
@ -25,7 +26,7 @@ class SettingsPagesAssetsTest extends TestCase
|
|||
$modulePath,
|
||||
$subscriptionsHelper,
|
||||
'123',
|
||||
'EUR',
|
||||
new CurrencyGetterStub(),
|
||||
'DE',
|
||||
Mockery::mock(Environment::class),
|
||||
true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue