Skip to content

Commit 57ad715

Browse files
Andrei KuprienkaA-Komar
authored andcommitted
MAGNIMEX-6: Unit tests and phpcsmd fixes
1 parent ac09ec7 commit 57ad715

File tree

10 files changed

+68
-43
lines changed

10 files changed

+68
-43
lines changed

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
use Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
99
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface as ValidatorInterface;
1010

11+
/**
12+
* Class AdvancedPricing
13+
*
14+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
15+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
16+
*/
1117
class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
1218
{
1319
const VALUE_ALL_GROUPS = 'ALL GROUPS';
@@ -140,8 +146,7 @@ public function __construct(
140146
AdvancedPricing\Validator $validator,
141147
AdvancedPricing\Validator\Website $websiteValidator,
142148
AdvancedPricing\Validator\GroupPrice $groupPriceValidator
143-
)
144-
{
149+
) {
145150
$this->jsonHelper = $jsonHelper;
146151
$this->_importExportData = $importExportData;
147152
$this->_resourceHelper = $resourceHelper;
@@ -225,6 +230,8 @@ protected function _importData()
225230

226231
/**
227232
* Save advanced pricing
233+
*
234+
* @return void
228235
*/
229236
public function saveAdvancedPricing()
230237
{
@@ -266,6 +273,8 @@ public function saveAdvancedPricing()
266273

267274
/**
268275
* Deletes Advanced price data from raw data.
276+
*
277+
* @return void
269278
*/
270279
public function deleteAdvancedPricing()
271280
{
@@ -330,12 +339,14 @@ protected function saveProductPrices(array $priceData, $table)
330339
protected function deleteProductTierAndGroupPrices(array $listSku, $tableName)
331340
{
332341
if ($tableName && $listSku) {
333-
if(!$this->_cachedSkuToDelete) {
334-
$this->_cachedSkuToDelete = $this->_connection->fetchCol($this->_connection->select()
342+
if (!$this->_cachedSkuToDelete) {
343+
$this->_cachedSkuToDelete = $this->_connection->fetchCol(
344+
$this->_connection->select()
335345
->from($this->_connection->getTableName('catalog_product_entity'), 'entity_id')
336-
->where('sku IN (?)', $listSku));
346+
->where('sku IN (?)', $listSku)
347+
);
337348
}
338-
if($this->_cachedSkuToDelete) {
349+
if ($this->_cachedSkuToDelete) {
339350
$this->_connection->delete(
340351
$tableName,
341352
$this->_connection->quoteInto('entity_id IN (?)', $this->_cachedSkuToDelete)
@@ -351,7 +362,7 @@ protected function deleteProductTierAndGroupPrices(array $listSku, $tableName)
351362
/**
352363
* Get website id by code
353364
*
354-
* @param $websiteCode
365+
* @param string $websiteCode
355366
* @return array|int|string
356367
*/
357368
protected function getWebSiteId($websiteCode)
@@ -388,4 +399,4 @@ protected function retrieveOldSkus()
388399
);
389400
return $oldSkus;
390401
}
391-
}
402+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ public function isValid($value)
4141

4242
/**
4343
* Init validators
44+
*
45+
* @return void
4446
*/
4547
public function init()
4648
{
4749
foreach ($this->validators as $validator) {
4850
$validator->init();
4951
}
5052
}
51-
}
53+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public function isValid($value)
6868
|| $this->hasEmptyColumns($value)) {
6969
$this->_addMessages([self::ERROR_GROUP_PRICE_DATA_INCOMPLETE]);
7070
return false;
71-
} elseif ($value[AdvancedPricing::COL_GROUP_PRICE_CUSTOMER_GROUP] == AdvancedPricing::VALUE_ALL_GROUPS
71+
} elseif (
72+
$value[AdvancedPricing::COL_GROUP_PRICE_CUSTOMER_GROUP] == AdvancedPricing::VALUE_ALL_GROUPS
7273
|| !isset($this->customerGroups[$value[AdvancedPricing::COL_GROUP_PRICE_CUSTOMER_GROUP]])
7374
) {
7475
$this->_addMessages([self::ERROR_INVALID_GROUP_PRICE_GROUP]);
@@ -124,4 +125,4 @@ protected function hasEmptyColumns(array $value)
124125
}
125126
return $hasEmptyValues;
126127
}
127-
}
128+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function init()
5656
*
5757
* @param mixed $value
5858
* @return bool
59+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
5960
*/
6061
public function isValid($value)
6162
{
@@ -118,4 +119,4 @@ protected function hasEmptyColumns(array $value)
118119
}
119120
return $hasEmptyValues;
120121
}
121-
}
122+
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,20 @@ class Website extends AbstractValidator implements RowValidatorInterface
1616
* @var \Magento\CatalogImportExport\Model\Import\Product\StoreResolver
1717
*/
1818
protected $storeResolver;
19+
20+
/**
21+
* @var \Magento\Store\Model\WebSite
22+
*/
1923
protected $webSiteModel;
2024

2125
/**
2226
* @param \Magento\CatalogImportExport\Model\Import\Product\StoreResolver $storeResolver
27+
* @param \Magento\Store\Model\WebSite $webSiteModel
2328
*/
2429
public function __construct(
2530
\Magento\CatalogImportExport\Model\Import\Product\StoreResolver $storeResolver,
2631
\Magento\Store\Model\WebSite $webSiteModel
27-
)
28-
{
32+
) {
2933
$this->storeResolver = $storeResolver;
3034
$this->webSiteModel = $webSiteModel;
3135
}
@@ -72,4 +76,4 @@ public function getAllWebsitesValue()
7276
{
7377
return AdvancedPricing::VALUE_ALL_WEBSITES . ' ['.$this->webSiteModel->getBaseCurrency()->getCurrencyCode().']';
7478
}
75-
}
79+
}

