GetterSetterTest.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Tax\Test\Unit;
  7. /**
  8. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  9. */
  10. class GetterSetterTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @param string $className
  14. * @param array $variables
  15. * @dataProvider dataProviderGettersSetters
  16. */
  17. public function testGettersSetters($className = null, $variables = null)
  18. {
  19. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  20. $classObject = $objectManager->getObject($className);
  21. foreach ($variables as $variableName => $variableValue) {
  22. $setterName = 'set' . $variableName;
  23. $this->assertTrue(
  24. method_exists($classObject, $setterName),
  25. "Method " . $setterName . " does not exist in " . $className
  26. );
  27. if (is_array($variableValue)) {
  28. if (strpos($variableValue[0], 'Magento') !== false) {
  29. $obj = $objectManager->getObject($variableValue[0]);
  30. $variableValue = [$obj];
  31. $variables[$variableName] = $variableValue;
  32. }
  33. } elseif (strpos($variableValue, 'Magento') !== false) {
  34. $obj = $objectManager->getObject($variableValue);
  35. $variableValue = $obj;
  36. $variables[$variableName] = $variableValue;
  37. }
  38. $this->assertNotFalse(
  39. call_user_func(
  40. [$classObject, $setterName],
  41. $variableValue
  42. ),
  43. "Calling method " . $setterName . " failed in " . $className
  44. );
  45. }
  46. foreach ($variables as $variableName => $variableValue) {
  47. $getterName = 'get' . $variableName;
  48. $this->assertTrue(
  49. method_exists($classObject, $getterName),
  50. "Method " . $getterName . " does not exist in " . $className
  51. );
  52. $result = call_user_func([$classObject, $getterName]);
  53. $this->assertNotFalse(
  54. $result,
  55. "Calling method " . $getterName . " failed in " . $className
  56. );
  57. $this->assertSame(
  58. $result,
  59. $variableValue,
  60. "Value from " . $getterName . "did not match in " . $className
  61. );
  62. }
  63. }
  64. /**
  65. * @return array
  66. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  67. */
  68. public function dataProviderGettersSetters()
  69. {
  70. // Test each class that implements the Tax Api Data Interfaces
  71. return [
  72. [\Magento\Tax\Model\TaxDetails\AppliedTax::class,
  73. [
  74. 'TaxRateKey' => 'taxRateKey',
  75. 'Percent' => 1.0,
  76. 'Amount' => 1.0,
  77. 'Rates' => [\Magento\Tax\Model\TaxDetails\AppliedTaxRate::class
  78. ],
  79. 'ExtensionAttributes' => \Magento\Tax\Api\Data\AppliedTaxExtension::class
  80. ]
  81. ],
  82. [\Magento\Tax\Model\TaxDetails\AppliedTaxRate::class,
  83. [
  84. 'Code' => 'code',
  85. 'Title' => 'title',
  86. 'Percent' => 1.0,
  87. 'ExtensionAttributes' => \Magento\Tax\Api\Data\AppliedTaxRateExtension::class
  88. ]
  89. ],
  90. [\Magento\Tax\Model\Sales\Order\Tax::class,
  91. [
  92. 'Code' => 'code',
  93. 'Title' => 'title',
  94. 'Percent' => 1.0,
  95. 'Amount' => 'amount',
  96. 'BaseAmount' => 'baseAmount',
  97. 'ExtensionAttributes' => \Magento\Tax\Api\Data\OrderTaxDetailsAppliedTaxExtension::class
  98. ]
  99. ],
  100. [\Magento\Tax\Model\Sales\Order\Details::class,
  101. [
  102. 'AppliedTaxes' => [\Magento\Tax\Model\Sales\Order\Tax::class
  103. ],
  104. 'Items' => [\Magento\Sales\Model\Order\Tax\Item::class
  105. ],
  106. 'ExtensionAttributes' => \Magento\Tax\Api\Data\OrderTaxDetailsExtension::class
  107. ]
  108. ],
  109. [\Magento\Sales\Model\Order\Tax\Item::class,
  110. [
  111. 'Type' => 'type',
  112. 'ItemId' => 1,
  113. 'AssociatedItemId' => 1,
  114. 'AppliedTaxes' => [\Magento\Tax\Model\Sales\Order\Tax::class
  115. ],
  116. 'ExtensionAttributes' => \Magento\Tax\Api\Data\OrderTaxDetailsItemExtension::class
  117. ]
  118. ],
  119. [\Magento\Tax\Model\Sales\Quote\QuoteDetails::class,
  120. [
  121. 'BillingAddress' => \Magento\Customer\Model\Data\Address::class,
  122. 'ShippingAddress' => \Magento\Customer\Model\Data\Address::class,
  123. 'CustomerTaxClassKey' => \Magento\Tax\Model\TaxClass\Key::class,
  124. 'CustomerId' => 1,
  125. 'Items' => [\Magento\Sales\Model\Order\Tax\Item::class
  126. ],
  127. 'CustomerTaxClassId' => 1,
  128. 'ExtensionAttributes' => \Magento\Tax\Api\Data\QuoteDetailsExtension::class
  129. ]
  130. ],
  131. [\Magento\Tax\Model\Sales\Quote\ItemDetails::class,
  132. [
  133. 'Code' => 'code',
  134. 'Type' => 'type',
  135. 'TaxClassKey' => \Magento\Tax\Model\TaxClass\Key::class,
  136. 'UnitPrice' => 1.0,
  137. 'Quantity' => 1.0,
  138. 'IsTaxIncluded' => true,
  139. 'ShortDescription' => 'shortDescription',
  140. 'DiscountAmount' => 1.0,
  141. 'ParentCode' => 'parentCode',
  142. 'AssociatedItemCode' => 1,
  143. 'TaxClassId' => 1,
  144. 'ExtensionAttributes' => \Magento\Tax\Api\Data\QuoteDetailsItemExtension::class
  145. ]
  146. ],
  147. [\Magento\Tax\Model\ClassModel::class,
  148. [
  149. 'ClassId' => 1,
  150. 'ClassName' => 'className',
  151. 'ClassType' => 'classType',
  152. 'ExtensionAttributes' => \Magento\Tax\Api\Data\TaxClassExtension::class
  153. ]
  154. ],
  155. [\Magento\Tax\Model\TaxClass\Key::class,
  156. [
  157. 'Type' => 'type',
  158. 'Value' => 'value',
  159. 'ExtensionAttributes' => \Magento\Tax\Api\Data\TaxClassKeyExtension::class
  160. ]
  161. ],
  162. [\Magento\Tax\Model\TaxDetails\TaxDetails::class,
  163. [
  164. 'Subtotal' => 1.0,
  165. 'TaxAmount' => 1.0,
  166. 'DiscountTaxCompensationAmount' => 1.0,
  167. 'AppliedTaxes' => [\Magento\Tax\Model\TaxDetails\AppliedTax::class
  168. ],
  169. 'Items' => [\Magento\Tax\Model\TaxDetails\ItemDetails::class
  170. ],
  171. 'ExtensionAttributes' => \Magento\Tax\Api\Data\TaxDetailsExtension::class
  172. ]
  173. ],
  174. [\Magento\Tax\Model\TaxDetails\ItemDetails::class,
  175. [
  176. 'Code' => 'code',
  177. 'Type' => 'type',
  178. 'TaxPercent' => 1.0,
  179. 'Price' => 1.0,
  180. 'PriceInclTax' => 1.0,
  181. 'RowTotal' => 1.0,
  182. 'RowTotalInclTax' => 1.0,
  183. 'RowTax' => 1.0,
  184. 'TaxableAmount' => 1.0,
  185. 'DiscountAmount' => 1.0,
  186. 'DiscountTaxCompensationAmount' => 1.0,
  187. 'AppliedTaxes' => [\Magento\Tax\Model\TaxDetails\AppliedTax::class
  188. ],
  189. 'AssociatedItemCode' => 1,
  190. 'ExtensionAttributes' => \Magento\Tax\Api\Data\TaxDetailsItemExtension::class
  191. ]
  192. ],
  193. [\Magento\Tax\Model\Calculation\Rate::class,
  194. [
  195. 'Id' => 1,
  196. 'TaxCountryId' => 'taxCountryId',
  197. 'TaxRegionId' => 1,
  198. 'RegionName' => 'regionName',
  199. 'TaxPostcode' => 'taxPostCode',
  200. 'ZipIsRange' => 1,
  201. 'ZipFrom' => 1,
  202. 'ZipTo' => 1,
  203. 'Rate' => 1.0,
  204. 'Code' => 'code',
  205. 'Titles' => [\Magento\Tax\Model\Calculation\Rate\Title::class
  206. ],
  207. 'ExtensionAttributes' => \Magento\Tax\Api\Data\TaxRateExtension::class
  208. ]
  209. ],
  210. [\Magento\Tax\Model\Calculation\Rate\Title::class,
  211. [
  212. 'StoreId' => 'storeId',
  213. 'Value' => 'value',
  214. 'ExtensionAttributes' => \Magento\Tax\Api\Data\TaxRateTitleExtension::class
  215. ]
  216. ],
  217. [\Magento\Tax\Model\Calculation\Rule::class,
  218. [
  219. 'Id' => 1,
  220. 'Code' => 'code',
  221. 'Priority' => 1,
  222. 'Position' => 1,
  223. 'CustomerTaxClassIds' => [1],
  224. 'ProductTaxClassIds' => [1],
  225. 'TaxRateIds' => [1],
  226. 'CalculateSubtotal' => true,
  227. 'ExtensionAttributes' => \Magento\Tax\Api\Data\TaxRuleExtension::class
  228. ]
  229. ]
  230. ];
  231. }
  232. }