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

Removed each() function usage #31

Merged
merged 1 commit into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,7 @@ public function getAttributeRawValue($entityId, $attribute, $store)
}

if (is_array($attributesData) && sizeof($attributesData) == 1) {
$_data = each($attributesData);
$attributesData = $_data[1];
$attributesData = array_shift($attributesData);
}

return $attributesData === false ? false : $attributesData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ public function joinTable($table, $bind, $fields = null, $cond = null, $joinType
{
$tableAlias = null;
if (is_array($table)) {
list($tableAlias, $tableName) = each($table);
list($tableAlias, $tableName) = [key($table), current($table)];
} else {
$tableName = $table;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,29 @@ public function testGetProductsWithTierPrice()
$this->assertEquals(50, $tierPrices[2]->getExtensionAttributes()->getPercentageValue());
$this->assertEquals(5, $tierPrices[2]->getValue());
}

/**
* Checks a case if table for join specified as an array.
*
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function testJoinTable()
{
$this->collection->joinTable(
['alias' => 'url_rewrite'],
'entity_id = entity_id',
['request_path'],
'{{table}}.entity_type = \'product\'',
'left'
);
$sql = (string) $this->collection->getSelect();
$productTable = $this->collection->getTable('catalog_product_entity');
$urlRewriteTable = $this->collection->getTable('url_rewrite');

$expected = 'SELECT `e`.*, `alias`.`request_path` FROM `' . $productTable . '` AS `e`'
. ' LEFT JOIN `' . $urlRewriteTable . '` AS `alias` ON (alias.entity_id =e.entity_id)'
. ' AND (alias.entity_type = \'product\')';

self::assertContains($expected, str_replace(PHP_EOL, '', $sql));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Model\ResourceModel;

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;

class ProductTest extends TestCase
{
/**
* @var Product
*/
private $model;

/**
* @var ObjectManagerInterface
*/
private $objectManager;

/**
* @inheritdoc
*/
protected function setUp()
{
$this->objectManager = Bootstrap::getObjectManager();

$this->model = $this->objectManager->get(Product::class);
}

/**
* Checks a possibility to retrieve product raw attribute value.
*
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
*/
public function testGetAttributeRawValue()
{
$sku = 'simple';
$attribute = 'name';

/** @var ProductRepositoryInterface $productRepository */
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
$product = $productRepository->get($sku);

$actual = $this->model->getAttributeRawValue($product->getId(), $attribute, null);
self::assertEquals($product->getName(), $actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ protected function buildModulesDependencies()
$moduleName = str_replace('/', '_', $moduleName[1]);
$config = simplexml_load_file($configFile);
$result = $config->xpath("/config/module/depends/module") ?: [];
while (list(, $node) = each($result)) {
foreach ($result as $node) {
/** @var \SimpleXMLElement $node */
$this->moduleDependencies[$moduleName][] = (string)$node['name'];
$this->moduleDependencies[$moduleName][] = (string) $node['name'];
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ public function testComponentPathsInRoot()
"If there are any component paths specified, then they must be reflected in 'replace' section"
);
$flat = $this->getFlatPathsInfo(self::$rootJson['extra']['component_paths']);
while (list(, list($component, $path)) = each($flat)) {
foreach ($flat as $item) {
list($component, $path) = $item;
$this->assertFileExists(
self::$root . '/' . $path,
"Missing or invalid component path: {$component} -> {$path}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2526,5 +2526,6 @@
['getDataFormTab', 'Magento\Backend\Test\Block\Widget\Tab', 'Magento\Ui\Test\Block\Adminhtml\AbstractContainer::getFieldsData'],
['getBunchImages', 'Magento\CatalogImportExport\Model\Import\Product'],
['_isAttributeValueEmpty', 'Magento\Catalog\Model\ResourceModel\AbstractResource'],
['var_dump', '']
['var_dump', ''],
['each', ''],
];
3 changes: 2 additions & 1 deletion setup/src/Magento/Setup/Model/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ public function install($request)

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

while (list(, list($message, $method, $params)) = each($script)) {
foreach ($script as $item) {
list($message, $method, $params) = $item;
$this->log->log($message);
call_user_func_array([$this, $method], $params);
$this->logProgress();
Expand Down