Skip to content

#27500 Prepare GroupedImportExport module Tests for PHPUnit 8 #27820

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

Merged
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
@@ -1,35 +1,35 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\GroupedImportExport\Test\Unit\Model\Export\Product;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\GroupedImportExport\Model\Export\RowCustomizer;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Class RowCustomizerTest
*/
class RowCustomizerTest extends \PHPUnit\Framework\TestCase
class RowCustomizerTest extends TestCase
{
/**
* @var ObjectManagerHelper
*/
protected $objectManagerHelper;

/**
* @var \Magento\GroupedImportExport\Model\Export\RowCustomizer|\PHPUnit_Framework_MockObject_MockObject
* @var RowCustomizer|MockObject
*/
protected $rowCustomizerMock;

/**
* Set up
*/
protected function setUp()
protected function setUp(): void
{
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->rowCustomizerMock = $this->objectManagerHelper->getObject(
\Magento\GroupedImportExport\Model\Export\RowCustomizer::class
RowCustomizer::class
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,63 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\GroupedImportExport\Test\Unit\Model\Import\Product\Type\Grouped;

use Magento\Catalog\Model\ResourceModel\Product\Link;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\DB\Adapter\Pdo\Mysql;
use Magento\Framework\DB\Select;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;

class LinksTest extends \PHPUnit\Framework\TestCase
use Magento\GroupedImportExport\Model\Import\Product\Type\Grouped\Links;
use Magento\ImportExport\Model\Import;
use Magento\ImportExport\Model\ImportFactory;
use Magento\ImportExport\Model\ResourceModel\Import\Data;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class LinksTest extends TestCase
{
/** @var \Magento\GroupedImportExport\Model\Import\Product\Type\Grouped\Links */
/** @var Links */
protected $links;

/** @var ObjectManagerHelper */
protected $objectManagerHelper;

/** @var \Magento\Catalog\Model\ResourceModel\Product\Link|\PHPUnit_Framework_MockObject_MockObject */
/** @var Link|MockObject */
protected $link;

/** @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject */
/** @var ResourceConnection|MockObject */
protected $resource;

/** @var \Magento\Framework\DB\Adapter\Pdo\Mysql */
/** @var Mysql */
protected $connection;

/** @var \Magento\ImportExport\Model\ImportFactory|\PHPUnit_Framework_MockObject_MockObject */
/** @var ImportFactory|MockObject */
protected $importFactory;

/** @var \Magento\ImportExport\Model\Import|\PHPUnit_Framework_MockObject_MockObject */
/** @var Import|MockObject */
protected $import;

protected function setUp()
protected function setUp(): void
{
$this->link = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product\Link::class);
$this->connection = $this->createMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class);
$this->resource = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
$this->link = $this->createMock(Link::class);
$this->connection = $this->createMock(Mysql::class);
$this->resource = $this->createMock(ResourceConnection::class);
$this->resource
->expects($this->once())
->method('getConnection')
->will($this->returnValue($this->connection));

$this->import = $this->createMock(\Magento\ImportExport\Model\Import::class);
$this->importFactory = $this->createPartialMock(\Magento\ImportExport\Model\ImportFactory::class, ['create']);
$this->import = $this->createMock(Import::class);
$this->importFactory = $this->createPartialMock(ImportFactory::class, ['create']);
$this->importFactory->expects($this->any())->method('create')->will($this->returnValue($this->import));

$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->links = $this->objectManagerHelper->getObject(
\Magento\GroupedImportExport\Model\Import\Product\Type\Grouped\Links::class,
Links::class,
[
'productLink' => $this->link,
'resource' => $this->resource,
Expand Down Expand Up @@ -98,7 +107,7 @@ public function testSaveLinksDataWithProductsAttrs($linksData)
$linksData['position'] = [4 => 6];
$linksData['qty'] = [9 => 3];
$this->processBehaviorGetter('append');
$select = $this->createMock(\Magento\Framework\DB\Select::class);
$select = $this->createMock(Select::class);
$this->connection->expects($this->any())->method('select')->will($this->returnValue($select));
$select->expects($this->any())->method('from')->will($this->returnSelf());
$select->expects($this->any())->method('where')->will($this->returnSelf());
Expand Down Expand Up @@ -146,7 +155,7 @@ public function attributesDataProvider()
*/
protected function processAttributeGetter($dbAttributes)
{
$select = $this->createMock(\Magento\Framework\DB\Select::class);
$select = $this->createMock(Select::class);
$this->connection->expects($this->once())->method('select')->will($this->returnValue($select));
$select->expects($this->once())->method('from')->will($this->returnSelf());
$select->expects($this->once())->method('where')->will($this->returnSelf());
Expand Down Expand Up @@ -176,7 +185,7 @@ public function testGetAttributes($dbAttributes, $returnedAttributes)
*/
protected function processBehaviorGetter($behavior)
{
$dataSource = $this->createMock(\Magento\ImportExport\Model\ResourceModel\Import\Data::class);
$dataSource = $this->createMock(Data::class);
$dataSource->expects($this->once())->method('getBehavior')->will($this->returnValue($behavior));
$this->import->expects($this->once())->method('getDataSourceModel')->will($this->returnValue($dataSource));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,61 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\GroupedImportExport\Test\Unit\Model\Import\Product\Type;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\CatalogImportExport\Model\Import\Product;
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection;
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\DB\Adapter\Pdo\Mysql;
use Magento\Framework\DB\Select;
use Magento\Framework\EntityManager\EntityMetadata;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\GroupedImportExport;
use Magento\GroupedImportExport\Model\Import\Product\Type\Grouped;
use Magento\GroupedImportExport\Model\Import\Product\Type\Grouped\Links;
use Magento\ImportExport\Test\Unit\Model\Import\AbstractImportTestCase;
use PHPUnit\Framework\MockObject\MockObject;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class GroupedTest extends \Magento\ImportExport\Test\Unit\Model\Import\AbstractImportTestCase
class GroupedTest extends AbstractImportTestCase
{
/** @var GroupedImportExport\Model\Import\Product\Type\Grouped */
protected $grouped;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var MockObject
*/
protected $setCollectionFactory;

/**
* @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection|\PHPUnit_Framework_MockObject_MockObject
* @var Collection|MockObject
*/
protected $setCollection;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var MockObject
*/
protected $attrCollectionFactory;

/**
* @var \Magento\Framework\DB\Adapter\Pdo\Mysql|\PHPUnit_Framework_MockObject_MockObject
* @var Mysql|MockObject
*/
protected $connection;

/**
* @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject
* @var Select|MockObject
*/
protected $select;

/**
* @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
* @var ResourceConnection|MockObject
*/
protected $resource;

Expand All @@ -52,28 +65,28 @@ class GroupedTest extends \Magento\ImportExport\Test\Unit\Model\Import\AbstractI
protected $params;

/**
* @var GroupedImportExport\Model\Import\Product\Type\Grouped\Links|\PHPUnit_Framework_MockObject_MockObject
* @var GroupedImportExport\Model\Import\Product\Type\Grouped\Links|MockObject
*/
protected $links;

/**
* @var \Magento\CatalogImportExport\Model\Import\Product|\PHPUnit_Framework_MockObject_MockObject
* @var Product|MockObject
*/
protected $entityModel;

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

$this->setCollectionFactory = $this->createPartialMock(
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory::class,
CollectionFactory::class,
['create']
);
$this->setCollection = $this->createPartialMock(
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection::class,
Collection::class,
['setEntityTypeFilter']
);
$this->setCollectionFactory->expects($this->any())->method('create')->will(
Expand All @@ -87,48 +100,48 @@ protected function setUp()
$this->attrCollectionFactory->expects($this->any())->method('create')->will($this->returnSelf());
$this->attrCollectionFactory->expects($this->any())->method('addFieldToFilter')->willReturn([]);
$this->entityModel = $this->createPartialMock(
\Magento\CatalogImportExport\Model\Import\Product::class,
Product::class,
['getErrorAggregator', 'getNewSku', 'getOldSku', 'getNextBunch', 'isRowAllowedToImport', 'getRowScope']
);
$this->entityModel->method('getErrorAggregator')->willReturn($this->getErrorAggregatorObject());
$this->params = [
0 => $this->entityModel,
1 => 'grouped'
];
$this->links = $this->createMock(\Magento\GroupedImportExport\Model\Import\Product\Type\Grouped\Links::class);
$this->links = $this->createMock(Links::class);
$entityAttributes = [
[
'attribute_set_name' => 'attribute_id',
'attribute_id' => 'attributeSetName',
]
];
$this->connection = $this->createPartialMock(
\Magento\Framework\DB\Adapter\Pdo\Mysql::class,
Mysql::class,
['select', 'fetchAll', 'fetchPairs', 'joinLeft', 'insertOnDuplicate', 'delete', 'quoteInto']
);
$this->select = $this->createPartialMock(
\Magento\Framework\DB\Select::class,
Select::class,
['from', 'where', 'joinLeft', 'getConnection']
);
$this->select->expects($this->any())->method('from')->will($this->returnSelf());
$this->select->expects($this->any())->method('where')->will($this->returnSelf());
$this->select->expects($this->any())->method('joinLeft')->will($this->returnSelf());
$this->connection->expects($this->any())->method('select')->will($this->returnValue($this->select));
$connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class);
$connectionMock = $this->createMock(Mysql::class);
$connectionMock->expects($this->any())->method('quoteInto')->will($this->returnValue('query'));
$this->select->expects($this->any())->method('getConnection')->willReturn($connectionMock);
$this->connection->expects($this->any())->method('insertOnDuplicate')->willReturnSelf();
$this->connection->expects($this->any())->method('delete')->willReturnSelf();
$this->connection->expects($this->any())->method('quoteInto')->willReturn('');
$this->connection->expects($this->any())->method('fetchAll')->will($this->returnValue($entityAttributes));
$this->resource = $this->createPartialMock(
\Magento\Framework\App\ResourceConnection::class,
ResourceConnection::class,
['getConnection', 'getTableName']
);
$this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection));
$this->resource->expects($this->any())->method('getTableName')->will($this->returnValue('tableName'));
$this->grouped = $this->objectManagerHelper->getObject(
\Magento\GroupedImportExport\Model\Import\Product\Type\Grouped::class,
Grouped::class,
[
'attrSetColFac' => $this->setCollectionFactory,
'prodAttrColFac' => $this->attrCollectionFactory,
Expand All @@ -137,19 +150,19 @@ protected function setUp()
'links' => $this->links
]
);
$metadataPoolMock = $this->createMock(\Magento\Framework\EntityManager\MetadataPool::class);
$entityMetadataMock = $this->createMock(\Magento\Framework\EntityManager\EntityMetadata::class);
$metadataPoolMock = $this->createMock(MetadataPool::class);
$entityMetadataMock = $this->createMock(EntityMetadata::class);
$metadataPoolMock->expects($this->any())
->method('getMetadata')
->with(\Magento\Catalog\Api\Data\ProductInterface::class)
->with(ProductInterface::class)
->willReturn($entityMetadataMock);
$entityMetadataMock->expects($this->any())
->method('getLinkField')
->willReturn('entity_id');
$entityMetadataMock->expects($this->any())
->method('getIdentifierField')
->willReturn('entity_id');
$reflection = new \ReflectionClass(\Magento\GroupedImportExport\Model\Import\Product\Type\Grouped::class);
$reflection = new \ReflectionClass(Grouped::class);
$reflectionProperty = $reflection->getProperty('metadataPool');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->grouped, $metadataPoolMock);
Expand All @@ -173,7 +186,7 @@ public function testSaveData($skus, $bunch)
$this->entityModel->expects($this->at(2))->method('getNextBunch')->will($this->returnValue([$bunch]));
$this->entityModel->expects($this->any())->method('isRowAllowedToImport')->will($this->returnValue(true));
$this->entityModel->expects($this->any())->method('getRowScope')->will($this->returnValue(
\Magento\CatalogImportExport\Model\Import\Product::SCOPE_DEFAULT
Product::SCOPE_DEFAULT
));

$this->links->expects($this->once())->method('saveLinksData');
Expand Down Expand Up @@ -263,10 +276,10 @@ public function testSaveDataScopeStore()
$this->entityModel->expects($this->at(2))->method('getNextBunch')->will($this->returnValue($bunch));
$this->entityModel->expects($this->any())->method('isRowAllowedToImport')->will($this->returnValue(true));
$this->entityModel->expects($this->at(4))->method('getRowScope')->will($this->returnValue(
\Magento\CatalogImportExport\Model\Import\Product::SCOPE_DEFAULT
Product::SCOPE_DEFAULT
));
$this->entityModel->expects($this->at(5))->method('getRowScope')->will($this->returnValue(
\Magento\CatalogImportExport\Model\Import\Product::SCOPE_STORE
Product::SCOPE_STORE
));

$this->links->expects($this->once())->method('saveLinksData');
Expand Down