11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2014 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
88namespace Magento \Tax \Test \Unit \Model \Sales \Total \Quote ;
99
10- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
10+ use Magento \Customer \Api \AccountManagementInterface ;
11+ use Magento \Customer \Api \Data \AddressInterface ;
12+ use Magento \Customer \Api \Data \RegionInterface ;
13+ use Magento \Customer \Api \Data \RegionInterfaceFactory ;
14+ use Magento \Customer \Api \Data \AddressInterfaceFactory ;
1115use Magento \Quote \Api \Data \ShippingAssignmentInterface ;
1216use Magento \Quote \Api \Data \ShippingInterface ;
1317use Magento \Quote \Model \Quote ;
1418use Magento \Quote \Model \Quote \Address as QuoteAddress ;
1519use Magento \Quote \Model \Quote \Address \Total as QuoteAddressTotal ;
1620use Magento \Quote \Model \Quote \Item as QuoteItem ;
1721use Magento \Store \Model \Store ;
22+ use Magento \Tax \Api \Data \QuoteDetailsInterfaceFactory ;
23+ use Magento \Tax \Api \Data \QuoteDetailsItemExtensionInterfaceFactory ;
1824use Magento \Tax \Api \Data \QuoteDetailsItemInterface ;
1925use Magento \Tax \Api \Data \QuoteDetailsItemInterfaceFactory ;
2026use Magento \Tax \Api \Data \TaxClassKeyInterface ;
2127use Magento \Tax \Api \Data \TaxClassKeyInterfaceFactory ;
2228use Magento \Tax \Api \Data \TaxDetailsItemInterface ;
29+ use Magento \Tax \Api \TaxCalculationInterface ;
2330use Magento \Tax \Helper \Data as TaxHelper ;
2431use Magento \Tax \Model \Config ;
2532use Magento \Tax \Model \Sales \Quote \ItemDetails ;
2633use Magento \Tax \Model \Sales \Total \Quote \CommonTaxCollector ;
2734use Magento \Tax \Model \TaxClass \Key as TaxClassKey ;
35+ use PHPUnit \Framework \MockObject \Exception ;
2836use PHPUnit \Framework \MockObject \MockObject ;
2937use PHPUnit \Framework \TestCase ;
3038
@@ -36,60 +44,88 @@ class CommonTaxCollectorTest extends TestCase
3644 /**
3745 * @var CommonTaxCollector
3846 */
39- private $ commonTaxCollector ;
47+ private CommonTaxCollector $ commonTaxCollector ;
4048
4149 /**
4250 * @var MockObject|Config
4351 */
44- private $ taxConfig ;
52+ private Config $ taxConfig ;
4553
4654 /**
4755 * @var MockObject|QuoteAddress
4856 */
49- private $ address ;
57+ private QuoteAddress $ address ;
5058
5159 /**
5260 * @var MockObject|Quote
5361 */
54- private $ quote ;
62+ private Quote $ quote ;
5563
5664 /**
5765 * @var MockObject|Store
5866 */
59- private $ store ;
67+ private Store $ store ;
6068
6169 /**
62- * @var MockObject
70+ * @var TaxClassKeyInterfaceFactory| MockObject
6371 */
64- protected $ taxClassKeyDataObjectFactoryMock ;
72+ private TaxClassKeyInterfaceFactory $ taxClassKeyDataObjectFactoryMock ;
6573
6674 /**
67- * @var MockObject
75+ * @var QuoteDetailsItemInterfaceFactory| MockObject
6876 */
69- protected $ quoteDetailsItemDataObjectFactoryMock ;
77+ private QuoteDetailsItemInterfaceFactory $ quoteDetailsItemDataObjectFactoryMock ;
7078
7179 /**
72- * @var QuoteDetailsItemInterface
80+ * @var QuoteDetailsItemInterface|MockObject
7381 */
74- protected $ quoteDetailsItemDataObject ;
82+ private QuoteDetailsItemInterface $ quoteDetailsItemDataObject ;
7583
7684 /**
77- * @var TaxClassKeyInterface
85+ * @var TaxClassKeyInterface|MockObject
7886 */
79- protected $ taxClassKeyDataObject ;
87+ private TaxClassKeyInterface $ taxClassKeyDataObject ;
8088
8189 /**
82- * @var TaxHelper
90+ * @var TaxHelper|MockObject
8391 */
84- private $ taxHelper ;
92+ private TaxHelper $ taxHelper ;
8593
8694 /**
87- * {@inheritdoc}
95+ * @var TaxCalculationInterface|TaxCalculationInterface&MockObject|MockObject
96+ */
97+ private TaxCalculationInterface $ taxCalculation ;
98+
99+ /**
100+ * @var QuoteDetailsInterfaceFactory|QuoteDetailsInterfaceFactory&MockObject|MockObject
101+ */
102+ private QuoteDetailsInterfaceFactory $ quoteDetailsFactory ;
103+
104+ /**
105+ * @var AddressInterfaceFactory|AddressInterfaceFactory&MockObject|MockObject
106+ */
107+ private AddressInterfaceFactory $ addressFactory ;
108+
109+ /**
110+ * @var RegionInterfaceFactory|RegionInterfaceFactory&MockObject|MockObject
111+ */
112+ private RegionInterfaceFactory $ regionFactory ;
113+
114+ /**
115+ * @var QuoteDetailsItemExtensionInterfaceFactory|QuoteDetailsItemExtensionInterfaceFactory&MockObject|MockObject
116+ */
117+ private QuoteDetailsItemExtensionInterfaceFactory $ quoteDetailsItemExtensionFactory ;
118+
119+ /**
120+ * @var AccountManagementInterface|AccountManagementInterface&MockObject|MockObject
121+ */
122+ private AccountManagementInterface $ accountManagement ;
123+
124+ /**
125+ * @inheritdoc
88126 */
89127 protected function setUp (): void
90128 {
91- $ objectManager = new ObjectManager ($ this );
92-
93129 $ this ->taxConfig = $ this ->getMockBuilder (Config::class)
94130 ->disableOriginalConstructor ()
95131 ->onlyMethods (['getShippingTaxClass ' , 'shippingPriceIncludesTax ' , 'discountTax ' ])
@@ -117,8 +153,13 @@ protected function setUp(): void
117153 ->method ('getQuote ' )
118154 ->willReturn ($ this ->quote );
119155 $ methods = ['create ' ];
120- $ this ->quoteDetailsItemDataObject = $ objectManager ->getObject (ItemDetails::class);
121- $ this ->taxClassKeyDataObject = $ objectManager ->getObject (TaxClassKey::class);
156+ $ this ->quoteDetailsItemDataObject = $ this ->createMock (ItemDetails::class);
157+ $ this ->quoteDetailsItemDataObject ->method ('setType ' )->willReturnSelf ();
158+ $ this ->quoteDetailsItemDataObject ->method ('setCode ' )->willReturnSelf ();
159+ $ this ->quoteDetailsItemDataObject ->method ('setQuantity ' )->willReturnSelf ();
160+ $ this ->taxClassKeyDataObject = $ this ->createMock (TaxClassKey::class);
161+ $ this ->taxClassKeyDataObject ->method ('setType ' )->willReturnSelf ();
162+ $ this ->taxClassKeyDataObject ->method ('setValue ' )->willReturnSelf ();
122163 $ this ->quoteDetailsItemDataObjectFactoryMock
123164 = $ this ->createPartialMock (QuoteDetailsItemInterfaceFactory::class, $ methods );
124165 $ this ->quoteDetailsItemDataObjectFactoryMock
@@ -132,15 +173,78 @@ protected function setUp(): void
132173 $ this ->taxHelper = $ this ->getMockBuilder (TaxHelper::class)
133174 ->disableOriginalConstructor ()
134175 ->getMock ();
135- $ this ->commonTaxCollector = $ objectManager ->getObject (
136- CommonTaxCollector::class,
137- [
138- 'taxConfig ' => $ this ->taxConfig ,
139- 'quoteDetailsItemDataObjectFactory ' => $ this ->quoteDetailsItemDataObjectFactoryMock ,
140- 'taxClassKeyDataObjectFactory ' => $ this ->taxClassKeyDataObjectFactoryMock ,
141- 'taxHelper ' => $ this ->taxHelper ,
142- ]
176+ $ this ->taxCalculation = $ this ->createMock (TaxCalculationInterface::class);
177+ $ this ->quoteDetailsFactory = $ this ->createMock (QuoteDetailsInterfaceFactory::class);
178+ $ this ->addressFactory = $ this ->createMock (AddressInterfaceFactory::class);
179+ $ this ->regionFactory = $ this ->createMock (RegionInterfaceFactory::class);
180+ $ this ->quoteDetailsItemExtensionFactory = $ this ->createMock (QuoteDetailsItemExtensionInterfaceFactory::class);
181+ $ this ->accountManagement = $ this ->createMock (AccountManagementInterface::class);
182+ $ this ->commonTaxCollector = new CommonTaxCollector (
183+ $ this ->taxConfig ,
184+ $ this ->taxCalculation ,
185+ $ this ->quoteDetailsFactory ,
186+ $ this ->quoteDetailsItemDataObjectFactoryMock ,
187+ $ this ->taxClassKeyDataObjectFactoryMock ,
188+ $ this ->addressFactory ,
189+ $ this ->regionFactory ,
190+ $ this ->taxHelper ,
191+ $ this ->quoteDetailsItemExtensionFactory ,
192+ $ this ->accountManagement
143193 );
194+
195+ parent ::setUp ();
196+ }
197+
198+ /**
199+ * @return void
200+ * @throws Exception
201+ */
202+ public function testMapAddress (): void
203+ {
204+ $ countryId = 1 ;
205+ $ regionId = 2 ;
206+ $ regionCode = 'regionCode ' ;
207+ $ region = 'region ' ;
208+ $ postCode = 'postCode ' ;
209+ $ city = 'city ' ;
210+ $ street = ['street ' ];
211+
212+ $ address = $ this ->createMock (QuoteAddress::class);
213+ $ address ->expects ($ this ->once ())->method ('getCountryId ' )->willReturn ($ countryId );
214+ $ address ->expects ($ this ->once ())->method ('getRegionId ' )->willReturn ($ regionId );
215+ $ address ->expects ($ this ->once ())->method ('getRegionCode ' )->willReturn ($ regionCode );
216+ $ address ->expects ($ this ->once ())->method ('getRegion ' )->willReturn ($ region );
217+ $ address ->expects ($ this ->once ())->method ('getPostcode ' )->willReturn ($ postCode );
218+ $ address ->expects ($ this ->once ())->method ('getCity ' )->willReturn ($ city );
219+ $ address ->expects ($ this ->once ())->method ('getStreet ' )->willReturn ($ street );
220+
221+ $ regionData = [
222+ 'data ' => [
223+ 'region_id ' => $ regionId ,
224+ 'region_code ' => $ regionCode ,
225+ 'region ' => $ region ,
226+ ]
227+ ];
228+ $ regionObject = $ this ->createMock (RegionInterface::class);
229+ $ this ->regionFactory ->expects ($ this ->once ())->method ('create ' )->with ($ regionData )->willReturn ($ regionObject );
230+ $ customerAddress = $ this ->createMock (AddressInterface::class);
231+
232+ $ this ->addressFactory ->expects ($ this ->once ())
233+ ->method ('create ' )
234+ ->with (
235+ [
236+ 'data ' => [
237+ 'country_id ' => $ countryId ,
238+ 'region ' => $ regionObject ,
239+ 'postcode ' => $ postCode ,
240+ 'city ' => $ city ,
241+ 'street ' => $ street
242+ ]
243+ ]
244+ )
245+ ->willReturn ($ customerAddress );
246+
247+ $ this ->assertSame ($ customerAddress , $ this ->commonTaxCollector ->mapAddress ($ address ));
144248 }
145249
146250 /**
@@ -153,12 +257,13 @@ protected function setUp(): void
153257 *
154258 * @return void
155259 * @dataProvider getShippingDataObjectDataProvider
260+ * @throws Exception
156261 */
157262 public function testGetShippingDataObject (
158263 array $ addressData ,
159- $ useBaseCurrency ,
160- $ shippingTaxClass ,
161- $ shippingPriceInclTax
264+ bool $ useBaseCurrency ,
265+ string $ shippingTaxClass ,
266+ bool $ shippingPriceInclTax
162267 ): void {
163268 $ shippingAssignmentMock = $ this ->getMockForAbstractClass (ShippingAssignmentInterface::class);
164269 /** @var MockObject|QuoteAddressTotal $totalsMock */
@@ -201,10 +306,8 @@ public function testGetShippingDataObject(
201306 ->expects ($ this ->once ())
202307 ->method ('getBaseShippingDiscountAmount ' )
203308 ->willReturn ($ baseShippingAmount );
204- $ expectedDiscountAmount = $ baseShippingAmount ;
205309 } else {
206310 $ totalsMock ->expects ($ this ->never ())->method ('getBaseShippingDiscountAmount ' );
207- $ expectedDiscountAmount = $ shippingAmount ;
208311 }
209312 }
210313 foreach ($ addressData as $ key => $ value ) {
@@ -214,10 +317,6 @@ public function testGetShippingDataObject(
214317 $ this ->quoteDetailsItemDataObject ,
215318 $ this ->commonTaxCollector ->getShippingDataObject ($ shippingAssignmentMock , $ totalsMock , $ useBaseCurrency )
216319 );
217-
218- if ($ shippingAmount ) {
219- $ this ->assertEquals ($ expectedDiscountAmount , $ this ->quoteDetailsItemDataObject ->getDiscountAmount ());
220- }
221320 }
222321
223322 /**
0 commit comments