Skip to content

Commit 58bf0d4

Browse files
authored
Merge pull request #545 from magento-performance/ACPT-1360
ACPT-1360: Automated test to validate _resetState methods cause same state as initially constructed
2 parents 0d00c69 + 9f4f820 commit 58bf0d4

File tree

34 files changed

+360
-73
lines changed

34 files changed

+360
-73
lines changed

app/code/Magento/Backup/Model/Fs/Collection.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,20 @@ public function __construct(
6161
) {
6262
$this->_backupData = $backupData;
6363
parent::__construct($entityFactory, $filesystem);
64-
6564
$this->_filesystem = $filesystem;
6665
$this->_backup = $backup;
6766
$this->_varDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
68-
6967
$this->_hideBackupsForApache();
68+
$this->initialize();
69+
}
7070

71+
private function initialize() {
7172
// set collection specific params
7273
$extensions = $this->_backupData->getExtensions();
73-
7474
foreach ($extensions as $value) {
7575
$extensions[] = '(' . preg_quote($value, '/') . ')';
7676
}
7777
$extensions = implode('|', $extensions);
78-
7978
$this->_varDirectory->create($this->_path);
8079
$path = rtrim($this->_varDirectory->getAbsolutePath($this->_path), '/') . '/';
8180
$this->setOrder(
@@ -90,6 +89,15 @@ public function __construct(
9089
);
9190
}
9291

92+
/**
93+
* @inheritDoc
94+
*/
95+
public function _resetState(): void
96+
{
97+
parent::_resetState();
98+
$this->initialize();
99+
}
100+
93101
/**
94102
* Create .htaccess file and deny backups directory access from web
95103
*

app/code/Magento/Bundle/Pricing/Adjustment/DefaultSelectionPriceListProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,6 @@ private function getBundleOptions(Product $saleableItem)
252252
*/
253253
public function _resetState(): void
254254
{
255-
$this->priceList = [];
255+
$this->priceList = null;
256256
}
257257
}

app/code/Magento/Catalog/Model/CategoryRepository/PopulateWithValues.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,6 @@ private function getAttributes(): array
157157
*/
158158
public function _resetState(): void
159159
{
160-
$this->attributes = [];
160+
$this->attributes = null;
161161
}
162162
}

app/code/Magento/Catalog/Model/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2840,7 +2840,7 @@ public function _resetState(): void
28402840
{
28412841
$this->_customOptions = [];
28422842
$this->_errors = [];
2843-
$this->_canAffectOptions = [];
2843+
$this->_canAffectOptions = false;
28442844
$this->_productIdCached = null;
28452845
}
28462846
}

