From beafb7b56bd92f463f24b5a6e6fa10c27fe28bcd Mon Sep 17 00:00:00 2001 From: emilicastells Date: Fri, 13 Aug 2021 17:09:27 +0200 Subject: [PATCH] Fix unit tests --- .../ApiClient/Factory/AmountFactoryTest.php | 15 ++++++++++++++- .../PHPUnit/ApiClient/Factory/ItemFactoryTest.php | 14 ++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/PHPUnit/ApiClient/Factory/AmountFactoryTest.php b/tests/PHPUnit/ApiClient/Factory/AmountFactoryTest.php index 713f043c4..72b78312e 100644 --- a/tests/PHPUnit/ApiClient/Factory/AmountFactoryTest.php +++ b/tests/PHPUnit/ApiClient/Factory/AmountFactoryTest.php @@ -3,13 +3,13 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\ApiClient\Factory; -use WooCommerce\PayPalCommerce\ApiClient\Entity\Amount; use WooCommerce\PayPalCommerce\ApiClient\Entity\Item; use WooCommerce\PayPalCommerce\ApiClient\Entity\Money; use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException; use WooCommerce\PayPalCommerce\ApiClient\TestCase; use Mockery; use function Brain\Monkey\Functions\expect; +use function Brain\Monkey\Functions\when; class AmountFactoryTest extends TestCase { @@ -45,6 +45,13 @@ class AmountFactoryTest extends TestCase ->andReturn(7); 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); $this->assertEquals($expectedCurrency, $result->currency_code()); $this->assertEquals((float) 1, $result->value()); @@ -90,6 +97,12 @@ class AmountFactoryTest extends TestCase ->andReturn(0); 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); $this->assertNull($result->breakdown()->discount()); } diff --git a/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php b/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php index 83e99760a..a46e4d67e 100644 --- a/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php +++ b/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php @@ -7,6 +7,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Item; use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException; use WooCommerce\PayPalCommerce\ApiClient\TestCase; use function Brain\Monkey\Functions\expect; +use function Brain\Monkey\Functions\when; use Mockery; class ItemFactoryTest extends TestCase @@ -51,6 +52,13 @@ class ItemFactoryTest extends TestCase expect('wp_strip_all_tags') ->with('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); $this->assertCount(1, $result); @@ -108,6 +116,12 @@ class ItemFactoryTest extends TestCase ->with('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); $item = current($result);