Fix phpunit

This commit is contained in:
dinamiko 2022-04-19 10:37:33 +02:00
parent e9cf818799
commit 372884ce16
2 changed files with 33 additions and 1 deletions

View file

@ -59,7 +59,6 @@ class ItemFactory {
$price_without_tax_rounded = round( $price_without_tax, 2 ); $price_without_tax_rounded = round( $price_without_tax, 2 );
$tax = round( $price - $price_without_tax_rounded, 2 ); $tax = round( $price - $price_without_tax_rounded, 2 );
$tax_rates = WC_Tax::get_rates( $product->get_tax_class() ); $tax_rates = WC_Tax::get_rates( $product->get_tax_class() );
$tax = new Money( $tax + $shipping_tax, $this->currency );
$tax = new Money( $tax, $this->currency ); $tax = new Money( $tax, $this->currency );
return new Item( return new Item(
mb_substr( $product->get_name(), 0, 127 ), mb_substr( $product->get_name(), 0, 127 ),

View file

@ -31,6 +31,9 @@ class ItemFactoryTest extends TestCase
$product $product
->expects('is_virtual') ->expects('is_virtual')
->andReturn(false); ->andReturn(false);
$product
->expects('get_tax_class')
->andReturn('');
$items = [ $items = [
[ [
'data' => $product, 'data' => $product,
@ -58,6 +61,9 @@ class ItemFactoryTest extends TestCase
$woocommerce->session = $session; $woocommerce->session = $session;
$session->shouldReceive('get')->andReturn([]); $session->shouldReceive('get')->andReturn([]);
$tax = Mockery::mock('alias:WC_Tax');
$tax->expects('get_rates')->andReturn([]);
$result = $testee->from_wc_cart($cart); $result = $testee->from_wc_cart($cart);
$this->assertCount(1, $result); $this->assertCount(1, $result);
@ -92,6 +98,10 @@ class ItemFactoryTest extends TestCase
$product $product
->expects('is_virtual') ->expects('is_virtual')
->andReturn(true); ->andReturn(true);
$product
->expects('get_tax_class')
->andReturn('');
$items = [ $items = [
[ [
'data' => $product, 'data' => $product,
@ -119,6 +129,9 @@ class ItemFactoryTest extends TestCase
$woocommerce->session = $session; $woocommerce->session = $session;
$session->shouldReceive('get')->andReturn([]); $session->shouldReceive('get')->andReturn([]);
$tax = Mockery::mock('alias:WC_Tax');
$tax->expects('get_rates')->andReturn([]);
$result = $testee->from_wc_cart($cart); $result = $testee->from_wc_cart($cart);
$item = current($result); $item = current($result);
@ -139,6 +152,9 @@ class ItemFactoryTest extends TestCase
$product $product
->expects('get_sku') ->expects('get_sku')
->andReturn('sku'); ->andReturn('sku');
$product
->expects('get_tax_class')
->andReturn('foo');
$product $product
->expects('is_virtual') ->expects('is_virtual')
->andReturn(false); ->andReturn(false);
@ -173,6 +189,9 @@ class ItemFactoryTest extends TestCase
->expects('get_fees') ->expects('get_fees')
->andReturn([]); ->andReturn([]);
$tax = Mockery::mock('alias:WC_Tax');
$tax->expects('get_rates')->andReturn([]);
$result = $testee->from_wc_order($order); $result = $testee->from_wc_order($order);
$this->assertCount(1, $result); $this->assertCount(1, $result);
$item = current($result); $item = current($result);
@ -205,6 +224,10 @@ class ItemFactoryTest extends TestCase
$product $product
->expects('is_virtual') ->expects('is_virtual')
->andReturn(true); ->andReturn(true);
$product
->expects('get_tax_class')
->andReturn('foo');
expect('wp_strip_all_tags') expect('wp_strip_all_tags')
->with('description') ->with('description')
->andReturn('description'); ->andReturn('description');
@ -236,6 +259,9 @@ class ItemFactoryTest extends TestCase
->expects('get_fees') ->expects('get_fees')
->andReturn([]); ->andReturn([]);
$tax = Mockery::mock('alias:WC_Tax');
$tax->expects('get_rates')->andReturn([]);
$result = $testee->from_wc_order($order); $result = $testee->from_wc_order($order);
$item = current($result); $item = current($result);
/** /**
@ -263,6 +289,10 @@ class ItemFactoryTest extends TestCase
$product $product
->expects('is_virtual') ->expects('is_virtual')
->andReturn(true); ->andReturn(true);
$product
->expects('get_tax_class')
->andReturn('foo');
expect('wp_strip_all_tags') expect('wp_strip_all_tags')
->with($description) ->with($description)
->andReturn(mb_substr( $description, 0, 127 )); ->andReturn(mb_substr( $description, 0, 127 ));
@ -294,6 +324,9 @@ class ItemFactoryTest extends TestCase
->expects('get_fees') ->expects('get_fees')
->andReturn([]); ->andReturn([]);
$tax = Mockery::mock('alias:WC_Tax');
$tax->expects('get_rates')->andReturn([]);
$result = $testee->from_wc_order($order); $result = $testee->from_wc_order($order);
$item = current($result); $item = current($result);
/** /**