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