woocommerce-paypal-payments/tests/PHPUnit/ApiClient/Entity/AmountBreakdownTest.php

124 lines
4.4 KiB
PHP
Raw Normal View History

2020-08-31 13:38:54 +03:00
<?php
declare(strict_types=1);
2020-09-14 07:51:45 +03:00
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
2020-08-31 13:38:54 +03:00
2022-02-09 16:28:27 +02:00
use WooCommerce\PayPalCommerce\TestCase;
2020-08-31 13:38:54 +03:00
use Mockery;
class AmountBreakdownTest extends TestCase
{
public function test()
{
$itemTotal = Mockery::mock(Money::class);
$itemTotal
2020-09-01 09:47:36 +03:00
->expects('to_array')->andReturn(['itemTotal']);
2020-08-31 13:38:54 +03:00
$shipping = Mockery::mock(Money::class);
$shipping
2020-09-01 09:47:36 +03:00
->expects('to_array')->andReturn(['shipping']);
2020-08-31 13:38:54 +03:00
$taxTotal = Mockery::mock(Money::class);
$taxTotal
2020-09-01 09:47:36 +03:00
->expects('to_array')->andReturn(['taxTotal']);
2020-08-31 13:38:54 +03:00
$handling = Mockery::mock(Money::class);
$handling
2020-09-01 09:47:36 +03:00
->expects('to_array')->andReturn(['handling']);
2020-08-31 13:38:54 +03:00
$insurance = Mockery::mock(Money::class);
$insurance
2020-09-01 09:47:36 +03:00
->expects('to_array')->andReturn(['insurance']);
2020-08-31 13:38:54 +03:00
$shippingDiscount = Mockery::mock(Money::class);
$shippingDiscount
2020-09-01 09:47:36 +03:00
->expects('to_array')->andReturn(['shippingDiscount']);
2020-08-31 13:38:54 +03:00
$discount = Mockery::mock(Money::class);
$discount
2020-09-01 09:47:36 +03:00
->expects('to_array')->andReturn(['discount']);
2020-08-31 13:38:54 +03:00
$testee = new AmountBreakdown(
$itemTotal,
$shipping,
$taxTotal,
$handling,
$insurance,
$shippingDiscount,
$discount
);
2020-09-01 09:47:36 +03:00
$this->assertEquals($itemTotal, $testee->item_total());
2020-08-31 13:38:54 +03:00
$this->assertEquals($shipping, $testee->shipping());
2020-09-01 09:47:36 +03:00
$this->assertEquals($taxTotal, $testee->tax_total());
2020-08-31 13:38:54 +03:00
$this->assertEquals($handling, $testee->handling());
$this->assertEquals($insurance, $testee->insurance());
2020-09-01 09:47:36 +03:00
$this->assertEquals($shippingDiscount, $testee->shipping_discount());
2020-08-31 13:38:54 +03:00
$this->assertEquals($discount, $testee->discount());
$expected = [
'item_total' => ['itemTotal'],
'shipping' => ['shipping'],
'tax_total' => ['taxTotal'],
'handling' => ['handling'],
'insurance' => ['insurance'],
'shipping_discount' => ['shippingDiscount'],
'discount' => ['discount'],
];
2020-09-01 09:47:36 +03:00
$this->assertEquals($expected, $testee->to_array());
2020-08-31 13:38:54 +03:00
}
/**
* @dataProvider dataDropArrayKeyIfNoValueGiven
*/
public function testDropArrayKeyIfNoValueGiven($keyMissing, $methodName)
{
$itemTotal = Mockery::mock(Money::class);
$itemTotal
2020-09-01 09:47:36 +03:00
->shouldReceive('to_array')->zeroOrMoreTimes()->andReturn(['itemTotal']);
2020-08-31 13:38:54 +03:00
$shipping = Mockery::mock(Money::class);
$shipping
2020-09-01 09:47:36 +03:00
->shouldReceive('to_array')->zeroOrMoreTimes()->andReturn(['shipping']);
2020-08-31 13:38:54 +03:00
$taxTotal = Mockery::mock(Money::class);
$taxTotal
2020-09-01 09:47:36 +03:00
->shouldReceive('to_array')->zeroOrMoreTimes()->andReturn(['taxTotal']);
2020-08-31 13:38:54 +03:00
$handling = Mockery::mock(Money::class);
$handling
2020-09-01 09:47:36 +03:00
->shouldReceive('to_array')->zeroOrMoreTimes()->andReturn(['handling']);
2020-08-31 13:38:54 +03:00
$insurance = Mockery::mock(Money::class);
$insurance
2020-09-01 09:47:36 +03:00
->shouldReceive('to_array')->zeroOrMoreTimes()->andReturn(['insurance']);
2020-08-31 13:38:54 +03:00
$shippingDiscount = Mockery::mock(Money::class);
$shippingDiscount
2020-09-01 09:47:36 +03:00
->shouldReceive('to_array')->zeroOrMoreTimes()->andReturn(['shippingDiscount']);
2020-08-31 13:38:54 +03:00
$discount = Mockery::mock(Money::class);
$discount
2020-09-01 09:47:36 +03:00
->shouldReceive('to_array')->zeroOrMoreTimes()->andReturn(['discount']);
2020-08-31 13:38:54 +03:00
$items = [
'item_total' => $itemTotal,
'shipping' => $shipping,
'tax_total' => $taxTotal,
'handling' => $handling,
'insurance' => $insurance,
'shipping_discount' => $shippingDiscount,
'discount' => $discount,
];
$items[$keyMissing] = null;
$testee = new AmountBreakdown(...array_values($items));
2020-09-01 09:47:36 +03:00
$array = $testee->to_array();
2020-08-31 13:38:54 +03:00
$result = ! array_key_exists($keyMissing, $array);
$this->assertTrue($result);
$this->assertNull($testee->{$methodName}(), "$methodName should return null");
}
public function dataDropArrayKeyIfNoValueGiven() : array
{
return [
2020-09-01 09:47:36 +03:00
['item_total', 'item_total'],
2020-08-31 13:38:54 +03:00
['shipping', 'shipping'],
2020-09-01 09:47:36 +03:00
['tax_total', 'tax_total'],
2020-08-31 13:38:54 +03:00
['handling', 'handling'],
['insurance', 'insurance'],
2020-09-01 09:47:36 +03:00
['shipping_discount', 'shipping_discount'],
2020-08-31 13:38:54 +03:00
['discount', 'discount'],
];
}
}