PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/magento/module-tax/Test/Unit/GetterSetterTest.php

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