Skip to content

Commit 033a8d6

Browse files
committed
MAGETWO-56806: [Backport] Performance with Customer Updates to M2.0.x branch
- Convert literal class names to \Namespace\Classname::class
1 parent 35fdff8 commit 033a8d6

File tree

8 files changed

+121
-105
lines changed

8 files changed

+121
-105
lines changed

app/code/Magento/Customer/Model/ResourceModel/Address.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ class Address extends \Magento\Eav\Model\Entity\VersionControl\AbstractEntity
2828
*/
2929
protected $customerRepository;
3030

31+
/**
32+
* @var DeleteRelation
33+
*/
34+
protected $deleteRelation;
35+
36+
/**
37+
* @var CustomerRegistry
38+
*/
39+
protected $customerRegistry;
40+
3141
/**
3242
* @param \Magento\Eav\Model\Entity\Context $context
3343
* @param \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot $entitySnapshot,
@@ -124,7 +134,10 @@ public function delete($object)
124134
*/
125135
private function getDeleteRelation()
126136
{
127-
return ObjectManager::getInstance()->get(DeleteRelation::class);
137+
if ($this->deleteRelation === null) {
138+
$this->deleteRelation = ObjectManager::getInstance()->get(DeleteRelation::class);
139+
}
140+
return $this->deleteRelation;
128141
}
129142

130143
/**
@@ -133,7 +146,10 @@ private function getDeleteRelation()
133146
*/
134147
private function getCustomerRegistry()
135148
{
136-
return ObjectManager::getInstance()->get(CustomerRegistry::class);
149+
if ($this->customerRegistry === null) {
150+
$this->customerRegistry = ObjectManager::getInstance()->get(CustomerRegistry::class);
151+
}
152+
return $this->customerRegistry;
137153
}
138154