app/code/Magento/AdvancedPricingImportExport/Model/Indexer/Product/Price/Plugin/Import.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class Import extends \Magento\Catalog\Model\Indexer\Product\Price\Plugin\Abstrac
99
{
1010
/**
1111
* After import handler
12+
*
13+
* @return void
1214
*/
1315
public function afterSaveAdvancedPricing()
1416
{
@@ -19,6 +21,8 @@ public function afterSaveAdvancedPricing()
1921

2022
/**
2123
* After delete handler
24+
*
25+
* @return void
2226
*/
2327
public function afterDeleteAdvancedPricing()
2428
{

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,14 @@ public function testSaveAdvancedPricing(
331331

332332
public function testDeleteAdvancedPricingFormListSkuToDelete()
333333
{
334-
$sku_1 = 'sku value';
335-
$sku_2 = 'sku value';
334+
$skuOne = 'sku value';
335+
$skuTwo = 'sku value';
336336
$data = [
337337
0 => [
338-
AdvancedPricing::COL_SKU => $sku_1
338+
AdvancedPricing::COL_SKU => $skuOne
339339
],
340340
1 => [
341-
AdvancedPricing::COL_SKU => $sku_2
341+
AdvancedPricing::COL_SKU => $skuTwo
342342
],
343343
];
344344

@@ -650,7 +650,7 @@ protected function setPropertyValue(&$object, $property, $value)
650650
*
651651
* @return \PHPUnit_Framework_MockObject_MockObject
652652
*/
653-
private function getAdvancedPricingMock($methods = array())
653+
private function getAdvancedPricingMock($methods = [])
654654
{
655655
return $this->getMock(
656656
'\Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing',

app/code/Magento/CatalogImportExport/Model/Export/Product.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ protected function updateDataWithCategoryColumns(&$dataRow, &$rowCategories, $pr
624624
if (!isset($rowCategories[$productId])) {
625625
return false;
626626
}
627-
$categories = array();
627+
$categories = [];
628628
foreach ($rowCategories[$productId] as $categoryId) {
629629
$categoryPath = $this->_rootCategories[$categoryId];
630630
if (isset($this->_categories[$categoryId])) {
@@ -854,7 +854,7 @@ protected function collectRawData()
854854
* @var \Magento\Catalog\Model\Product $item
855855
*/
856856
foreach ($collection as $itemId => $item) {
857-
$additionalAttributes = array();
857+
$additionalAttributes = [];
858858
foreach ($this->_getExportAttrCodes() as $code) {
859859
$attrValue = $item->getData($code);
860860
if (!$this->isValidAttributeValue($code, $attrValue)) {
@@ -1020,29 +1020,29 @@ protected function addMultirowData($dataRow, $multiRawData)
10201020
unset($dataRow[self::COL_STORE]);
10211021
$this->updateDataWithCategoryColumns($dataRow, $multiRawData['rowCategories'], $productId);
10221022
if (!empty($multiRawData['rowWebsites'][$productId])) {
1023-
$websiteCodes = array();
1023+
$websiteCodes = [];
10241024
foreach ($multiRawData['rowWebsites'][$productId] as $productWebsite) {
10251025
$websiteCodes[] = $this->_websiteIdToCode[$productWebsite];
10261026
}
10271027
$dataRow['_product_websites'] = implode(ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $websiteCodes);
1028-
$multiRawData['rowWebsites'][$productId] = array();
1028+
$multiRawData['rowWebsites'][$productId] = [];
10291029
}
10301030
if (!empty($multiRawData['mediaGalery'][$productId])) {
1031-
$additionalImages = array();
1032-
$additionalImageLabels = array();
1031+
$additionalImages = [];
1032+
$additionalImageLabels = [];
10331033
foreach ($multiRawData['mediaGalery'][$productId] as $mediaItem) {
10341034
$additionalImages[] = $mediaItem['_media_image'];
10351035
$additionalImageLabels[] = $mediaItem['_media_label'];
10361036
}
10371037
$dataRow['additional_images'] = implode(ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $additionalImages);
10381038
$dataRow['additional_image_labels'] = implode(ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $additionalImageLabels);
1039-
$multiRawData['mediaGalery'][$productId] = array();
1039+
$multiRawData['mediaGalery'][$productId] = [];
10401040
}
10411041
foreach ($this->_linkTypeProvider->getLinkTypes() as $linkTypeName => $linkId) {
10421042
if (!empty($multiRawData['linksRows'][$productId][$linkId])) {
10431043
$colPrefix = $linkTypeName . '_';
10441044

1045-
$associations = array();
1045+
$associations = [];
10461046
foreach ($multiRawData['linksRows'][$productId][$linkId] as $linkData) {
10471047
if ($linkData['default_qty'] !== null) {
10481048
$skuItem = $linkData['sku'] . ImportProduct::PAIR_NAME_VALUE_SEPARATOR . $linkData['default_qty'];
@@ -1051,7 +1051,7 @@ protected function addMultirowData($dataRow, $multiRawData)
10511051
}
10521052
$associations[$skuItem] = $linkData['position'];
10531053
}
1054-
$multiRawData['linksRows'][$productId][$linkId] = array();
1054+
$multiRawData['linksRows'][$productId][$linkId] = [];
10551055
asort($associations);
10561056
$dataRow[$colPrefix . 'skus'] = implode(ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, array_keys($associations));
10571057
}
@@ -1070,10 +1070,10 @@ protected function addMultirowData($dataRow, $multiRawData)
10701070

10711071
if (!empty($multiRawData['customOptionsData'][$productId][$storeId])) {
10721072
$customOptionsRows = $multiRawData['customOptionsData'][$productId][$storeId];
1073-
$multiRawData['customOptionsData'][$productId][$storeId] = array();
1073+
$multiRawData['customOptionsData'][$productId][$storeId] = [];
10741074
$customOptions = implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $customOptionsRows);
10751075

1076-
$dataRow = array_merge($dataRow, array('custom_options' => $customOptions));
1076+
$dataRow = array_merge($dataRow, ['custom_options' => $customOptions]);
10771077
}
10781078

10791079
if (empty($dataRow)) {
@@ -1099,10 +1099,10 @@ protected function addMultirowData($dataRow, $multiRawData)
10991099
*/
11001100
protected function _customFieldsMapping($rowData)
11011101
{
1102-
foreach ($this->_fieldsMap as $system_field_name => $file_field_name) {
1103-
if (isset($rowData[$system_field_name])) {
1104-
$rowData[$file_field_name] = $rowData[$system_field_name];
1105-
unset($rowData[$system_field_name]);
1102+
foreach ($this->_fieldsMap as $systemFieldName => $fileFieldName) {
1103+
if (isset($rowData[$systemFieldName])) {
1104+
$rowData[$fileFieldName] = $rowData[$systemFieldName];
1105+
unset($rowData[$systemFieldName]);
11061106
}
11071107
}
11081108
return $rowData;
@@ -1117,9 +1117,9 @@ protected function _customFieldsMapping($rowData)
11171117
*/
11181118
protected function _customHeadersMapping($rowData)
11191119
{
1120-
foreach ($rowData as $key => $field_name) {
1121-
if (isset($this->_fieldsMap[$field_name])) {
1122-
$rowData[$key] = $this->_fieldsMap[$field_name];
1120+
foreach ($rowData as $key => $fieldName) {
1121+
if (isset($this->_fieldsMap[$fieldName])) {
1122+
$rowData[$key] = $this->_fieldsMap[$fieldName];
11231123
}
11241124
}
11251125
return $rowData;
@@ -1131,7 +1131,7 @@ protected function _customHeadersMapping($rowData)
11311131
*/
11321132
protected function optionRowToCellString($option)
11331133
{
1134-
$result = array();
1134+
$result = [];
11351135

11361136
foreach ($option as $key => $value) {
11371137
$result[] = $key . ImportProduct::PAIR_NAME_VALUE_SEPARATOR . $value;

app/code/Magento/CatalogImportExport/Model/Import/Uploader.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,12 @@ public function init()
135135
* Proceed moving a file from TMP to destination folder
136136
*
137137
* @param string $fileName
138+
* @param bool $renameFileOff
138139
* @return array
139140
*/
140-
public function move($fileName, $renameFileOff=false)
141+
public function move($fileName, $renameFileOff = false)
141142
{
142-
if($renameFileOff) {
143+
if ($renameFileOff) {
143144
$this->setAllowRenameFiles(false);
144145
}
145146
if (preg_match('/\bhttps?:\/\//i', $fileName, $matches)) {

app/code/Magento/ImportExport/Test/Unit/Block/Adminhtml/Export/FilterTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ public function setUp()
138138
[],
139139
[],
140140
'',
141-
false);
141+
false
142+
);
142143
$this->eavConfig = $this->getMock('Magento\Eav\Model\Config', [], [], '', false);
143144
$this->eavTypeFactory = $this->getMock('Magento\Eav\Model\Entity\TypeFactory', [], [], '', false);
144145
$this->storeManager = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false);
@@ -310,7 +311,7 @@ public function decorateFilterDataProvider()
310311
*
311312
* @todo to implement it.
312313
*/
313-
public function test_prepareForm()
314+
public function testPrepareForm()
314315
{
315316
$this->markTestIncomplete('This test has not been implemented yet.');
316317
}

0 commit comments

Comments
 (0)