Skip to content

Commit 63a818d

Browse files
author
Robert He
committed
MAGETWO-31371: Improve Unit and Integration test coverage
- fixed data api interfaces - added setter/getter test
1 parent 786ed7b commit 63a818d

File tree

8 files changed

+166
-79
lines changed

8 files changed

+166
-79
lines changed

app/code/Magento/Tax/Api/Data/QuoteDetailsItemInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function setQuantity($quantity);
114114
* @return bool
115115
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
116116
*/
117-
public function getTaxIncluded();
117+
public function getIsTaxIncluded();
118118

119119
/**
120120
* Set whether the tax is included in the unit price and row total
@@ -172,7 +172,7 @@ public function setParentCode($parentCode);
172172
/**
173173
* Get associated item code if this item is associated with another item, null otherwise
174174
*
175-
* @return mixed|null
175+
* @return int|null
176176
*/
177177
public function getAssociatedItemCode();
178178

app/code/Magento/Tax/Api/Data/TaxDetailsItemInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function setAppliedTaxes(array $appliedTaxes = null);
221221
/**
222222
* Return associated item code if this item is associated with another item, null otherwise
223223
*
224-
* @return mixed|null
224+
* @return int|null
225225
*/
226226
public function getAssociatedItemCode();
227227

app/code/Magento/Tax/Model/Calculation/AbstractCalculator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function setCustomerId($customerId)
217217
*/
218218
public function calculate(QuoteDetailsItemInterface $item, $quantity, $round = true)
219219
{
220-
if ($item->getTaxIncluded()) {
220+
if ($item->getIsTaxIncluded()) {
221221
return $this->calculateWithTaxInPrice($item, $quantity, $round);
222222
} else {
223223
return $this->calculateWithTaxNotInPrice($item, $quantity, $round);

app/code/Magento/Tax/Model/Converter.php

Lines changed: 0 additions & 71 deletions
This file was deleted.

app/code/Magento/Tax/Model/Sales/Quote/ItemDetails.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function getQuantity()
5656
/**
5757
* {@inheritdoc}
5858
*/
59-
public function getTaxIncluded()
59+
public function getIsTaxIncluded()
6060
{
6161
return $this->getData(QuoteDetailsItemInterface::KEY_TAX_INCLUDED);
6262
}
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Tax\Test\Unit;
7+
8+
class GetterSetterTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @param string $className
12+
* @param array $variableNames
13+
* @dataProvider dataProviderGettersSetters
14+
*/
15+
public function testGettersSetters($className = null, $variableNames = null)
16+
{
17+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
18+
$classObject = $objectManager->getObject($className);
19+
20+
foreach ($variableNames as $variableName => $variableValue) {
21+
$setterName = 'set' . $variableName;
22+
23+
$this->assertTrue(method_exists($classObject, $setterName),
24+
"Method " . $setterName . " does not exist in " . $className);
25+
26+
if (is_array($variableValue)) {
27+
if (strpos($variableValue[0], 'Magento') !== false) {
28+
$obj = $objectManager->getObject($variableValue[0]);
29+
$variableValue = [$obj];
30+
$variableNames[$variableName] = $variableValue;
31+
}
32+
} else if (strpos($variableValue, 'Magento') !== false) {
33+
$obj = $objectManager->getObject($variableValue);
34+
$variableValue = $obj;
35+
$variableNames[$variableName] = $variableValue;
36+
}
37+
$this->assertNotFalse(call_user_func(array($classObject, $setterName), $variableValue),
38+
"Calling method " . $setterName . " failed in " . $className);
39+
}
40+
41+
foreach ($variableNames as $variableName => $variableValue) {
42+
$getterName = 'get' . $variableName;
43+
44+
$this->assertTrue(method_exists($classObject, $getterName),
45+
"Method " . $getterName . " does not exist in " . $className);
46+
$result = call_user_func(array($classObject, $getterName));
47+
$this->assertNotFalse($result,
48+
"Calling method " . $getterName . " failed in " . $className);
49+
$this->assertSame($result, $variableValue,
50+
"Value from " . $getterName . "did not match in " . $className);
51+
}
52+
}
53+
54+
/**
55+
* @return array
56+
*/
57+
public function dataProviderGettersSetters()
58+
{
59+
// Test each class that implements the Tax Api Data Interfaces
60+
return [
61+
[
62+
'Magento\Tax\Model\TaxDetails\AppliedTax',
63+
['TaxRateKey' => 'taxRateKey', 'Percent' => 1.0, 'Amount' => 1.0,
64+
'Rates' => ['Magento\Tax\Model\TaxDetails\AppliedTaxRate'],
65+
'ExtensionAttributes' => 'Magento\Tax\Api\Data\AppliedTaxExtension']
66+
],
67+
[
68+
'Magento\Tax\Model\TaxDetails\AppliedTaxRate',
69+
['Code' => 'code', 'Title' => 'title', 'Percent' => 1.0,
70+
'ExtensionAttributes' => 'Magento\Tax\Api\Data\AppliedTaxRateExtension']
71+
],
72+
[
73+
'Magento\Tax\Model\Sales\Order\Tax',
74+
['Code' => 'code', 'Title' => 'title', 'Percent' => 1.0, 'Amount' => 'amount',
75+
'BaseAmount' => 'baseAmount',
76+
'ExtensionAttributes' => 'Magento\Tax\Api\Data\OrderTaxDetailsAppliedTaxExtension']
77+
],
78+
[
79+
'Magento\Tax\Model\Sales\Order\Details',
80+
['AppliedTaxes' => ['Magento\Tax\Model\Sales\Order\Tax'],
81+
'Items' => ['Magento\Tax\Model\Sales\Order\Tax\Item'],
82+
'ExtensionAttributes' => 'Magento\Tax\Api\Data\OrderTaxDetailsExtension']
83+
],
84+
[
85+
'Magento\Tax\Model\Sales\Order\Tax\Item',
86+
['Type' => 'type', 'ItemId' => 1, 'AssociatedItemId' => 1,
87+
'AppliedTaxes' => ['Magento\Tax\Model\Sales\Order\Tax'],
88+
'ExtensionAttributes' => 'Magento\Tax\Api\Data\OrderTaxDetailsItemExtension']
89+
],
90+
[
91+
'Magento\Tax\Model\Sales\Quote\QuoteDetails',
92+
['BillingAddress' => 'Magento\Customer\Model\Data\Address',
93+
'ShippingAddress' => 'Magento\Customer\Model\Data\Address',
94+
'CustomerTaxClassKey' => 'Magento\Tax\Model\TaxClass\Key',
95+
'CustomerId' => 1,
96+
'Items' => ['Magento\Tax\Model\Sales\Order\Tax\Item'],
97+
'CustomerTaxClassId' => 1,
98+
'ExtensionAttributes' => 'Magento\Tax\Api\Data\QuoteDetailsExtension']
99+
],
100+
[
101+
'Magento\Tax\Model\Sales\Quote\ItemDetails',
102+
['Code' => 'code', 'Type' => 'type',
103+
'TaxClassKey' => 'Magento\Tax\Model\TaxClass\Key',
104+
'UnitPrice' => 1.0, 'Quantity' => 1.0,
105+
'IsTaxIncluded' => true, 'ShortDescription' => 'shortDescription',
106+
'DiscountAmount' => 1.0, 'ParentCode' => 'parentCode', 'AssociatedItemCode' => 1,
107+
'TaxClassId' => 1,
108+
'ExtensionAttributes' => '\Magento\Tax\Api\Data\QuoteDetailsItemExtension']
109+
],
110+
[
111+
'Magento\Tax\Model\ClassModel',
112+
['ClassId' => 1, 'ClassName' => 'className', 'ClassType' => 'classType',
113+
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxClassExtension']
114+
],
115+
[
116+
'Magento\Tax\Model\TaxClass\Key',
117+
['Type' => 'type', 'Value' => 'value',
118+
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxClassKeyExtension']
119+
],
120+
[
121+
'Magento\Tax\Model\TaxDetails\TaxDetails',
122+
['Subtotal' => 1.0, 'TaxAmount' => 1.0,
123+
'DiscountTaxCompensationAmount' => 1.0,
124+
'AppliedTaxes' => ['Magento\Tax\Model\TaxDetails\AppliedTax'],
125+
'Items' => ['Magento\Tax\Model\TaxDetails\ItemDetails'],
126+
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxDetailsExtension']
127+
],
128+
[
129+
'Magento\Tax\Model\TaxDetails\ItemDetails',
130+
['Code' => 'code', 'Type' => 'type', 'TaxPercent' => 1.0, 'Price' => 1.0, 'PriceInclTax' => 1.0,
131+
'RowTotal' => 1.0, 'RowTotalInclTax' => 1.0, 'RowTax' => 1.0, 'TaxableAmount' => 1.0,
132+
'DiscountAmount' => 1.0, 'DiscountTaxCompensationAmount' => 1.0,
133+
'AppliedTaxes' => ['Magento\Tax\Model\TaxDetails\AppliedTax'],
134+
'AssociatedItemCode' => 1,
135+
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxDetailsItemExtension']
136+
],
137+
[
138+
'Magento\Tax\Model\Calculation\Rate',
139+
['Id' => 1, 'TaxCountryId' => 'taxCountryId', 'TaxRegionId' => 1, 'RegionName' => 'regionName',
140+
'TaxPostcode' => 'taxPostCode', 'ZipIsRange' => 1, 'ZipFrom' => 1, 'ZipTo' => 1,
141+
'Rate' => 1.0, 'Code' => 'code',
142+
'Titles' => ['Magento\Tax\Model\Calculation\Rate\Title'],
143+
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxRateExtension']
144+
],
145+
[
146+
'Magento\Tax\Model\Calculation\Rate\Title',
147+
['StoreId' => 'storeId', 'Value' => 'value',
148+
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxRateTitleExtension']
149+
],
150+
[
151+
'Magento\Tax\Model\Calculation\Rule',
152+
['Id' => 1, 'Code' => 'code', 'Priority' => 1, 'Position' => 1, 'CustomerTaxClassIds' => [1],
153+
'ProductTaxClassIds' => [1], 'TaxRateIds' => [1], 'CalculateSubtotal' => true,
154+
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxRuleExtension']
155+
]
156+
];
157+
}
158+
}

app/code/Magento/Tax/Test/Unit/Model/Calculation/RowBaseAndTotalBaseCalculatorTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ protected function initMockItem($taxIncluded)
168168
],
169169
[
170170
self::ONCE => true,
171-
self::MOCK_METHOD_NAME => 'getTaxIncluded',
171+
self::MOCK_METHOD_NAME => 'getIsTaxIncluded',
172172
self::MOCK_VALUE => $taxIncluded
173173
]
174174
]

app/code/Magento/Tax/Test/Unit/Model/Calculation/UnitBaseCalculatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function testCalculateWithTaxInPrice()
114114
{
115115
$mockItem = $this->getMockItem();
116116
$mockItem->expects($this->once())
117-
->method('getTaxIncluded')
117+
->method('getIsTaxIncluded')
118118
->will($this->returnValue(true));
119119

120120
$this->mockConfig->expects($this->once())
@@ -147,7 +147,7 @@ public function testCalculateWithTaxNotInPrice()
147147
{
148148
$mockItem = $this->getMockItem();
149149
$mockItem->expects($this->once())
150-
->method('getTaxIncluded')
150+
->method('getIsTaxIncluded')
151151
->will($this->returnValue(false));
152152

153153
$this->mockConfig->expects($this->once())

0 commit comments

Comments
 (0)