139155
/**

app/code/Magento/Customer/Test/Unit/Model/ResourceModel/Address/DeleteRelationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DeleteRelationTest extends \PHPUnit_Framework_TestCase
1919
protected function setUp()
2020
{
2121
$this->customerFactoryMock = $this->getMock(
22-
'Magento\Customer\Model\CustomerFactory',
22+
\Magento\Customer\Model\CustomerFactory::class,
2323
['create'],
2424
[],
2525
'',
@@ -49,7 +49,7 @@ public function testDeleteRelation($addressId, $isDefaultBilling, $isDefaultShip
4949
->getMock();
5050

5151
$addressResource = $this->getMockForAbstractClass(
52-
'Magento\Framework\Model\ResourceModel\Db\AbstractDb',
52+
\Magento\Framework\Model\ResourceModel\Db\AbstractDb::class,
5353
[],
5454
'',
5555
false,

app/code/Magento/Customer/Test/Unit/Model/ResourceModel/AddressRepositoryTest.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -64,34 +64,34 @@ class AddressRepositoryTest extends \PHPUnit_Framework_TestCase
6464

6565
protected function setUp()
6666
{
67-
$this->addressFactory = $this->getMock('Magento\Customer\Model\AddressFactory', ['create'], [], '', false);
68-
$this->addressRegistry = $this->getMock('Magento\Customer\Model\AddressRegistry', [], [], '', false);
69-
$this->customerRegistry = $this->getMock('Magento\Customer\Model\CustomerRegistry', [], [], '', false);
70-
$this->addressResourceModel = $this->getMock('Magento\Customer\Model\ResourceModel\Address', [], [], '', false);
71-
$this->directoryData = $this->getMock('Magento\Directory\Helper\Data', [], [], '', false);
67+
$this->addressFactory = $this->getMock(\Magento\Customer\Model\AddressFactory::class, ['create'], [], '', false);
68+
$this->addressRegistry = $this->getMock(\Magento\Customer\Model\AddressRegistry::class, [], [], '', false);
69+
$this->customerRegistry = $this->getMock(\Magento\Customer\Model\CustomerRegistry::class, [], [], '', false);
70+
$this->addressResourceModel = $this->getMock(\Magento\Customer\Model\ResourceModel\Address::class, [], [], '', false);
71+
$this->directoryData = $this->getMock(\Magento\Directory\Helper\Data::class, [], [], '', false);
7272
$this->addressSearchResultsFactory = $this->getMock(
73-
'Magento\Customer\Api\Data\AddressSearchResultsInterfaceFactory',
73+
\Magento\Customer\Api\Data\AddressSearchResultsInterfaceFactory::class,
7474
['create'],
7575
[],
7676
'',
7777
false
7878
);
7979
$this->addressCollectionFactory = $this->getMock(
80-
'Magento\Customer\Model\ResourceModel\Address\CollectionFactory',
80+
\Magento\Customer\Model\ResourceModel\Address\CollectionFactory::class,
8181
['create'],
8282
[],
8383
'',
8484
false
8585
);
8686
$this->extensionAttributesJoinProcessor = $this->getMockForAbstractClass(
87-
'Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface',
87+
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface::class,
8888
[],
8989
'',
9090
false
9191
);
92-
$this->customer = $this->getMock('Magento\Customer\Model\Customer', [], [], '', false);
92+
$this->customer = $this->getMock(\Magento\Customer\Model\Customer::class, [], [], '', false);
9393
$this->address = $this->getMock(
94-
'Magento\Customer\Model\Address',
94+
\Magento\Customer\Model\Address::class,
9595
[
9696
'getId',
9797
'getCountryId',
@@ -130,9 +130,9 @@ public function testSave()
130130
{
131131
$customerId = 34;
132132
$addressId = 53;
133-
$customerAddress = $this->getMockForAbstractClass('Magento\Customer\Api\Data\AddressInterface', [], '', false);
133+
$customerAddress = $this->getMockForAbstractClass(\Magento\Customer\Api\Data\AddressInterface::class, [], '', false);
134134
$addressCollection =
135-
$this->getMock('Magento\Customer\Model\ResourceModel\Address\Collection', [], [], '', false);
135+
$this->getMock(\Magento\Customer\Model\ResourceModel\Address\Collection::class, [], [], '', false);
136136
$customerAddress->expects($this->atLeastOnce())
137137
->method('getCustomerId')
138138
->willReturn($customerId);
@@ -190,7 +190,7 @@ public function testSaveWithException()
190190
{
191191
$customerId = 34;
192192
$addressId = 53;
193-
$customerAddress = $this->getMockForAbstractClass('Magento\Customer\Api\Data\AddressInterface', [], '', false);
193+
$customerAddress = $this->getMockForAbstractClass(\Magento\Customer\Api\Data\AddressInterface::class, [], '', false);
194194
$customerAddress->expects($this->atLeastOnce())
195195
->method('getCustomerId')
196196
->willReturn($customerId);
@@ -215,9 +215,9 @@ public function testSaveWithException()
215215

216216
protected function prepareMocksForInvalidAddressValidation()
217217
{
218-
$countryModel = $this->getMock('Magento\Directory\Model\Country', [], [], '', false);
218+
$countryModel = $this->getMock(\Magento\Directory\Model\Country::class, [], [], '', false);
219219
$regionCollection = $this->getMock(
220-
'Magento\Directory\Model\ResourceModel\Region\Collection',
220+
\Magento\Directory\Model\ResourceModel\Region\Collection::class,
221221
[],
222222
[],
223223
'',
@@ -264,7 +264,7 @@ protected function prepareMocksForInvalidAddressValidation()
264264

265265
public function testGetById()
266266
{
267-
$customerAddress = $this->getMockForAbstractClass('Magento\Customer\Api\Data\AddressInterface', [], '', false);
267+
$customerAddress = $this->getMockForAbstractClass(\Magento\Customer\Api\Data\AddressInterface::class, [], '', false);
268268
$this->addressRegistry->expects($this->once())
269269
->method('retrieve')
270270
->with(12)
@@ -278,17 +278,17 @@ public function testGetById()
278278

279279
public function testGetList()
280280
{
281-
$filterGroup = $this->getMock('Magento\Framework\Api\Search\FilterGroup', [], [], '', false);
282-
$filter = $this->getMock('Magento\Framework\Api\Filter', [], [], '', false);
283-
$collection = $this->getMock('Magento\Customer\Model\ResourceModel\Address\Collection', [], [], '', false);
281+
$filterGroup = $this->getMock(\Magento\Framework\Api\Search\FilterGroup::class, [], [], '', false);
282+
$filter = $this->getMock(\Magento\Framework\Api\Filter::class, [], [], '', false);
283+
$collection = $this->getMock(\Magento\Customer\Model\ResourceModel\Address\Collection::class, [], [], '', false);
284284
$searchResults = $this->getMockForAbstractClass(
285-
'Magento\Customer\Api\Data\AddressSearchResultsInterface',
285+
\Magento\Customer\Api\Data\AddressSearchResultsInterface::class,
286286
[],
287287
'',
288288
false
289289
);
290290
$searchCriteria = $this->getMockForAbstractClass(
291-
'Magento\Framework\Api\SearchCriteriaInterface',
291+
\Magento\Framework\Api\SearchCriteriaInterface::class,
292292
[],
293293
'',
294294
false
@@ -301,7 +301,7 @@ public function testGetList()
301301
->willReturn($collection);
302302
$this->extensionAttributesJoinProcessor->expects($this->once())
303303
->method('process')
304-
->with($collection, 'Magento\Customer\Api\Data\AddressInterface');
304+
->with($collection, \Magento\Customer\Api\Data\AddressInterface::class);
305305
$searchCriteria->expects($this->once())
306306
->method('getFilterGroups')
307307
->willReturn([$filterGroup]);
@@ -326,7 +326,7 @@ public function testGetList()
326326
$searchResults->expects($this->once())
327327
->method('setTotalCount')
328328
->with(23);
329-
$sortOrder = $this->getMock('Magento\Framework\Api\SortOrder', [], [], '', false);
329+
$sortOrder = $this->getMock(\Magento\Framework\Api\SortOrder::class, [], [], '', false);
330330
$searchCriteria->expects($this->once())
331331
->method('getSortOrders')
332332
->willReturn([$sortOrder]);
@@ -357,7 +357,7 @@ public function testGetList()
357357
$this->address->expects($this->once())
358358
->method('getId')
359359
->willReturn(12);
360-
$customerAddress = $this->getMockForAbstractClass('Magento\Customer\Api\Data\AddressInterface', [], '', false);
360+
$customerAddress = $this->getMockForAbstractClass(\Magento\Customer\Api\Data\AddressInterface::class, [], '', false);
361361
$this->addressRegistry->expects($this->once())
362362
->method('retrieve')
363363
->with(12)
@@ -381,13 +381,13 @@ public function testDelete()
381381
$customerId = 43;
382382

383383
$addressCollection = $this->getMock(
384-
'Magento\Customer\Model\ResourceModel\Address\Collection',
384+
\Magento\Customer\Model\ResourceModel\Address\Collection::class,
385385
[],
386386
[],
387387
'',
388388
false
389389
);
390-
$customerAddress = $this->getMockForAbstractClass('Magento\Customer\Api\Data\AddressInterface', [], '', false);
390+
$customerAddress = $this->getMockForAbstractClass(\Magento\Customer\Api\Data\AddressInterface::class, [], '', false);
391391
$customerAddress->expects($this->once())
392392
->method('getId')
393393
->willReturn($addressId);
@@ -428,7 +428,7 @@ public function testDeleteById()
428428
->method('getCustomerId')
429429
->willReturn($customerId);
430430
$addressCollection = $this->getMock(
431-
'Magento\Customer\Model\ResourceModel\Address\Collection',
431+
\Magento\Customer\Model\ResourceModel\Address\Collection::class,
432432
[],
433433
[],
434434
'',

0 commit comments

Comments
 (0)