Skip to content

Commit 1093d53

Browse files
author
Yu Tang
committed
MAGETWO-33120: Refactor code that uses customer builders in integration tests
1 parent 95c0a37 commit 1093d53

File tree

27 files changed

+342
-360
lines changed

27 files changed

+342
-360
lines changed

dev/tests/integration/testsuite/Magento/Checkout/Block/Onepage/BillingTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ class BillingTest extends \PHPUnit_Framework_TestCase
2222
/** @var \Magento\Quote\Model\Quote\AddressFactory */
2323
protected $_quoteAddressFactory;
2424

25-
/** @var \Magento\Customer\Api\Data\CustomerDataBuilder */
26-
protected $_customerBuilder;
27-
2825
/** @var \Magento\Customer\Api\CustomerRepositoryInterface */
2926
protected $_customerRepository;
3027

@@ -40,7 +37,6 @@ protected function setUp()
4037
{
4138
parent::setUp();
4239
$objectManager = Bootstrap::getObjectManager();
43-
$this->_customerBuilder = $objectManager->create('Magento\Customer\Api\Data\CustomerDataBuilder');
4440
$this->_customerRepository = $objectManager->create('Magento\Customer\Api\CustomerRepositoryInterface');
4541
$customer = $this->_customerRepository->getById(self::FIXTURE_CUSTOMER_ID);
4642

@@ -129,13 +125,11 @@ protected function _updateQuoteCustomerName()
129125
$emptyAddress->setLastname(null);
130126
$this->_block->getQuote()->setBillingAddress($emptyAddress);
131127
$customer = $this->_customerRepository->getById(self::FIXTURE_CUSTOMER_ID);
132-
$customer = $this->_customerBuilder->populate(
133-
$customer
134-
)->setFirstname(
128+
$customer->setFirstname(
135129
self::SAMPLE_FIRST_NAME
136130
)->setLastname(
137131
self::SAMPLE_LAST_NAME
138-
)->create();
132+
);
139133
$this->_block->getQuote()->setCustomer($customer);
140134
$this->_block->getQuote()->save();
141135

dev/tests/integration/testsuite/Magento/Customer/Api/AddressRepositoryTest.php

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,25 @@ class AddressRepositoryTest extends \PHPUnit_Framework_TestCase
2626
/** @var \Magento\Customer\Model\Data\Address[] */
2727
private $_expectedAddresses;
2828

29-
/** @var \Magento\Customer\Api\Data\AddressDataBuilder */
30-
private $_addressBuilder;
29+
/** @var \Magento\Customer\Api\Data\AddressInterfaceFactory */
30+
private $_addressFactory;
31+
32+
/** @var \Magento\Framework\Api\DataObjectHelper */
33+
protected $dataObjectHelper;
3134

3235
protected function setUp()
3336
{
3437
$this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
3538
$this->repository = $this->_objectManager->create('Magento\Customer\Api\AddressRepositoryInterface');
36-
$this->_addressBuilder = $this->_objectManager->create('Magento\Customer\Api\Data\AddressDataBuilder');
39+
$this->_addressFactory = $this->_objectManager->create('Magento\Customer\Api\Data\AddressInterfaceFactory');
40+
$this->dataObjectHelper = $this->_objectManager->create('Magento\Framework\Api\DataObjectHelper');
3741

38-
$builder = $this->_objectManager->create('Magento\Customer\Api\Data\RegionDataBuilder');
39-
$region = $builder
40-
->setRegionCode('AL')
42+
$regionFactory = $this->_objectManager->create('Magento\Customer\Api\Data\RegionInterfaceFactory');
43+
$region = $regionFactory->create();
44+
$region->setRegionCode('AL')
4145
->setRegion('Alabama')
42-
->setRegionId(1)
43-
->create();
44-
$this->_addressBuilder
46+
->setRegionId(1);
47+
$address = $this->_addressFactory->create()
4548
->setId('1')
4649
->setCountryId('US')
4750
->setCustomerId(1)
@@ -53,10 +56,9 @@ protected function setUp()
5356
->setFirstname('John')
5457
->setLastname('Smith')
5558
->setCompany('CompanyName');
56-
$address = $this->_addressBuilder->create();
5759

5860
/* XXX: would it be better to have a clear method for this? */
59-
$this->_addressBuilder
61+
$address2 = $this->_addressFactory->create()
6062
->setId('2')
6163
->setCountryId('US')
6264
->setCustomerId(1)
@@ -67,7 +69,6 @@ protected function setUp()
6769
->setTelephone('3234676')
6870
->setFirstname('John')
6971
->setLastname('Smith');
70-
$address2 = $this->_addressBuilder->create();
7172

7273
$this->_expectedAddresses = [$address, $address2];
7374
}
@@ -90,13 +91,11 @@ public function testSaveAddressChanges()
9091
{
9192
$address = $this->repository->getById(2);
9293

93-
$proposedAddressBuilder = $this->_addressBuilder->populate($address);
94-
$proposedAddressBuilder->setRegion($address->getRegion());
94+
$address->setRegion($address->getRegion());
9595
// change phone #
96-
$proposedAddressBuilder->setTelephone('555' . $address->getTelephone());
97-
$proposedAddressObject = $proposedAddressBuilder->create();
98-
$proposedAddress = $this->repository->save($proposedAddressObject);
99-
$this->assertEquals(2, $proposedAddress->getId());
96+
$address->setTelephone('555' . $address->getTelephone());
97+
$address = $this->repository->save($address);
98+
$this->assertEquals(2, $address->getId());
10099

101100
$savedAddress = $this->repository->getById(2);
102101
$this->assertNotEquals($this->_expectedAddresses[1]->getTelephone(), $savedAddress->getTelephone());
@@ -112,8 +111,7 @@ public function testSaveAddressChanges()
112111
*/
113112
public function testSaveAddressesIdSetButNotAlreadyExisting()
114113
{
115-
$proposedAddressBuilder = $this->_createSecondAddressBuilder()->setId(4200);
116-
$proposedAddress = $proposedAddressBuilder->create();
114+
$proposedAddress = $this->_createSecondAddressBuilder()->setId(4200);
117115
$this->repository->save($proposedAddress);
118116
}
119117

@@ -147,17 +145,16 @@ public function testGetAddressByIdBadAddressId()
147145
*/
148146
public function testSaveNewAddress()
149147
{
150-
$proposedAddress = $this->_createSecondAddressBuilder()->setCustomerId(1)->create();
148+
$proposedAddress = $this->_createSecondAddressBuilder()->setCustomerId(1);
151149

152150
$returnedAddress = $this->repository->save($proposedAddress);
153151
$this->assertNotNull($returnedAddress->getId());
154152

155153
$savedAddress = $this->repository->getById($returnedAddress->getId());
156154

157-
$expectedNewAddressBuilder = $this->_addressBuilder->populate($this->_expectedAddresses[1]);
158-
$expectedNewAddressBuilder->setId($savedAddress->getId());
159-
$expectedNewAddressBuilder->setRegion($this->_expectedAddresses[1]->getRegion());
160-
$expectedNewAddress = $expectedNewAddressBuilder->create();
155+
$expectedNewAddress = $this->_expectedAddresses[1];
156+
$expectedNewAddress->setId($savedAddress->getId());
157+
$expectedNewAddress->setRegion($this->_expectedAddresses[1]->getRegion());
161158
$this->assertEquals($expectedNewAddress, $savedAddress);
162159
}
163160

@@ -168,13 +165,12 @@ public function testSaveNewAddress()
168165
*/
169166
public function testSaveNewAddressWithAttributes()
170167
{
171-
$addressBuilder = $this->_createFirstAddressBuilder()
168+
$proposedAddress = $this->_createFirstAddress()
172169
->setCustomAttribute('firstname', 'Jane')
173170
->setCustomAttribute('id', 4200)
174171
->setCustomAttribute('weird', 'something_strange_with_hair')
175172
->setId(null)
176173
->setCustomerId(1);
177-
$proposedAddress = $addressBuilder->create();
178174

179175
$returnedAddress = $this->repository->save($proposedAddress);
180176

@@ -194,13 +190,12 @@ public function testSaveNewAddressWithAttributes()
194190
*/
195191
public function testSaveNewInvalidAddress()
196192
{
197-
$addressBuilder = $this->_createFirstAddressBuilder()
193+
$address = $this->_createFirstAddress()
198194
->setCustomAttribute('firstname', null)
199195
->setId(null)
200196
->setFirstname(null)
201197
->setLastname(null)
202198
->setCustomerId(1);
203-
$address = $addressBuilder->create();
204199
try {
205200
$this->repository->save($address);
206201
} catch (InputException $exception) {
@@ -214,7 +209,7 @@ public function testSaveNewInvalidAddress()
214209

215210
public function testSaveAddressesCustomerIdNotExist()
216211
{
217-
$proposedAddress = $this->_createSecondAddressBuilder()->setCustomerId(4200)->create();
212+
$proposedAddress = $this->_createSecondAddressBuilder()->setCustomerId(4200);
218213
try {
219214
$this->repository->save($proposedAddress);
220215
$this->fail('Expected exception not thrown');
@@ -225,7 +220,7 @@ public function testSaveAddressesCustomerIdNotExist()
225220

226221
public function testSaveAddressesCustomerIdInvalid()
227222
{
228-
$proposedAddress = $this->_createSecondAddressBuilder()->setCustomerId('this_is_not_a_valid_id')->create();
223+
$proposedAddress = $this->_createSecondAddressBuilder()->setCustomerId('this_is_not_a_valid_id');
229224
try {
230225
$this->repository->save($proposedAddress);
231226
$this->fail('Expected exception not thrown');
@@ -388,26 +383,35 @@ public function searchAddressDataProvider()
388383
/**
389384
* Helper function that returns an Address Data Object that matches the data from customer_address fixture
390385
*
391-
* @return \Magento\Customer\Api\Data\AddressDataBuilder
386+
* @return \Magento\Customer\Api\Data\AddressInterface
392387
*/
393-
private function _createFirstAddressBuilder()
388+
private function _createFirstAddress()
394389
{
395-
$addressBuilder = $this->_addressBuilder->populate($this->_expectedAddresses[0]);
396-
$addressBuilder->setId(null);
397-
$addressBuilder->setRegion($this->_expectedAddresses[0]->getRegion());
398-
return $addressBuilder;
390+
$address = $this->_addressFactory->create();
391+
$this->dataObjectHelper->mergeDataObjects('\Magento\Customer\Api\Data\AddressInterface',
392+
$address,
393+
$this->_expectedAddresses[0]
394+
);
395+
$address->setId(null);
396+
$address->setRegion($this->_expectedAddresses[0]->getRegion());
397+
return $address;
399398
}
400399

401400
/**
402401
* Helper function that returns an Address Data Object that matches the data from customer_two_address fixture
403402
*
404-
* @return \Magento\Customer\Api\Data\AddressDataBuilder
403+
* @return \Magento\Customer\Api\Data\AddressInterface
405404
*/
406405
private function _createSecondAddressBuilder()
407406
{
408-
$addressBuilder = $this->_addressBuilder->populate($this->_expectedAddresses[1]);
409-
$addressBuilder->setId(null);
410-
$addressBuilder->setRegion($this->_expectedAddresses[1]->getRegion());
411-
return $addressBuilder;
407+
$address = $this->_addressFactory->create();
408+
$this->dataObjectHelper->mergeDataObjects(
409+
'\Magento\Customer\Api\Data\AddressInterface',
410+
$address,
411+
$this->_expectedAddresses[1]
412+
);
413+
$address->setId(null);
414+
$address->setRegion($this->_expectedAddresses[1]->getRegion());
415+
return $address;
412416
}
413417
}

dev/tests/integration/testsuite/Magento/Customer/Block/Account/Dashboard/AddressTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public function testGetCustomerMissingCustomer()
6868
{
6969
$moduleManager = $this->objectManager->get('Magento\Framework\Module\Manager');
7070
if ($moduleManager->isEnabled('Magento_PageCache')) {
71-
$customerDataBuilder = $this->objectManager->create('Magento\Customer\Api\Data\CustomerDataBuilder');
72-
$customerData = $customerDataBuilder->setGroupId($this->_customerSession->getCustomerGroupId())->create();
71+
$customerDataFactory = $this->objectManager->create('Magento\Customer\Api\Data\CustomerInterfaceFactory');
72+
$customerData = $customerDataFactory->create()->setGroupId($this->_customerSession->getCustomerGroupId());
7373
$this->assertEquals($customerData, $this->_block->getCustomer());
7474
} else {
7575
$this->assertNull($this->_block->getCustomer());

dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/AccountTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ public function testNotReadOnly()
167167
*/
168168
public function testNewCustomer()
169169
{
170-
/** @var \Magento\Customer\Api\Data\CustomerDataBuilder $customerBuilder */
171-
$customerBuilder = $this->objectManager->get('Magento\Customer\Api\Data\CustomerDataBuilder');
170+
/** @var \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory */
171+
$customerFactory = $this->objectManager->get('Magento\Customer\Api\Data\CustomerInterfaceFactory');
172172
$customerData = $this->dataObjectProcessor
173-
->buildOutputDataArray($customerBuilder->create(), '\Magento\Customer\Api\Data\CustomerInterface');
173+
->buildOutputDataArray($customerFactory->create(), '\Magento\Customer\Api\Data\CustomerInterface');
174174
$this->backendSession->setCustomerData(
175175
['customer_id' => 0, 'account' => $customerData]
176176
);

dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/View/PersonalInfoTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
namespace Magento\Customer\Block\Adminhtml\Edit\Tab\View;
77

8-
use Magento\Customer\Api\Data\CustomerDataBuilder;
8+
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
99
use Magento\Customer\Controller\RegistryConstants;
1010

1111
/**
@@ -22,8 +22,8 @@ class PersonalInfoTest extends \PHPUnit_Framework_TestCase
2222
/** @var \Magento\Framework\Registry */
2323
private $_coreRegistry;
2424

25-
/** @var CustomerDataBuilder */
26-
private $_customerBuilder;
25+
/** @var CustomerInterfaceFactory */
26+
private $_customerFactory;
2727

2828
/** @var \Magento\Customer\Api\CustomerRepositoryInterface */
2929
private $_customerRepository;
@@ -58,7 +58,7 @@ public function setUp()
5858
['storeManager' => $this->_storeManager]
5959
);
6060

61-
$this->_customerBuilder = $this->_objectManager->get('Magento\Customer\Api\Data\CustomerDataBuilder');
61+
$this->_customerFactory = $this->_objectManager->get('Magento\Customer\Api\Data\CustomerInterfaceFactory');
6262
$this->_coreRegistry = $this->_objectManager->get('Magento\Framework\Registry');
6363
$this->_customerRepository = $this->_objectManager->get(
6464
'Magento\Customer\Api\CustomerRepositoryInterface'
@@ -184,15 +184,15 @@ public function testIsConfirmedStatusConfirmationIsNotRequired()
184184
{
185185
$password = 'password';
186186
/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
187-
$customer = $this->_customerBuilder->setConfirmation(
187+
$customer = $this->_customerFactory->create()->setConfirmation(
188188
true
189189
)->setFirstname(
190190
'firstname'
191191
)->setLastname(
192192
'lastname'
193193
)->setEmail(
194194
'email@email.com'
195-
)->create();
195+
);
196196
$customer = $this->_customerRepository->save($customer, $password);
197197
$this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customer->getId());
198198
$this->assertEquals('Confirmation Not Required', $this->_block->getIsConfirmedStatus());
@@ -235,13 +235,13 @@ public function testGetBillingAddressHtmlNoDefaultAddress()
235235
private function _createCustomer()
236236
{
237237
/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
238-
$customer = $this->_customerBuilder->setFirstname(
238+
$customer = $this->_customerFactory->create()->setFirstname(
239239
'firstname'
240240
)->setLastname(
241241
'lastname'
242242
)->setEmail(
243243
'email@email.com'
244-
)->create();
244+
);
245245
$data = ['account' => $this->_dataObjectProcessor
246246
->buildOutputDataArray($customer, 'Magento\Customer\Api\Data\CustomerInterface'), ];
247247
$this->_context->getBackendSession()->setCustomerData($data);

dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/ViewTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Magento\Customer\Block\Adminhtml\Edit\Tab;
77

88
use Magento\Customer\Api\CustomerRepositoryInterface;
9-
use Magento\Customer\Api\Data\CustomerDataBuilder;
9+
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
1010
use Magento\Customer\Controller\RegistryConstants;
1111

1212
/**
@@ -24,7 +24,7 @@ class ViewTest extends \PHPUnit_Framework_TestCase
2424
private $_coreRegistry;
2525

2626
/** @var CustomerDataBuilder */
27-
private $_customerBuilder;
27+
private $_customerFactory;
2828

2929
/** @var CustomerRepositoryInterface */
3030
private $_customerRepository;
@@ -51,7 +51,7 @@ public function setUp()
5151
['storeManager' => $this->_storeManager]
5252
);
5353

54-
$this->_customerBuilder = $this->_objectManager->get('Magento\Customer\Api\Data\CustomerDataBuilder');
54+
$this->_customerFactory = $this->_objectManager->get('Magento\Customer\Api\Data\CustomerInterfaceFactory');
5555
$this->_coreRegistry = $this->_objectManager->get('Magento\Framework\Registry');
5656
$this->_customerRepository = $this->_objectManager->get(
5757
'Magento\Customer\Api\CustomerRepositoryInterface'
@@ -121,13 +121,13 @@ public function testIsHidden()
121121
private function _createCustomer()
122122
{
123123
/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
124-
$customer = $this->_customerBuilder->setFirstname(
124+
$customer = $this->_customerFactory->create()->setFirstname(
125125
'firstname'
126126
)->setLastname(
127127
'lastname'
128128
)->setEmail(
129129
'email@email.com'
130-
)->create();
130+
);
131131
$data = ['account' => $this->_dataObjectProcessor
132132
->buildOutputDataArray($customer, 'Magento\Customer\Api\Data\CustomerInterface'), ];
133133
$this->_context->getBackendSession()->setCustomerData($data);

0 commit comments

Comments
 (0)