mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Fix unit tests
This commit is contained in:
parent
69b46c33d4
commit
beafb7b56b
2 changed files with 28 additions and 1 deletions
|
@ -3,13 +3,13 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
|
namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
|
||||||
|
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Amount;
|
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Item;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\Item;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
|
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
use function Brain\Monkey\Functions\expect;
|
use function Brain\Monkey\Functions\expect;
|
||||||
|
use function Brain\Monkey\Functions\when;
|
||||||
|
|
||||||
class AmountFactoryTest extends TestCase
|
class AmountFactoryTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -45,6 +45,13 @@ class AmountFactoryTest extends TestCase
|
||||||
->andReturn(7);
|
->andReturn(7);
|
||||||
|
|
||||||
expect('get_woocommerce_currency')->andReturn($expectedCurrency);
|
expect('get_woocommerce_currency')->andReturn($expectedCurrency);
|
||||||
|
|
||||||
|
$woocommerce = Mockery::mock(\WooCommerce::class);
|
||||||
|
$session = Mockery::mock(\WC_Session::class);
|
||||||
|
when('WC')->justReturn($woocommerce);
|
||||||
|
$woocommerce->session = $session;
|
||||||
|
$session->shouldReceive('get')->andReturn([]);
|
||||||
|
|
||||||
$result = $testee->from_wc_cart($cart);
|
$result = $testee->from_wc_cart($cart);
|
||||||
$this->assertEquals($expectedCurrency, $result->currency_code());
|
$this->assertEquals($expectedCurrency, $result->currency_code());
|
||||||
$this->assertEquals((float) 1, $result->value());
|
$this->assertEquals((float) 1, $result->value());
|
||||||
|
@ -90,6 +97,12 @@ class AmountFactoryTest extends TestCase
|
||||||
->andReturn(0);
|
->andReturn(0);
|
||||||
|
|
||||||
expect('get_woocommerce_currency')->andReturn($expectedCurrency);
|
expect('get_woocommerce_currency')->andReturn($expectedCurrency);
|
||||||
|
|
||||||
|
$woocommerce = Mockery::mock(\WooCommerce::class);
|
||||||
|
$session = Mockery::mock(\WC_Session::class);
|
||||||
|
when('WC')->justReturn($woocommerce);
|
||||||
|
$woocommerce->session = $session;
|
||||||
|
$session->shouldReceive('get')->andReturn([]);
|
||||||
$result = $testee->from_wc_cart($cart);
|
$result = $testee->from_wc_cart($cart);
|
||||||
$this->assertNull($result->breakdown()->discount());
|
$this->assertNull($result->breakdown()->discount());
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Item;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
|
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
|
||||||
use function Brain\Monkey\Functions\expect;
|
use function Brain\Monkey\Functions\expect;
|
||||||
|
use function Brain\Monkey\Functions\when;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
|
|
||||||
class ItemFactoryTest extends TestCase
|
class ItemFactoryTest extends TestCase
|
||||||
|
@ -51,6 +52,13 @@ class ItemFactoryTest extends TestCase
|
||||||
expect('wp_strip_all_tags')
|
expect('wp_strip_all_tags')
|
||||||
->with('description')
|
->with('description')
|
||||||
->andReturn('description');
|
->andReturn('description');
|
||||||
|
|
||||||
|
$woocommerce = Mockery::mock(\WooCommerce::class);
|
||||||
|
$session = Mockery::mock(\WC_Session::class);
|
||||||
|
when('WC')->justReturn($woocommerce);
|
||||||
|
$woocommerce->session = $session;
|
||||||
|
$session->shouldReceive('get')->andReturn([]);
|
||||||
|
|
||||||
$result = $testee->from_wc_cart($cart);
|
$result = $testee->from_wc_cart($cart);
|
||||||
|
|
||||||
$this->assertCount(1, $result);
|
$this->assertCount(1, $result);
|
||||||
|
@ -108,6 +116,12 @@ class ItemFactoryTest extends TestCase
|
||||||
->with('description')
|
->with('description')
|
||||||
->andReturn('description');
|
->andReturn('description');
|
||||||
|
|
||||||
|
$woocommerce = Mockery::mock(\WooCommerce::class);
|
||||||
|
$session = Mockery::mock(\WC_Session::class);
|
||||||
|
when('WC')->justReturn($woocommerce);
|
||||||
|
$woocommerce->session = $session;
|
||||||
|
$session->shouldReceive('get')->andReturn([]);
|
||||||
|
|
||||||
$result = $testee->from_wc_cart($cart);
|
$result = $testee->from_wc_cart($cart);
|
||||||
|
|
||||||
$item = current($result);
|
$item = current($result);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue