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
}

0 commit comments

Comments
 (0)