app/code/Magento/Catalog/Model/ResourceModel/Collection/AbstractCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public function __construct(
8181
*/
8282
public function _resetState(): void
8383
{
84-
parent::_resetState();
8584
$this->_storeId = null;
85+
parent::_resetState();
8686
}
8787

8888
/**

app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ public function __construct(
397397
*/
398398
public function _resetState(): void
399399
{
400-
parent::_resetState();
401400
$this->_flatEnabled = [];
402401
$this->_addUrlRewrite = false;
403402
$this->_urlRewriteCategory = '';
@@ -419,7 +418,7 @@ public function _resetState(): void
419418
$this->linkField = null;
420419
$this->backend = null;
421420
$this->emptyItem = null;
422-
$this->_construct();
421+
parent::_resetState();
423422
}
424423

425424
/**

app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ public function __construct(
224224
*/
225225
public function _resetState(): void
226226
{
227-
parent::_resetState();
228227
$this->queryText = null;
229228
$this->search = null;
230229
$this->searchCriteriaBuilder = null;
231230
$this->searchResult = null;
232231
$this->filterBuilder = null;
233232
$this->searchOrders = null;
233+
parent::_resetState();
234234
}
235235

236236
/**

app/code/Magento/Cms/Model/ResourceModel/Block/Grid/Collection.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ class Collection extends BlockCollection implements SearchResultInterface
3434
*/
3535
protected $aggregations;
3636

37+
/** @var string */
38+
private $model;
39+
40+
/** @var string */
41+
private $resourceModel;
42+
3743
/**
3844
* @param EntityFactoryInterface $entityFactory
3945
* @param LoggerInterface $logger
@@ -68,6 +74,8 @@ public function __construct(
6874
AbstractDb $resource = null,
6975
TimezoneInterface $timeZone = null
7076
) {
77+
$this->resourceModel = $resourceModel;
78+
$this->model = $model;
7179
parent::__construct(
7280
$entityFactory,
7381
$logger,
@@ -80,11 +88,20 @@ public function __construct(
8088
);
8189
$this->_eventPrefix = $eventPrefix;
8290
$this->_eventObject = $eventObject;
83-
$this->_init($model, $resourceModel);
91+
$this->_init($this->model, $this->resourceModel);
8492
$this->setMainTable($mainTable);
8593
$this->timeZone = $timeZone ?: ObjectManager::getInstance()->get(TimezoneInterface::class);
8694
}
8795

96+
/**
97+
* @inheritDoc
98+
*/
99+
public function _resetState(): void
100+
{
101+
parent::_resetState();
102+
$this->_init($this->model, $this->resourceModel);
103+
}
104+
88105
/**
89106
* @inheritDoc
90107
*/

app/code/Magento/Cms/Model/ResourceModel/Page/Grid/Collection.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ class Collection extends PageCollection implements SearchResultInterface
3434
*/
3535
protected $aggregations;
3636

37+
/** @var mixed */
38+
private $model;
39+
40+
/** @var string */
41+
private $resourceModel;
42+
3743
/**
3844
* @param EntityFactoryInterface $entityFactory
3945
* @param LoggerInterface $logger
@@ -68,6 +74,8 @@ public function __construct(
6874
AbstractDb $resource = null,
6975
TimezoneInterface $timeZone = null
7076
) {
77+
$this->resourceModel = $resourceModel;
78+
$this->model = $model;
7179
parent::__construct(
7280
$entityFactory,
7381
$logger,
@@ -80,11 +88,20 @@ public function __construct(
8088
);
8189
$this->_eventPrefix = $eventPrefix;
8290
$this->_eventObject = $eventObject;
83-
$this->_init($model, $resourceModel);
91+
$this->_init($this->model, $this->resourceModel);
8492
$this->setMainTable($mainTable);
8593
$this->timeZone = $timeZone ?: ObjectManager::getInstance()->get(TimezoneInterface::class);
8694
}
8795

96+
/**
97+
* @inheritDoc
98+
*/
99+
public function _resetState(): void
100+
{
101+
parent::_resetState();
102+
$this->_init($this->model, $this->resourceModel);
103+
}
104+
88105
/**
89106
* @inheritDoc
90107
*/

app/code/Magento/ConfigurableProduct/Model/Product/VariationHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class VariationHandler implements ResetAfterRequestInterface
4545
protected $productFactory;
4646

4747
/**
48-
* @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute[]
48+
* @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute[]|null
4949
*/
5050
private $attributes;
5151

@@ -309,6 +309,6 @@ function ($image) {
309309
*/
310310
public function _resetState(): void
311311
{
312-
$this->attributes = [];
312+
$this->attributes = null;
313313
}
314314
}

app/code/Magento/ConfigurableProduct/Pricing/Price/ConfigurableOptionsProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ConfigurableOptionsProvider implements ConfigurableOptionsProviderInterfac
2222
private $configurable;
2323

2424
/**
25-
* @var ProductInterface[]
25+
* @var ProductInterface[]|null
2626
*/
2727
private $products;
2828

@@ -63,6 +63,6 @@ public function getProducts(ProductInterface $product)
6363
*/
6464
public function _resetState(): void
6565
{
66-
$this->products = [];
66+
$this->products = null;
6767
}
6868
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ public function isAttributeVisible($code)
429429
public function _resetState(): void
430430
{
431431
$this->_config = [];
432-
$this->_attributes = [];
432+
$this->_attributes = null;
433433
$this->_streetLines = [];
434434
}
435435
}

app/code/Magento/Customer/Model/Metadata/AttributeMetadataCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class AttributeMetadataCache implements ResetAfterRequestInterface
3636
private $state;
3737

3838
/**
39-
* @var AttributeMetadataInterface[]
39+
* @var AttributeMetadataInterface[]|null
4040
*/
4141
private $attributes;
4242

@@ -180,6 +180,6 @@ private function isEnabled()
180180
*/
181181
public function _resetState(): void
182182
{
183-
$this->attributes = [];
183+
$this->attributes = null;
184184
}
185185
}

