Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed coding standard violations in the Framework\Model namespace #9361

Merged
merged 3 commits into from
Jun 23, 2017
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 @@ -4,17 +4,16 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

namespace Magento\Framework\Model\ResourceModel\Db\Collection;
use Magento\Framework\App\ResourceConnection\SourceProviderInterface;

use \Magento\Framework\App\ResourceConnection\SourceProviderInterface;
use \Magento\Framework\Data\Collection\AbstractDb;

/**
* Abstract Resource Collection
* @SuppressWarnings(PHPMD.NumberOfChildren)
*/
abstract class AbstractCollection extends \Magento\Framework\Data\Collection\AbstractDb
implements SourceProviderInterface
abstract class AbstractCollection extends AbstractDb implements SourceProviderInterface
{
/**
* Model name
Expand Down Expand Up @@ -231,12 +230,11 @@ protected function _initSelectFields()
$column = $field;
}

if ($alias !== null && in_array(
$alias,
$columnsToSelect
) ||
if ($alias !== null &&
in_array($alias, $columnsToSelect) ||
// If field already joined from another table
$alias === null && isset($alias, $columnsToSelect)
$alias === null &&
isset($alias, $columnsToSelect)
) {
continue;
}
Expand Down Expand Up @@ -458,7 +456,9 @@ public function getResourceModelName()
public function getResource()
{
if (empty($this->_resource)) {
$this->_resource = \Magento\Framework\App\ObjectManager::getInstance()->create($this->getResourceModelName());
$this->_resource = \Magento\Framework\App\ObjectManager::getInstance()->create(
$this->getResourceModelName()
);
}
return $this->_resource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

namespace Magento\Framework\Model\Test\Unit;

use Magento\Framework\Api\AttributeValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

namespace Magento\Framework\Model\Test\Unit\ResourceModel\Db;

use Magento\Framework\DB\Adapter\AdapterInterface;
Expand Down Expand Up @@ -139,7 +137,8 @@ public function testGetIdFieldname()
{
$data = 'MainTableName';
$idFieldNameProperty = new \ReflectionProperty(
AbstractDb::class, '_idFieldName'
AbstractDb::class,
'_idFieldName'
);
$idFieldNameProperty->setAccessible(true);
$idFieldNameProperty->setValue($this->_model, $data);
Expand Down Expand Up @@ -171,8 +170,7 @@ public function testGetMainTable($tableName, $expectedResult)
$this->_resourcesMock->expects($this->once())
->method('getTableName')
->with($expectedResult)
->will($this->returnValue($expectedResult)
);
->will($this->returnValue($expectedResult));
$this->assertEquals($expectedResult, $this->_model->getMainTable());
}

Expand Down Expand Up @@ -312,8 +310,7 @@ public function testDelete()
);
$this->_resourcesMock->expects($this->any())
->method('getConnection')
->will($this->returnValue($connectionInterfaceMock)
);
->will($this->returnValue($connectionInterfaceMock));

$abstractModelMock->expects($this->once())->method('getData')->willReturn(['data' => 'value']);
$connectionMock = $this->getMock(AdapterInterface::class);
Expand Down Expand Up @@ -416,8 +413,7 @@ public function testGetDataChanged($getOriginData, $expected)
$this->_resourcesMock->expects($this->once())
->method('getTableName')
->with('table')
->will($this->returnValue('tableName')
);
->will($this->returnValue('tableName'));
$abstractModelMock->expects($this->at(0))->method('getOrigData')->will($this->returnValue(true));
$abstractModelMock->expects($this->at(1))->method('getOrigData')->will($this->returnValue($getOriginData));
$connectionInterfaceMock->expects($this->any())->method('describeTable')->with('tableName')->will(
Expand All @@ -434,6 +430,9 @@ public function hasDataChangedDataProvider()
];
}

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testPrepareDataForUpdate()
{
$connectionMock = $this->getMock(AdapterInterface::class, [], [], '', false);
Expand Down Expand Up @@ -473,8 +472,7 @@ public function testPrepareDataForUpdate()
$data = 'tableName';
$this->_resourcesMock->expects($this->any())
->method('getConnection')
->will($this->returnValue($connectionMock)
);
->will($this->returnValue($connectionMock));
$this->_resourcesMock->expects($this->any())->method('getTableName')->with($data)->will(
$this->returnValue('tableName')
);
Expand Down Expand Up @@ -503,7 +501,9 @@ public function testPrepareDataForUpdate()
$abstractModelMock->afterLoad();
$this->assertEquals($abstractModelMock->getData(), $abstractModelMock->getStoredData());
$newData = ['value' => 'Test Value New'];
$this->_model->expects($this->atLeastOnce())->method('_prepareDataForTable')->will($this->returnValue($newData));
$this->_model->expects($this->atLeastOnce())
->method('_prepareDataForTable')
->will($this->returnValue($newData));
$abstractModelMock->addData($newData);
$this->assertNotEquals($abstractModelMock->getData(), $abstractModelMock->getStoredData());
$abstractModelMock->isObjectNew(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

namespace Magento\Framework\Model\Test\Unit\ResourceModel\Db\Collection;

use Magento\Framework\DB\Select;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use Magento\Framework\DataObject as MagentoObject;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Framework\ObjectManagerInterface;
Expand Down Expand Up @@ -215,7 +212,11 @@ public function testGetSelect($idFieldNameRet, $getPartRet, $expected)
->method('getPart')
->will($this->returnValue($getPartRet));

$this->selectMock->expects($this->once())->method('setPart')->with(\Magento\Framework\DB\Select::COLUMNS, $expected);
$this->selectMock
->expects($this->once())
->method('setPart')
->with(\Magento\Framework\DB\Select::COLUMNS, $expected);

$this->assertTrue($this->uut->getSelect() instanceof Select);
}

Expand Down Expand Up @@ -410,34 +411,3 @@ public function testSave()
$this->assertTrue($this->uut->save() instanceof Uut);
}
}

/**
* Pattern type: Public Morozov
*/
class Uut extends AbstractCollection
{
public function wereFieldsToSelectChanged()
{
return $this->_fieldsToSelectChanged;
}

public function getFieldsToSelect()
{
return $this->_fieldsToSelect;
}

public function setFieldsToSelect(array $fields)
{
$this->_fieldsToSelect = $fields;
}

public function setResource($resource)
{
$this->_resource = $resource;
}

public function getJoinedTables()
{
return $this->_joinedTables;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Framework\Model\Test\Unit\ResourceModel\Db\Collection;

use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;

/**
* Pattern type: Public Morozov
*/
class Uut extends AbstractCollection
{
public function wereFieldsToSelectChanged()
{
return $this->_fieldsToSelectChanged;
}

public function getFieldsToSelect()
{
return $this->_fieldsToSelect;
}

public function setFieldsToSelect(array $fields)
{
$this->_fieldsToSelect = $fields;
}

public function setResource($resource)
{
$this->_resource = $resource;
}

public function getJoinedTables()
{
return $this->_joinedTables;
}
}