Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 98853cb

Browse files
author
Oleksii Korshenko
authored
MAGETWO-87317: Fix #20: Removed each() function usage #31
2 parents 872638b + 59eae8a commit 98853cb

File tree

8 files changed

+87
-8
lines changed

8 files changed

+87
-8
lines changed

app/code/Magento/Catalog/Model/ResourceModel/AbstractResource.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,7 @@ public function getAttributeRawValue($entityId, $attribute, $store)
571571
}
572572

573573
if (is_array($attributesData) && sizeof($attributesData) == 1) {
574-
$_data = each($attributesData);
575-
$attributesData = $_data[1];
574+
$attributesData = array_shift($attributesData);
576575
}
577576

578577
return $attributesData === false ? false : $attributesData;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ public function joinTable($table, $bind, $fields = null, $cond = null, $joinType
803803
{
804804
$tableAlias = null;
805805
if (is_array($table)) {
806-
list($tableAlias, $tableName) = each($table);
806+
list($tableAlias, $tableName) = [key($table), current($table)];
807807
} else {
808808
$tableName = $table;
809809
}

dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Product/CollectionTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,29 @@ public function testGetProductsWithTierPrice()
124124
$this->assertEquals(50, $tierPrices[2]->getExtensionAttributes()->getPercentageValue());
125125
$this->assertEquals(5, $tierPrices[2]->getValue());
126126
}
127+
128+
/**
129+
* Checks a case if table for join specified as an array.
130+
*
131+
* @throws \Magento\Framework\Exception\LocalizedException
132+
*/
133+
public function testJoinTable()
134+
{
135+
$this->collection->joinTable(
136+
['alias' => 'url_rewrite'],
137+
'entity_id = entity_id',
138+
['request_path'],
139+
'{{table}}.entity_type = \'product\'',
140+
'left'
141+
);
142+
$sql = (string) $this->collection->getSelect();
143+
$productTable = $this->collection->getTable('catalog_product_entity');
144+
$urlRewriteTable = $this->collection->getTable('url_rewrite');
145+
146+
$expected = 'SELECT `e`.*, `alias`.`request_path` FROM `' . $productTable . '` AS `e`'
147+
. ' LEFT JOIN `' . $urlRewriteTable . '` AS `alias` ON (alias.entity_id =e.entity_id)'
148+
. ' AND (alias.entity_type = \'product\')';
149+
150+
self::assertContains($expected, str_replace(PHP_EOL, '', $sql));
151+
}
127152
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Model\ResourceModel;
7+
8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Framework\ObjectManagerInterface;
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
use PHPUnit\Framework\TestCase;
12+
13+
class ProductTest extends TestCase
14+
{
15+
/**
16+
* @var Product
17+
*/
18+
private $model;
19+
20+
/**
21+
* @var ObjectManagerInterface
22+
*/
23+
private $objectManager;
24+
25+
/**
26+
* @inheritdoc
27+
*/
28+
protected function setUp()
29+
{
30+
$this->objectManager = Bootstrap::getObjectManager();
31+
32+
$this->model = $this->objectManager->get(Product::class);
33+
}
34+
35+
/**
36+
* Checks a possibility to retrieve product raw attribute value.
37+
*
38+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
39+
*/
40+
public function testGetAttributeRawValue()
41+
{
42+
$sku = 'simple';
43+
$attribute = 'name';
44+
45+
/** @var ProductRepositoryInterface $productRepository */
46+
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
47+
$product = $productRepository->get($sku);
48+
49+
$actual = $this->model->getAttributeRawValue($product->getId(), $attribute, null);
50+
self::assertEquals($product->getName(), $actual);
51+
}
52+
}

dev/tests/static/testsuite/Magento/Test/Integrity/CircularDependencyTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ protected function buildModulesDependencies()
4444
$moduleName = str_replace('/', '_', $moduleName[1]);
4545
$config = simplexml_load_file($configFile);
4646
$result = $config->xpath("/config/module/depends/module") ?: [];
47-
while (list(, $node) = each($result)) {
47+
foreach ($result as $node) {
4848
/** @var \SimpleXMLElement $node */
49-
$this->moduleDependencies[$moduleName][] = (string)$node['name'];
49+
$this->moduleDependencies[$moduleName][] = (string) $node['name'];
5050
}
5151
}
5252
}

dev/tests/static/testsuite/Magento/Test/Integrity/ComposerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ public function testComponentPathsInRoot()
336336
"If there are any component paths specified, then they must be reflected in 'replace' section"
337337
);
338338
$flat = $this->getFlatPathsInfo(self::$rootJson['extra']['component_paths']);
339-
while (list(, list($component, $path)) = each($flat)) {
339+
foreach ($flat as $item) {
340+
list($component, $path) = $item;
340341
$this->assertFileExists(
341342
self::$root . '/' . $path,
342343
"Missing or invalid component path: {$component} -> {$path}"

dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2526,5 +2526,6 @@
25262526
['getDataFormTab', 'Magento\Backend\Test\Block\Widget\Tab', 'Magento\Ui\Test\Block\Adminhtml\AbstractContainer::getFieldsData'],
25272527
['getBunchImages', 'Magento\CatalogImportExport\Model\Import\Product'],
25282528
['_isAttributeValueEmpty', 'Magento\Catalog\Model\ResourceModel\AbstractResource'],
2529-
['var_dump', '']
2529+
['var_dump', ''],
2530+
['each', ''],
25302531
];

setup/src/Magento/Setup/Model/Installer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ public function install($request)
337337

338338
$this->log->log('Starting Magento installation:');
339339

340-
while (list(, list($message, $method, $params)) = each($script)) {
340+
foreach ($script as $item) {
341+
list($message, $method, $params) = $item;
341342
$this->log->log($message);
342343
call_user_func_array([$this, $method], $params);
343344
$this->logProgress();

0 commit comments

Comments
 (0)