Skip to content

Commit 9a444e6

Browse files
ACPT-1552
* Fixing AbstractAddress to properly use its new cache classes * Updating its unit tests and subclasses * Fix static test failure in LoggerProxy
1 parent 77c0895 commit 9a444e6

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Magento\Customer\Api\Data\AddressInterface;
1010
use Magento\Customer\Api\Data\AddressInterfaceFactory;
1111
use Magento\Customer\Api\Data\RegionInterfaceFactory;
12+
use Magento\Customer\Model\Address\AbstractAddress\CountryModelsCache;
13+
use Magento\Customer\Model\Address\AbstractAddress\RegionModelsCache;
1214
use Magento\Framework\Indexer\StateInterface;
1315

1416
/**
@@ -74,6 +76,8 @@ class Address extends \Magento\Customer\Model\Address\AbstractAddress
7476
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
7577
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
7678
* @param array $data
79+
* @param CountryModelsCache|null $countryModelsCache
80+
* @param RegionModelsCache|null $regionModelsCache
7781
*
7882
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
7983
*/
@@ -96,7 +100,9 @@ public function __construct(
96100
\Magento\Framework\Indexer\IndexerRegistry $indexerRegistry,
97101
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
98102
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
99-
array $data = []
103+
array $data = [],
104+
?CountryModelsCache $countryModelsCache = null,
105+
?RegionModelsCache $regionModelsCache = null,
100106
) {
101107
$this->dataProcessor = $dataProcessor;
102108
$this->_customerFactory = $customerFactory;
@@ -117,7 +123,9 @@ public function __construct(
117123
$dataObjectHelper,
118124
$resource,
119125
$resourceCollection,
120-
$data
126+
$data,
127+
$countryModelsCache,
128+
$regionModelsCache,
121129
);
122130
}
123131

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ public function getCountry()
522522
*/
523523
public function getCountryModel()
524524
{
525-
if ($country = $this->countryModelsCache->get($this->getCountryId())) {
525+
if (!($country = $this->countryModelsCache->get($this->getCountryId()))) {
526526
$country = $this->_createCountryInstance();
527527
$country->load($this->getCountryId());
528528
$this->countryModelsCache->add($this->getCountryId(), $country);
@@ -541,7 +541,7 @@ public function getRegionModel($regionId = null)
541541
if ($regionId === null) {
542542
$regionId = $this->getRegionId();
543543
}
544-
if ($region = $this->regionModelsCache->get($regionId)) {
544+
if (!($region = $this->regionModelsCache->get($regionId))) {
545545
$region = $this->_createRegionInstance();
546546
$region->load($regionId);
547547
$this->regionModelsCache->add($regionId, $region);

app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2525
use PHPUnit\Framework\MockObject\MockObject;
2626
use PHPUnit\Framework\TestCase;
27+
use Magento\Customer\Model\Address\AbstractAddress\RegionModelsCache;
28+
use Magento\Customer\Model\Address\AbstractAddress\CountryModelsCache;
2729

2830
/**
2931
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -109,6 +111,8 @@ protected function setUp(): void
109111
'resource' => $this->resourceMock,
110112
'resourceCollection' => $this->resourceCollectionMock,
111113
'compositeValidator' => $this->compositeValidatorMock,
114+
'countryModelsCache' => new CountryModelsCache,
115+
'regionModelsCache' => new RegionModelsCache,
112116
]
113117
);
114118
}

app/code/Magento/Quote/Model/Quote/Address.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Customer\Api\Data\AddressInterfaceFactory;
1111
use Magento\Customer\Api\Data\RegionInterfaceFactory;
1212
use Magento\Customer\Model\Address\AbstractAddress;
13+
use Magento\Customer\Model\Address\AbstractAddress\CountryModelsCache;
14+
use Magento\Customer\Model\Address\AbstractAddress\RegionModelsCache;
1315
use Magento\Customer\Model\Address\Mapper;
1416
use Magento\Directory\Helper\Data;
1517
use Magento\Directory\Model\CountryFactory;
@@ -335,6 +337,8 @@ class Address extends AbstractAddress implements
335337
* @param array $data
336338
* @param Json $serializer
337339
* @param StoreManagerInterface $storeManager
340+
* @param CountryModelsCache|null $countryModelsCache
341+
* @param RegionModelsCache|null $regionModelsCache
338342
*
339343
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
340344
*/
@@ -372,7 +376,9 @@ public function __construct(
372376
AbstractDb $resourceCollection = null,
373377
array $data = [],
374378
Json $serializer = null,
375-
StoreManagerInterface $storeManager = null
379+
StoreManagerInterface $storeManager = null,
380+
?CountryModelsCache $countryModelsCache = null,
381+
?RegionModelsCache $regionModelsCache = null,
376382
) {
377383
$this->_scopeConfig = $scopeConfig;
378384
$this->_addressItemFactory = $addressItemFactory;
@@ -409,7 +415,9 @@ public function __construct(
409415
$dataObjectHelper,
410416
$resource,
411417
$resourceCollection,
412-
$data
418+
$data,
419+
$countryModelsCache,
420+
$regionModelsCache,
413421
);
414422
}
415423

lib/internal/Magento/Framework/Logger/LoggerProxy.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public function __construct(
4040
$this->objectManager = $objectManager;
4141
}
4242

43+
/**
44+
* @inheritDoc
45+
*/
4346
public function _resetState(): void
4447
{
4548
$this->logger = null;

0 commit comments

Comments
 (0)