Skip to content

Commit 24793f9

Browse files
refactored unit test class
1 parent a84629f commit 24793f9

File tree

1 file changed

+52
-33
lines changed

1 file changed

+52
-33
lines changed

app/code/Magento/Quote/Test/Unit/Observer/Frontend/Quote/Address/CollectTotalsObserverTest.php

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,85 +6,104 @@
66

77
namespace Magento\Quote\Test\Unit\Observer\Frontend\Quote\Address;
88

9+
use Magento\Customer\Api\AddressRepositoryInterface;
10+
use Magento\Customer\Api\Data\AddressInterface;
11+
use Magento\Customer\Api\Data\CustomerInterface;
12+
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
13+
use Magento\Customer\Api\Data\GroupInterface;
14+
use Magento\Customer\Api\GroupManagementInterface;
15+
use Magento\Customer\Model\Session;
16+
use Magento\Customer\Model\Vat;
17+
use Magento\Framework\Event\Observer;
18+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
19+
use Magento\Quote\Api\Data\ShippingAssignmentInterface;
20+
use Magento\Quote\Api\Data\ShippingInterface;
21+
use Magento\Quote\Model\Quote;
22+
use Magento\Quote\Model\Quote\Address;
23+
use Magento\Quote\Observer\Frontend\Quote\Address\CollectTotalsObserver;
24+
use Magento\Quote\Observer\Frontend\Quote\Address\VatValidator;
25+
use PHPUnit\Framework\TestCase;
26+
use PHPUnit\Framework\MockObject\MockObject;
27+
928
/**
1029
* Class CollectTotalsTest
1130
*
1231
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1332
*/
14-
class CollectTotalsObserverTest extends \PHPUnit\Framework\TestCase
33+
class CollectTotalsObserverTest extends TestCase
1534
{
1635
/**
17-
* @var \Magento\Quote\Observer\Frontend\Quote\Address\CollectTotalsObserver
36+
* @var CollectTotalsObserver
1837
*/
1938
protected $model;
2039

2140
/**
22-
* @var \PHPUnit_Framework_MockObject_MockObject
41+
* @var MockObject
2342
*/
2443
protected $customerAddressMock;
2544

2645
/**
27-
* @var \PHPUnit_Framework_MockObject_MockObject
46+
* @var MockObject
2847
*/
2948
protected $customerSession;
3049

3150
/**
32-
* @var \PHPUnit_Framework_MockObject_MockObject
51+
* @var MockObject
3352
*/
3453
protected $customerVatMock;
3554

3655
/**
37-
* @var \PHPUnit_Framework_MockObject_MockObject
56+
* @var MockObject
3857
*/
3958
protected $addressRepository;
4059

4160
/**
42-
* @var \PHPUnit_Framework_MockObject_MockObject
61+
* @var MockObject
4362
*/
4463
protected $quoteAddressMock;
4564

4665
/**
47-
* @var \PHPUnit_Framework_MockObject_MockObject
66+
* @var MockObject
4867
*/
4968
protected $quoteMock;
5069

5170
/**
52-
* @var \PHPUnit_Framework_MockObject_MockObject
71+
* @var MockObject
5372
*/
5473
protected $storeId;
5574

5675
/**
57-
* @var \PHPUnit_Framework_MockObject_MockObject
76+
* @var MockObject
5877
*/
5978
protected $customerMock;
6079

6180
/**
62-
* @var \PHPUnit_Framework_MockObject_MockObject
81+
* @var MockObject
6382
*/
6483
protected $vatValidatorMock;
6584

6685
/**
67-
* @var \PHPUnit_Framework_MockObject_MockObject
86+
* @var MockObject
6887
*/
6988
protected $observerMock;
7089

7190
/**
72-
* @var \PHPUnit_Framework_MockObject_MockObject
91+
* @var MockObject
7392
*/
7493
protected $customerDataFactoryMock;
7594

7695
/**
77-
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
96+
* @var ObjectManager
7897
*/
7998
protected $objectManager;
8099

81100
/**
82-
* @var \PHPUnit_Framework_MockObject_MockObject
101+
* @var MockObject
83102
*/
84103
protected $groupManagementMock;
85104

86105
/**
87-
* @var \PHPUnit_Framework_MockObject_MockObject
106+
* @var MockObject
88107
*/
89108
protected $groupInterfaceMock;
90109

@@ -93,10 +112,10 @@ class CollectTotalsObserverTest extends \PHPUnit\Framework\TestCase
93112
*/
94113
protected function setUp()
95114
{
96-
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
115+
$this->objectManager = new ObjectManager($this);
97116
$this->storeId = 1;
98117
$this->customerMock = $this->getMockForAbstractClass(
99-
\Magento\Customer\Api\Data\CustomerInterface::class,
118+
CustomerInterface::class,
100119
[],
101120
'',
102121
false,
@@ -105,29 +124,29 @@ protected function setUp()
105124
['getStoreId', 'getCustomAttribute', 'getId', '__wakeup']
106125
);
107126
$this->customerAddressMock = $this->createMock(\Magento\Customer\Helper\Address::class);
108-
$this->customerVatMock = $this->createMock(\Magento\Customer\Model\Vat::class);
127+
$this->customerVatMock = $this->createMock(Vat::class);
109128
$this->customerDataFactoryMock = $this->createPartialMock(
110-
\Magento\Customer\Api\Data\CustomerInterfaceFactory::class,
129+
CustomerInterfaceFactory::class,
111130
['mergeDataObjectWithArray', 'create']
112131
);
113-
$this->vatValidatorMock = $this->createMock(\Magento\Quote\Observer\Frontend\Quote\Address\VatValidator::class);
132+
$this->vatValidatorMock = $this->createMock(VatValidator::class);
114133
$this->observerMock = $this->createPartialMock(
115-
\Magento\Framework\Event\Observer::class,
134+
Observer::class,
116135
['getShippingAssignment', 'getQuote']
117136
);
118137

119138
$this->quoteAddressMock = $this->createPartialMock(
120-
\Magento\Quote\Model\Quote\Address::class,
139+
Address::class,
121140
['getCountryId', 'getVatId', 'getQuote', 'setPrevQuoteCustomerGroupId', '__wakeup']
122141
);
123142

124143
$this->quoteMock = $this->createPartialMock(
125-
\Magento\Quote\Model\Quote::class,
144+
Quote::class,
126145
['setCustomerGroupId', 'getCustomerGroupId', 'getCustomer', '__wakeup', 'setCustomer']
127146
);
128147

129148
$this->groupManagementMock = $this->getMockForAbstractClass(
130-
\Magento\Customer\Api\GroupManagementInterface::class,
149+
GroupManagementInterface::class,
131150
[],
132151
'',
133152
false,
@@ -140,7 +159,7 @@ protected function setUp()
140159
);
141160

142161
$this->groupInterfaceMock = $this->getMockForAbstractClass(
143-
\Magento\Customer\Api\Data\GroupInterface::class,
162+
GroupInterface::class,
144163
[],
145164
'',
146165
false,
@@ -149,8 +168,8 @@ protected function setUp()
149168
['getId']
150169
);
151170

152-
$shippingAssignmentMock = $this->createMock(\Magento\Quote\Api\Data\ShippingAssignmentInterface::class);
153-
$shippingMock = $this->createMock(\Magento\Quote\Api\Data\ShippingInterface::class);
171+
$shippingAssignmentMock = $this->createMock(ShippingAssignmentInterface::class);
172+
$shippingMock = $this->createMock(ShippingInterface::class);
154173
$shippingAssignmentMock->expects($this->once())->method('getShipping')->willReturn($shippingMock);
155174
$shippingMock->expects($this->once())->method('getAddress')->willReturn($this->quoteAddressMock);
156175

@@ -163,14 +182,14 @@ protected function setUp()
163182
->method('getCustomer')
164183
->will($this->returnValue($this->customerMock));
165184

166-
$this->addressRepository = $this->createMock(\Magento\Customer\Api\AddressRepositoryInterface::class);
167-
$this->customerSession = $this->getMockBuilder(\Magento\Customer\Model\Session::class)
185+
$this->addressRepository = $this->createMock(AddressRepositoryInterface::class);
186+
$this->customerSession = $this->getMockBuilder(Session::class)
168187
->disableOriginalConstructor()
169188
->getMock();
170189

171190
$this->customerMock->expects($this->any())->method('getStoreId')->will($this->returnValue($this->storeId));
172191

173-
$this->model = new \Magento\Quote\Observer\Frontend\Quote\Address\CollectTotalsObserver(
192+
$this->model = new CollectTotalsObserver(
174193
$this->customerAddressMock,
175194
$this->customerVatMock,
176195
$this->vatValidatorMock,
@@ -313,7 +332,7 @@ public function testDispatchWithAddressCustomerVatIdAndCountryId()
313332
$customerVat = "123123123";
314333
$defaultShipping = 1;
315334

316-
$customerAddress = $this->createMock(\Magento\Quote\Model\Quote\Address::class);
335+
$customerAddress = $this->createMock(Address::class);
317336
$customerAddress->expects($this->any())
318337
->method("getVatId")
319338
->willReturn($customerVat);
@@ -350,7 +369,7 @@ public function testDispatchWithEmptyShippingAddress()
350369
$customerVat = "123123123";
351370
$defaultShipping = 1;
352371

353-
$customerAddress = $this->createMock(\Magento\Customer\Api\Data\AddressInterface::class);
372+
$customerAddress = $this->createMock(AddressInterface::class);
354373
$customerAddress->expects($this->once())
355374
->method("getCountryId")
356375
->willReturn($customerCountryCode);

0 commit comments

Comments
 (0)