From 372884ce16172891bc642159121399f7520b7c8e Mon Sep 17 00:00:00 2001 From: dinamiko Date: Tue, 19 Apr 2022 10:37:33 +0200 Subject: [PATCH] Fix phpunit --- .../src/Factory/ItemFactory.php | 1 - .../ApiClient/Factory/ItemFactoryTest.php | 33 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-api-client/src/Factory/ItemFactory.php b/modules/ppcp-api-client/src/Factory/ItemFactory.php index 3bd277807..cdd8692e0 100644 --- a/modules/ppcp-api-client/src/Factory/ItemFactory.php +++ b/modules/ppcp-api-client/src/Factory/ItemFactory.php @@ -59,7 +59,6 @@ class ItemFactory { $price_without_tax_rounded = round( $price_without_tax, 2 ); $tax = round( $price - $price_without_tax_rounded, 2 ); $tax_rates = WC_Tax::get_rates( $product->get_tax_class() ); - $tax = new Money( $tax + $shipping_tax, $this->currency ); $tax = new Money( $tax, $this->currency ); return new Item( mb_substr( $product->get_name(), 0, 127 ), diff --git a/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php b/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php index ee89d6f5c..c323c62ab 100644 --- a/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php +++ b/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php @@ -31,6 +31,9 @@ class ItemFactoryTest extends TestCase $product ->expects('is_virtual') ->andReturn(false); + $product + ->expects('get_tax_class') + ->andReturn(''); $items = [ [ 'data' => $product, @@ -58,6 +61,9 @@ class ItemFactoryTest extends TestCase $woocommerce->session = $session; $session->shouldReceive('get')->andReturn([]); + $tax = Mockery::mock('alias:WC_Tax'); + $tax->expects('get_rates')->andReturn([]); + $result = $testee->from_wc_cart($cart); $this->assertCount(1, $result); @@ -92,6 +98,10 @@ class ItemFactoryTest extends TestCase $product ->expects('is_virtual') ->andReturn(true); + $product + ->expects('get_tax_class') + ->andReturn(''); + $items = [ [ 'data' => $product, @@ -119,6 +129,9 @@ class ItemFactoryTest extends TestCase $woocommerce->session = $session; $session->shouldReceive('get')->andReturn([]); + $tax = Mockery::mock('alias:WC_Tax'); + $tax->expects('get_rates')->andReturn([]); + $result = $testee->from_wc_cart($cart); $item = current($result); @@ -139,6 +152,9 @@ class ItemFactoryTest extends TestCase $product ->expects('get_sku') ->andReturn('sku'); + $product + ->expects('get_tax_class') + ->andReturn('foo'); $product ->expects('is_virtual') ->andReturn(false); @@ -173,6 +189,9 @@ class ItemFactoryTest extends TestCase ->expects('get_fees') ->andReturn([]); + $tax = Mockery::mock('alias:WC_Tax'); + $tax->expects('get_rates')->andReturn([]); + $result = $testee->from_wc_order($order); $this->assertCount(1, $result); $item = current($result); @@ -205,6 +224,10 @@ class ItemFactoryTest extends TestCase $product ->expects('is_virtual') ->andReturn(true); + $product + ->expects('get_tax_class') + ->andReturn('foo'); + expect('wp_strip_all_tags') ->with('description') ->andReturn('description'); @@ -236,6 +259,9 @@ class ItemFactoryTest extends TestCase ->expects('get_fees') ->andReturn([]); + $tax = Mockery::mock('alias:WC_Tax'); + $tax->expects('get_rates')->andReturn([]); + $result = $testee->from_wc_order($order); $item = current($result); /** @@ -263,6 +289,10 @@ class ItemFactoryTest extends TestCase $product ->expects('is_virtual') ->andReturn(true); + $product + ->expects('get_tax_class') + ->andReturn('foo'); + expect('wp_strip_all_tags') ->with($description) ->andReturn(mb_substr( $description, 0, 127 )); @@ -294,6 +324,9 @@ class ItemFactoryTest extends TestCase ->expects('get_fees') ->andReturn([]); + $tax = Mockery::mock('alias:WC_Tax'); + $tax->expects('get_rates')->andReturn([]); + $result = $testee->from_wc_order($order); $item = current($result); /**