Skip to content

Commit

Permalink
#27500 Prepare BundleImportExport module Tests for PHPUnit 8
Browse files Browse the repository at this point in the history
  • Loading branch information
lbajsarowicz committed Apr 12, 2020
1 parent 86515dd commit 3e84faf
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,82 +1,87 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\BundleImportExport\Test\Unit\Model\Export\Product;

use Magento\Bundle\Model\Option;
use Magento\BundleImportExport\Model\Export\RowCustomizer;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Framework\App\ScopeInterface;
use Magento\Framework\App\ScopeResolverInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
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\BundleImportExport\Model\Export\RowCustomizer|\PHPUnit_Framework_MockObject_MockObject
* @var RowCustomizer|MockObject
*/
protected $rowCustomizerMock;

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

/**
* @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject
* @var Product|MockObject
*/
protected $product;

/**
* @var \Magento\Bundle\Model\ResourceModel\Option\Collection|\PHPUnit_Framework_MockObject_MockObject
* @var \Magento\Bundle\Model\ResourceModel\Option\Collection|MockObject
*/
protected $optionsCollection;

/**
* @var \Magento\Bundle\Model\Option|\PHPUnit_Framework_MockObject_MockObject
* @var Option|MockObject
*/
protected $option;

/**
* @var \Magento\Bundle\Model\ResourceModel\Selection\Collection|\PHPUnit_Framework_MockObject_MockObject
* @var \Magento\Bundle\Model\ResourceModel\Selection\Collection|MockObject
*/
protected $selectionsCollection;

/**
* @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject
* @var Product|MockObject
*/
protected $selection;

/** @var \Magento\Framework\App\ScopeResolverInterface|\PHPUnit_Framework_MockObject_MockObject */
/** @var ScopeResolverInterface|MockObject */
private $scopeResolver;

/**
* Set up
*/
protected function setUp()
protected function setUp(): void
{
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->scopeResolver = $this->getMockBuilder(\Magento\Framework\App\ScopeResolverInterface::class)
$this->scopeResolver = $this->getMockBuilder(ScopeResolverInterface::class)
->disableOriginalConstructor()
->setMethods(['getScope'])
->getMockForAbstractClass();
$this->rowCustomizerMock = $this->objectManagerHelper->getObject(
\Magento\BundleImportExport\Model\Export\RowCustomizer::class,
RowCustomizer::class,
[
'scopeResolver' => $this->scopeResolver,
]
);
$this->productResourceCollection = $this->createPartialMock(
\Magento\Catalog\Model\ResourceModel\Product\Collection::class,
Collection::class,
['addAttributeToFilter', 'getIterator']
);
$this->product = $this->createPartialMock(
\Magento\Catalog\Model\Product::class,
Product::class,
[
'getEntityId',
'getPriceType',
Expand Down Expand Up @@ -106,7 +111,7 @@ protected function setUp()
$this->product->expects($this->any())->method('getOptionsCollection')->willReturn($this->optionsCollection);
$this->optionsCollection->expects($this->any())->method('setOrder')->willReturnSelf();
$this->option = $this->createPartialMock(
\Magento\Bundle\Model\Option::class,
Option::class,
['getId', 'getOptionId', 'getTitle', 'getType', 'getRequired']
);
$this->option->expects($this->any())->method('getId')->willReturn(1);
Expand All @@ -118,7 +123,7 @@ protected function setUp()
$this->returnValue(new \ArrayIterator([$this->option]))
);
$this->selection = $this->createPartialMock(
\Magento\Catalog\Model\Product::class,
Product::class,
[
'getSku',
'getSelectionPriceValue',
Expand Down Expand Up @@ -156,7 +161,7 @@ protected function setUp()
*/
public function testPrepareData()
{
$scope = $this->getMockBuilder(\Magento\Framework\App\ScopeInterface::class)->getMockForAbstractClass();
$scope = $this->getMockBuilder(ScopeInterface::class)->getMockForAbstractClass();
$this->scopeResolver->expects($this->any())->method('getScope')->willReturn($scope);
$result = $this->rowCustomizerMock->prepareData($this->productResourceCollection, [1]);
$this->assertNotNull($result);
Expand Down Expand Up @@ -185,7 +190,7 @@ public function testAddHeaderColumns()
*/
public function testAddData()
{
$scope = $this->getMockBuilder(\Magento\Framework\App\ScopeInterface::class)->getMockForAbstractClass();
$scope = $this->getMockBuilder(ScopeInterface::class)->getMockForAbstractClass();
$this->scopeResolver->expects($this->any())->method('getScope')->willReturn($scope);
$preparedData = $this->rowCustomizerMock->prepareData($this->productResourceCollection, [1]);
$attributes = 'attribute=1,sku_type=1,attribute2="Text",price_type=1,price_view=1,weight_type=1,'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
Expand All @@ -10,35 +10,35 @@
use Magento\Catalog\Model\ResourceModel\Product\Relation;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Class RelationsDataSaverTest
*/
class RelationsDataSaverTest extends \PHPUnit\Framework\TestCase
class RelationsDataSaverTest extends TestCase
{
/**
* @var RelationsDataSaver
*/
private $relationsDataSaver;

/**
* @var ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
* @var ResourceConnection|MockObject
*/
private $resourceMock;

/**
* @var AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
* @var AdapterInterface|MockObject
*/
private $connectionMock;

/**
* @var Relation|\PHPUnit_Framework_MockObject_MockObject
* @var Relation|MockObject
*/
private $productRelationMock;

protected function setUp()
protected function setUp(): void
{
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$helper = new ObjectManager($this);
$this->resourceMock = $this->getMockBuilder(ResourceConnection::class)
->disableOriginalConstructor()
->getMock();
Expand Down
Loading

0 comments on commit 3e84faf

Please sign in to comment.