Skip to content

Commit 6cf3e85

Browse files
Merge branch 'MAGNIMEX-13-static-tests' into 'master'
Magnimex 13 static tests MAGNIMEX-13: Import history - Fix static tests See merge request !178
2 parents 64f8f86 + 5b90cfd commit 6cf3e85

File tree

15 files changed

+113
-81
lines changed

15 files changed

+113
-81
lines changed

app/code/Magento/AdvancedPricingImportExport/Model/Export/AdvancedPricing.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ protected function getExportData()
305305
/**
306306
* @param array $exportData
307307
* @return array
308+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
308309
*/
309310
protected function correctExportData($exportData)
310311
{
@@ -343,6 +344,8 @@ protected function correctExportData($exportData)
343344
* @param array $listSku
344345
* @param string $table
345346
* @return array|bool
347+
* @SuppressWarnings(PHPMD.NPathComplexity)
348+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
346349
*/
347350
protected function getTierAndGroupPrices(array $listSku, $table)
348351
{

app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ public function replaceAdvancedPricing()
305305
* Save and replace advanced prices
306306
*
307307
* @return $this
308+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
308309
*/
309310
protected function saveAndReplaceAdvancedPrices()
310311
{

app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Export/AdvancedPricingTest.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,14 @@ public function testExportZeroConditionCalls()
357357
$itemsPerPage = 10;
358358

359359
$this->advancedPricing->expects($this->once())->method('getWriter')->willReturn($this->writer);
360-
$this->advancedPricing->expects($this->exactly(1))->method('_getEntityCollection')->willReturn($this->abstractCollection);
361-
$this->advancedPricing->expects($this->once())->method('_prepareEntityCollection')->with($this->abstractCollection);
360+
$this->advancedPricing
361+
->expects($this->exactly(1))
362+
->method('_getEntityCollection')
363+
->willReturn($this->abstractCollection);
364+
$this->advancedPricing
365+
->expects($this->once())
366+
->method('_prepareEntityCollection')
367+
->with($this->abstractCollection);
362368
$this->advancedPricing->expects($this->once())->method('getItemsPerPage')->willReturn($itemsPerPage);
363369
$this->advancedPricing->expects($this->once())->method('paginateCollection')->with($page, $itemsPerPage);
364370
$this->abstractCollection->expects($this->once())->method('setOrder')->with('has_options', 'asc');
@@ -383,8 +389,14 @@ public function testExportCurrentPageCalls()
383389
$curPage = $lastPage = $page = 1;
384390
$itemsPerPage = 10;
385391
$this->advancedPricing->expects($this->once())->method('getWriter')->willReturn($this->writer);
386-
$this->advancedPricing->expects($this->exactly(1))->method('_getEntityCollection')->willReturn($this->abstractCollection);
387-
$this->advancedPricing->expects($this->once())->method('_prepareEntityCollection')->with($this->abstractCollection);
392+
$this->advancedPricing
393+
->expects($this->exactly(1))
394+
->method('_getEntityCollection')
395+
->willReturn($this->abstractCollection);
396+
$this->advancedPricing
397+
->expects($this->once())
398+
->method('_prepareEntityCollection')
399+
->with($this->abstractCollection);
388400
$this->advancedPricing->expects($this->once())->method('getItemsPerPage')->willReturn($itemsPerPage);
389401
$this->advancedPricing->expects($this->once())->method('paginateCollection')->with($page, $itemsPerPage);
390402
$this->abstractCollection->expects($this->once())->method('setOrder')->with('has_options', 'asc');

app/code/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractType.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
*/
1313
abstract class AbstractType
1414
{
15-
static $commonAttributesCache = [];
15+
/**
16+
* Common attributes cache
17+
*
18+
* @var array
19+
*/
20+
public static $commonAttributesCache = [];
1621

1722
/**
1823
* Product type attribute sets and attributes parameters.
@@ -176,7 +181,7 @@ protected function _getProductAttributes($attrSetData)
176181
protected function _initAttributes()
177182
{
178183
// temporary storage for attributes' parameters to avoid double querying inside the loop
179-
$entity_id = $this->_entityModel->getEntityTypeId();
184+
$entityId = $this->_entityModel->getEntityTypeId();
180185
$entityAttributes = $this->_connection->fetchPairs(
181186
$this->_connection->select()->from(
182187
['attr' => $this->_resource->getTableName('eav_entity_attribute')],
@@ -186,27 +191,27 @@ protected function _initAttributes()
186191
'set.attribute_set_id = attr.attribute_set_id',
187192
['set.attribute_set_name']
188193
)->where(
189-
$this->_connection->quoteInto('attr.entity_type_id IN (?)', $entity_id)
194+
$this->_connection->quoteInto('attr.entity_type_id IN (?)', $entityId)
190195
)
191196
);
192197
$absentKeys = [];
193-
foreach ($entityAttributes as $attribute_id => $attributeSetName) {
194-
if (!isset(self::$commonAttributesCache[$attribute_id])) {
198+
foreach ($entityAttributes as $attributeId => $attributeSetName) {
199+
if (!isset(self::$commonAttributesCache[$attributeId])) {
195200
if (!isset($absentKeys[$attributeSetName])) {
196201
$absentKeys[$attributeSetName] = [];
197202
}
198-
$absentKeys[$attributeSetName][] = $attribute_id;
203+
$absentKeys[$attributeSetName][] = $attributeId;
199204
}
200205
}
201206
foreach ($absentKeys as $attributeSetName => $attributeIds) {
202207
$this->attachAttributesById($attributeSetName, $attributeIds);
203208
}
204-
foreach ($entityAttributes as $attribute_id => $attributeSetName) {
205-
if (isset(self::$commonAttributesCache[$attribute_id])) {
206-
$attribute = self::$commonAttributesCache[$attribute_id];
209+
foreach ($entityAttributes as $attributeId => $attributeSetName) {
210+
if (isset(self::$commonAttributesCache[$attributeId])) {
211+
$attribute = self::$commonAttributesCache[$attributeId];
207212
$this->_addAttributeParams(
208213
$attributeSetName,
209-
self::$commonAttributesCache[$attribute_id],
214+
self::$commonAttributesCache[$attributeId],
210215
$attribute
211216
);
212217
}
@@ -215,12 +220,18 @@ protected function _initAttributes()
215220
}
216221

217222
/**
223+
* Attach Attributes By Id
224+
*
218225
* @param string $attributeSetName
219226
* @param array $attributeIds
227+
* @return void
220228
*/
221229
protected function attachAttributesById($attributeSetName, $attributeIds)
222230
{
223-
foreach ($this->_prodAttrColFac->create()->addFieldToFilter('main_table.attribute_id', ['in' => $attributeIds]) as $attribute) {
231+
foreach ($this->_prodAttrColFac->create()->addFieldToFilter(
232+
'main_table.attribute_id',
233+
['in' => $attributeIds]
234+
) as $attribute) {
224235
$attributeCode = $attribute->getAttributeCode();
225236
$attributeId = $attribute->getId();
226237

app/code/Magento/CatalogUrlRewrite/Model/Product/Plugin/Import.php

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
use Magento\UrlRewrite\Model\OptionProvider;
2020
use Magento\UrlRewrite\Model\UrlFinderInterface;
2121

22+
/**
23+
* Class Import
24+
*
25+
* @SuppressWarnings(PHPMD.TooManyFields)
26+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27+
*/
2228
class Import
2329
{
2430
/**
@@ -68,8 +74,10 @@ class Import
6874
/** @var \Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator */
6975
protected $productUrlPathGenerator;
7076

77+
/** @var array */
7178
protected $websitesToStoreIds;
7279

80+
/** @var array */
7381
protected $entityStoresToCheckOverridden = [];
7482

7583
/** @var array */
@@ -101,6 +109,7 @@ class Import
101109
* @param UrlRewriteFactory $urlRewriteFactory
102110
* @param UrlFinderInterface $urlFinder
103111
* @throws \InvalidArgumentException
112+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
104113
*/
105114
public function __construct(
106115
\Magento\Catalog\Model\ProductFactory $catalogProductFactory,
@@ -123,7 +132,10 @@ public function __construct(
123132
$this->urlRewriteFactory = $urlRewriteFactory;
124133
$attribute = $eavConfig->getAttribute(Product::ENTITY, self::URL_KEY_ATTRIBUTE_CODE);
125134
if (!$attribute) {
126-
throw new \InvalidArgumentException(sprintf('Cannot retrieve attribute for entity type "%s"', Product::ENTITY_TYPE));
135+
throw new \InvalidArgumentException(sprintf(
136+
'Cannot retrieve attribute for entity type "%s"',
137+
Product::ENTITY_TYPE
138+
));
127139
}
128140
$this->connection = $resource->getConnection(Resource::DEFAULT_READ_RESOURCE);
129141
$this->urlKeyAttributeId = $attribute->getId();
@@ -156,9 +168,10 @@ public function afterImportData(Observer $observer)
156168
/**
157169
* Create product model from imported data for URL rewrite purposes.
158170
*
159-
* @param $rowData
171+
* @param array $rowData
160172
*
161173
* @return Import
174+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
162175
*/
163176
protected function _populateForUrlGeneration($rowData)
164177
{
@@ -197,8 +210,10 @@ protected function _populateForUrlGeneration($rowData)
197210
}
198211

199212
/**
200-
* @param $product
201-
* @param $storeId
213+
* Add product to import
214+
*
215+
* @param \Magento\CatalogImportExport\Model\Import\Product $product
216+
* @param string $storeId
202217
* @return $this
203218
*/
204219
protected function addProductToImport($product, $storeId)
@@ -210,6 +225,12 @@ protected function addProductToImport($product, $storeId)
210225
return $this;
211226
}
212227

228+
/**
229+
* Populate global product
230+
*
231+
* @param \Magento\CatalogImportExport\Model\Import\Product $product
232+
* @return $this
233+
*/
213234
protected function populateGlobalProduct($product)
214235
{
215236
foreach ($this->import->getProductWebsites($product->getSku()) as $websiteId) {
@@ -218,12 +239,12 @@ protected function populateGlobalProduct($product)
218239
if (!$this->isGlobalScope($storeId)) {
219240
$this->addProductToImport($product, $storeId);
220241
$this->entityStoresToCheckOverridden[] = $this->connection->quoteInto(
221-
'(store_id = ?',
222-
$storeId
223-
) . $this->connection->quoteInto(
224-
' AND entity_id = ?)',
225-
$product->getId()
226-
);
242+
'(store_id = ?',
243+
$storeId
244+
) . $this->connection->quoteInto(
245+
' AND entity_id = ?)',
246+
$product->getId()
247+
);
227248
}
228249
}
229250
}

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Product/Plugin/ImportTest.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,15 @@ public function testCurrentUrlRewritesRegenerateForCustomWithoutTargetPathGenera
10921092
])));
10931093
$this->productUrlPathGenerator->expects($this->never())->method('getUrlPathWithSuffix');
10941094
$this->product->expects($this->any())->method('getId')->will($this->returnValue($productId));
1095-
$this->currentUrlRewritesRegeneratorPrepareUrlRewriteMock($storeId, $productId, $requestPath, $targetPath, 0, [], $description);
1095+
$this->currentUrlRewritesRegeneratorPrepareUrlRewriteMock(
1096+
$storeId,
1097+
$productId,
1098+
$requestPath,
1099+
$targetPath,
1100+
0,
1101+
[],
1102+
$description
1103+
);
10961104

10971105
$actualResult = $this->import->currentUrlRewritesRegenerate();
10981106
$this->assertEquals(
@@ -1135,7 +1143,15 @@ public function testCurrentUrlRewritesRegenerateForCustomWithTargetPathGeneratio
11351143
$this->productUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')
11361144
->will($this->returnValue($targetPath));
11371145
$this->product->expects($this->any())->method('getId')->will($this->returnValue($productId));
1138-
$this->currentUrlRewritesRegeneratorPrepareUrlRewriteMock($storeId, $productId, $requestPath, $targetPath, 'code', [], $description);
1146+
$this->currentUrlRewritesRegeneratorPrepareUrlRewriteMock(
1147+
$storeId,
1148+
$productId,
1149+
$requestPath,
1150+
$targetPath,
1151+
'code',
1152+
[],
1153+
$description
1154+
);
11391155

11401156
$actualResult = $this->import->currentUrlRewritesRegenerate();
11411157
$this->assertEquals(

app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,7 @@ protected function _collectSuperDataLabels($data, $productSuperAttrId, $productI
804804
*
805805
* @throws \Exception
806806
* @return \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType
807+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
807808
*/
808809
public function saveData()
809810
{
@@ -865,7 +866,9 @@ public function saveData()
865866
}
866867

867868
/**
868-
* @param $bunch
869+
* Configurable in bunch
870+
*
871+
* @param array $bunch
869872
* @return bool
870873
*/
871874
protected function configurableInBunch($bunch)

app/code/Magento/GroupedImportExport/Test/Unit/Model/Import/Product/Type/GroupedTest.php

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@ protected function setUp()
8181
$this->setCollectionFactory->expects($this->any())->method('create')->will(
8282
$this->returnValue($this->setCollection)
8383
);
84-
$this->setCollection->expects($this->any())
85-
->method('setEntityTypeFilter')
86-
->will($this->returnValue([]));
87-
84+
$this->setCollection->expects($this->any())->method('setEntityTypeFilter')->will($this->returnValue([]));
8885
$this->attrCollectionFactory = $this->getMock(
8986
'Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory',
9087
['create', 'addFieldToFilter'],
@@ -117,27 +114,14 @@ protected function setUp()
117114
];
118115
$this->connection = $this->getMock(
119116
'Magento\Framework\DB\Adapter\Pdo\Mysql',
120-
[
121-
'select',
122-
'fetchAll',
123-
'fetchPairs',
124-
'joinLeft',
125-
'insertOnDuplicate',
126-
'delete',
127-
'quoteInto'
128-
],
117+
['select', 'fetchAll', 'fetchPairs', 'joinLeft', 'insertOnDuplicate', 'delete', 'quoteInto'],
129118
[],
130119
'',
131120
false
132121
);
133122
$this->select = $this->getMock(
134123
'Magento\Framework\DB\Select',
135-
[
136-
'from',
137-
'where',
138-
'joinLeft',
139-
'getAdapter',
140-
],
124+
['from', 'where', 'joinLeft', 'getAdapter'],
141125
[],
142126
'',
143127
false
@@ -152,27 +136,16 @@ protected function setUp()
152136
$this->connection->expects($this->any())->method('insertOnDuplicate')->willReturnSelf();
153137
$this->connection->expects($this->any())->method('delete')->willReturnSelf();
154138
$this->connection->expects($this->any())->method('quoteInto')->willReturn('');
155-
$this->connection
156-
->expects($this->any())
157-
->method('fetchPairs')
158-
->will($this->returnValue($entityAttributes));
139+
$this->connection->expects($this->any())->method('fetchPairs')->will($this->returnValue($entityAttributes));
159140
$this->resource = $this->getMock(
160141
'\Magento\Framework\App\Resource',
161-
[
162-
'getConnection',
163-
'getTableName',
164-
],
142+
['getConnection', 'getTableName'],
165143
[],
166144
'',
167145
false
168146
);
169-
$this->resource->expects($this->any())->method('getConnection')->will(
170-
$this->returnValue($this->connection)
171-
);
172-
$this->resource->expects($this->any())->method('getTableName')->will(
173-
$this->returnValue('tableName')
174-
);
175-
147+
$this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection));
148+
$this->resource->expects($this->any())->method('getTableName')->will($this->returnValue('tableName'));
176149
$this->objectManagerHelper = new ObjectManagerHelper($this);
177150
$this->grouped = $this->objectManagerHelper->getObject(
178151
'Magento\GroupedImportExport\Model\Import\Product\Type\Grouped',

app/code/Magento/ImportExport/Model/Import/Entity/AbstractEntity.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -686,11 +686,11 @@ public function isRowAllowedToImport(array $rowData, $rowNum)
686686
return $this->validateRow($rowData, $rowNum) && !isset($this->_rowsToSkip[$rowNum]);
687687
}
688688

689-
/*
690-
* Is import need to log in history.
691-
*
692-
* @return bool
693-
*/
689+
/**
690+
* Is import need to log in history.
691+
*
692+
* @return bool
693+
*/
694694
public function isNeedToLogInHistory()
695695
{
696696
return $this->logInHistory;

app/code/Magento/ImportExport/Model/Resource/History.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ public function getLastInsertedId($userId)
3838

3939
return $adapter->fetchOne($select);
4040
}
41-
}
41+
}

0 commit comments

Comments
 (0)