app/code/Magento/Customer/Model/ResourceModel/Group/Grid/Collection.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ class Collection extends GroupCollection implements SearchResultInterface
2121
*/
2222
protected $aggregations;
2323

24+
/** @var string */
25+
private $model;
26+
27+
/** @var string */
28+
private $resourceModel;
29+
2430
/**
2531
* @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
2632
* @param \Psr\Log\LoggerInterface $logger
@@ -49,6 +55,8 @@ public function __construct(
4955
$connection = null,
5056
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
5157
) {
58+
$this->resourceModel = $resourceModel;
59+
$this->model = $model;
5260
parent::__construct(
5361
$entityFactory,
5462
$logger,
@@ -59,10 +67,19 @@ public function __construct(
5967
);
6068
$this->_eventPrefix = $eventPrefix;
6169
$this->_eventObject = $eventObject;
62-
$this->_init($model, $resourceModel);
70+
$this->_init($this->model, $this->resourceModel);
6371
$this->setMainTable($mainTable);
6472
}
6573

74+
/**
75+
* @inheritDoc
76+
*/
77+
public function _resetState(): void
78+
{
79+
parent::_resetState();
80+
$this->_init($this->model, $this->resourceModel);
81+
}
82+
6683
/**
6784
* Resource initialization
6885
* @return $this

app/code/Magento/Directory/Model/ResourceModel/Currency.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,6 @@ protected function _getRatesByCode($code, $toCurrencies = null)
241241
*/
242242
public function _resetState(): void
243243
{
244-
self::$_rateCache = [];
244+
self::$_rateCache = null;
245245
}
246246
}

app/code/Magento/Eav/Model/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ private function getWebsiteId(Collection $attributeCollection): int
989989
public function _resetState(): void
990990
{
991991
$this->attributesPerSet = [];
992-
$this->_attributeData = [];
992+
$this->_attributeData = null;
993993
foreach ($this->attributes ?? [] as $attributesGroupedByEntityTypeCode) {
994994
foreach ($attributesGroupedByEntityTypeCode as $attribute) {
995995
if ($attribute instanceof ResetAfterRequestInterface) {

app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,6 @@ public function getFlatUpdateSelect($store)
302302
public function _resetState(): void
303303
{
304304
$this->_optionsDefault = [];
305-
$this->_options = [];
305+
$this->_options = null;
306306
}
307307
}

app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ protected function _construct()
186186
*/
187187
public function _resetState(): void
188188
{
189-
parent::_resetState();
190189
$this->_itemsById = [];
191190
$this->_staticFields = [];
192191
$this->_entity = null;
@@ -196,6 +195,11 @@ public function _resetState(): void
196195
$this->_joinEntities = [];
197196
$this->_joinAttributes = [];
198197
$this->_joinFields = [];
198+
parent::_resetState();
199+
$this->_construct();
200+
$this->setConnection($this->getEntity()->getConnection());
201+
$this->_prepareStaticFields();
202+
$this->_initSelect();
199203
}
200204

201205
/**

app/code/Magento/Eav/Model/ResourceModel/Form/Attribute/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ protected function _construct()
101101
*/
102102
public function _resetState(): void
103103
{
104-
parent::_resetState();
105104
$this->_store = null;
106105
$this->_entityType = null;
106+
parent::_resetState();
107107
}
108108

109109
/**

app/code/Magento/GiftMessage/Model/OrderItemRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,6 @@ protected function getItemById($orderId, $orderItemId)
180180
*/
181181
public function _resetState(): void
182182
{
183-
$this->orders = [];
183+
$this->orders = null;
184184
}
185185
}

app/code/Magento/GroupedProductGraphQl/Model/Resolver/Product/Price/Provider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Provider implements ProviderInterface, ResetAfterRequestInterface
2323
/**
2424
* Cache product prices so only fetch once
2525
*
26-
* @var AmountInterface[]
26+
* @var AmountInterface[]|null
2727
*/
2828
private $minimalProductAmounts;
2929

@@ -100,6 +100,6 @@ private function getMinimalProductAmount(SaleableInterface $product, string $pri
100100
*/
101101
public function _resetState(): void
102102
{
103-
$this->minimalProductAmounts = [];
103+
$this->minimalProductAmounts = null;
104104
}
105105
}

0 commit comments

Comments
 (0)