Skip to content

Commit 3abb33c

Browse files
author
Oleksii Korshenko
authored
Merge pull request #27702 from lbajsarowicz/phpunit8/module-CatalogWidget
#27500 PHPUnit 8 for module CatalogWidget
2 parents 9e8a0f4 + a6f1107 commit 3abb33c

File tree

6 files changed

+156
-104
lines changed

6 files changed

+156
-104
lines changed

app/code/Magento/CatalogWidget/Test/Unit/Block/Product/ProductsListTest.php

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,131 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66

77
namespace Magento\CatalogWidget\Test\Unit\Block\Product;
88

9+
use Magento\Catalog\Block\Product\Widget\Html\Pager;
10+
use Magento\Catalog\Model\Product;
911
use Magento\Catalog\Model\Product\Visibility;
10-
12+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
13+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
1114
use Magento\CatalogWidget\Block\Product\ProductsList;
15+
use Magento\CatalogWidget\Model\Rule;
16+
use Magento\Directory\Model\Currency;
17+
use Magento\Framework\App\Http\Context;
18+
use Magento\Framework\App\RequestInterface;
19+
use Magento\Framework\DataObject\IdentityInterface;
1220
use Magento\Framework\Pricing\PriceCurrencyInterface;
21+
use Magento\Framework\Pricing\Render;
22+
use Magento\Framework\Serialize\Serializer\Json;
1323
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
24+
use Magento\Framework\View\Design\ThemeInterface;
25+
use Magento\Framework\View\DesignInterface;
26+
use Magento\Framework\View\LayoutInterface;
27+
use Magento\Rule\Model\Condition\Combine;
28+
use Magento\Rule\Model\Condition\Sql\Builder;
29+
use Magento\Store\Model\Store;
30+
use Magento\Store\Model\StoreManagerInterface;
31+
32+
use Magento\Widget\Helper\Conditions;
33+
use PHPUnit\Framework\MockObject\MockObject;
34+
use PHPUnit\Framework\TestCase;
1435

1536
/**
16-
* Class ProductsListTest
1737
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1838
*/
19-
class ProductsListTest extends \PHPUnit\Framework\TestCase
39+
class ProductsListTest extends TestCase
2040
{
2141
/**
22-
* @var \Magento\CatalogWidget\Block\Product\ProductsList
42+
* @var ProductsList
2343
*/
2444
protected $productsList;
2545

2646
/**
27-
* @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
47+
* @var CollectionFactory|MockObject
2848
*/
2949
protected $collectionFactory;
3050

3151
/**
32-
* @var \Magento\Catalog\Model\Product\Visibility|\PHPUnit_Framework_MockObject_MockObject
52+
* @var Visibility|MockObject
3353
*/
3454
protected $visibility;
3555

3656
/**
37-
* @var \Magento\Framework\App\Http\Context|\PHPUnit_Framework_MockObject_MockObject
57+
* @var Context|MockObject
3858
*/
3959
protected $httpContext;
4060

4161
/**
42-
* @var \Magento\Rule\Model\Condition\Sql\Builder|\PHPUnit_Framework_MockObject_MockObject
62+
* @var Builder|MockObject
4363
*/
4464
protected $builder;
4565

4666
/**
47-
* @var \Magento\CatalogWidget\Model\Rule|\PHPUnit_Framework_MockObject_MockObject
67+
* @var Rule|MockObject
4868
*/
4969
protected $rule;
5070

5171
/**
52-
* @var \Magento\Widget\Helper\Conditions|\PHPUnit_Framework_MockObject_MockObject
72+
* @var Conditions|MockObject
5373
*/
5474
protected $widgetConditionsHelper;
5575

5676
/**
57-
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
77+
* @var StoreManagerInterface|MockObject
5878
*/
5979
protected $storeManager;
6080

6181
/**
62-
* @var \Magento\Framework\View\DesignInterface
82+
* @var DesignInterface
6383
*/
6484
protected $design;
6585

6686
/**
67-
* @var \Magento\Framework\App\RequestInterface
87+
* @var RequestInterface
6888
*/
6989
protected $request;
7090

7191
/**
72-
* @var \Magento\Framework\View\LayoutInterface
92+
* @var LayoutInterface
7393
*/
7494
protected $layout;
7595

7696
/**
77-
* @var PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
97+
* @var PriceCurrencyInterface|MockObject
7898
*/
7999
private $priceCurrency;
80100

81101
/**
82-
* @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject
102+
* @var Json|MockObject
83103
*/
84104
private $serializer;
85105

86-
protected function setUp()
106+
protected function setUp(): void
87107
{
88108
$this->collectionFactory =
89-
$this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class)
109+
$this->getMockBuilder(CollectionFactory::class)
90110
->setMethods(['create'])
91111
->disableOriginalConstructor()->getMock();
92-
$this->visibility = $this->getMockBuilder(\Magento\Catalog\Model\Product\Visibility::class)
112+
$this->visibility = $this->getMockBuilder(Visibility::class)
93113
->setMethods(['getVisibleInCatalogIds'])
94114
->disableOriginalConstructor()
95115
->getMock();
96-
$this->httpContext = $this->createMock(\Magento\Framework\App\Http\Context::class);
97-
$this->builder = $this->createMock(\Magento\Rule\Model\Condition\Sql\Builder::class);
98-
$this->rule = $this->createMock(\Magento\CatalogWidget\Model\Rule::class);
99-
$this->serializer = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class);
100-
$this->widgetConditionsHelper = $this->getMockBuilder(\Magento\Widget\Helper\Conditions::class)
116+
$this->httpContext = $this->createMock(Context::class);
117+
$this->builder = $this->createMock(Builder::class);
118+
$this->rule = $this->createMock(Rule::class);
119+
$this->serializer = $this->createMock(Json::class);
120+
$this->widgetConditionsHelper = $this->getMockBuilder(Conditions::class)
101121
->disableOriginalConstructor()
102122
->getMock();
103-
$this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
104-
$this->design = $this->createMock(\Magento\Framework\View\DesignInterface::class);
123+
$this->storeManager = $this->createMock(StoreManagerInterface::class);
124+
$this->design = $this->createMock(DesignInterface::class);
105125

106126
$objectManagerHelper = new ObjectManagerHelper($this);
107127
$arguments = $objectManagerHelper->getConstructArguments(
108-
\Magento\CatalogWidget\Block\Product\ProductsList::class,
128+
ProductsList::class,
109129
[
110130
'productCollectionFactory' => $this->collectionFactory,
111131
'catalogProductVisibility' => $this->visibility,
@@ -123,20 +143,20 @@ protected function setUp()
123143
$this->priceCurrency = $this->createMock(PriceCurrencyInterface::class);
124144

125145
$this->productsList = $objectManagerHelper->getObject(
126-
\Magento\CatalogWidget\Block\Product\ProductsList::class,
146+
ProductsList::class,
127147
$arguments
128148
);
129149
$objectManagerHelper->setBackwardCompatibleProperty($this->productsList, 'priceCurrency', $this->priceCurrency);
130150
}
131151

132152
public function testGetCacheKeyInfo()
133153
{
134-
$store = $this->getMockBuilder(\Magento\Store\Model\Store::class)
154+
$store = $this->getMockBuilder(Store::class)
135155
->disableOriginalConstructor()->setMethods(['getId'])->getMock();
136156
$store->expects($this->once())->method('getId')->willReturn(1);
137157
$this->storeManager->expects($this->once())->method('getStore')->willReturn($store);
138158

139-
$theme = $this->createMock(\Magento\Framework\View\Design\ThemeInterface::class);
159+
$theme = $this->createMock(ThemeInterface::class);
140160
$theme->expects($this->once())->method('getId')->willReturn('blank');
141161
$this->design->expects($this->once())->method('getDesignTheme')->willReturn($theme);
142162

@@ -149,7 +169,7 @@ public function testGetCacheKeyInfo()
149169
$this->request->expects($this->once())->method('getParam')->with('page_number')->willReturn(1);
150170

151171
$this->request->expects($this->once())->method('getParams')->willReturn('request_params');
152-
$currency = $this->createMock(\Magento\Directory\Model\Currency::class);
172+
$currency = $this->createMock(Currency::class);
153173
$currency->expects($this->once())->method('getCode')->willReturn('USD');
154174
$this->priceCurrency->expects($this->once())->method('getCurrency')->willReturn($currency);
155175

@@ -178,13 +198,13 @@ public function testGetCacheKeyInfo()
178198

179199
public function testGetProductPriceHtml()
180200
{
181-
$product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
201+
$product = $this->getMockBuilder(Product::class)
182202
->setMethods(['getId'])
183203
->disableOriginalConstructor()
184204
->getMock();
185205
$product->expects($this->once())->method('getId')->willReturn(1);
186206

187-
$priceRenderer = $this->getMockBuilder(\Magento\Framework\Pricing\Render::class)
207+
$priceRenderer = $this->getMockBuilder(Render::class)
188208
->setMethods(['render'])
189209
->disableOriginalConstructor()
190210
->getMock();
@@ -202,7 +222,7 @@ public function testGetProductPriceHtml()
202222
$this->assertEquals('<html>', $this->productsList->getProductPriceHtml(
203223
$product,
204224
'some-price-type',
205-
\Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
225+
Render::ZONE_ITEM_LIST,
206226
[
207227
'include_container' => false,
208228
'display_minimal_price' => false
@@ -217,7 +237,7 @@ public function testGetPagerHtmlEmpty()
217237

218238
public function testGetPagerHtml()
219239
{
220-
$collection = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Collection::class)
240+
$collection = $this->getMockBuilder(Collection::class)
221241
->setMethods(['getSize'])
222242
->disableOriginalConstructor()
223243
->getMock();
@@ -227,7 +247,7 @@ public function testGetPagerHtml()
227247
$this->productsList->setData('products_per_page', 2);
228248
$this->productsList->setData('product_collection', $collection);
229249

230-
$pagerBlock = $this->getMockBuilder(\Magento\Catalog\Block\Product\Widget\Html\Pager::class)
250+
$pagerBlock = $this->getMockBuilder(Pager::class)
231251
->setMethods([
232252
'toHtml',
233253
'setUseContainer',
@@ -266,7 +286,7 @@ public function testCreateCollection($pagerEnable, $productsCount, $productsPerP
266286
{
267287
$this->visibility->expects($this->once())->method('getVisibleInCatalogIds')
268288
->willReturn([Visibility::VISIBILITY_IN_CATALOG, Visibility::VISIBILITY_BOTH]);
269-
$collection = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Collection::class)
289+
$collection = $this->getMockBuilder(Collection::class)
270290
->setMethods([
271291
'setVisibility',
272292
'addMinimalPrice',
@@ -367,14 +387,14 @@ public function testShowPager()
367387

368388
public function testGetIdentities()
369389
{
370-
$collection = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Collection::class)
390+
$collection = $this->getMockBuilder(Collection::class)
371391
->setMethods([
372392
'addAttributeToSelect',
373393
'getIterator',
374394
])->disableOriginalConstructor()
375395
->getMock();
376396

377-
$product = $this->createPartialMock(\Magento\Framework\DataObject\IdentityInterface::class, ['getIdentities']);
397+
$product = $this->createPartialMock(IdentityInterface::class, ['getIdentities']);
378398
$notProduct = $this->getMockBuilder('NotProduct')
379399
->setMethods(['getIdentities'])
380400
->disableOriginalConstructor()
@@ -394,11 +414,11 @@ public function testGetIdentities()
394414
/**
395415
* @param $collection
396416
*
397-
* @return \PHPUnit_Framework_MockObject_MockObject
417+
* @return MockObject
398418
*/
399419
private function getConditionsForCollection($collection)
400420
{
401-
$conditions = $this->getMockBuilder(\Magento\Rule\Model\Condition\Combine::class)
421+
$conditions = $this->getMockBuilder(Combine::class)
402422
->setMethods(['collectValidatedAttributes'])
403423
->disableOriginalConstructor()
404424
->getMock();

app/code/Magento/CatalogWidget/Test/Unit/Block/Product/Widget/ConditionsTest.php

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
@@ -8,44 +8,58 @@
88
use Magento\Backend\Block\Template\Context;
99
use Magento\CatalogWidget\Block\Product\Widget\Conditions;
1010
use Magento\CatalogWidget\Model\Rule;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\Data\Form\Element\AbstractElement;
13+
use Magento\Framework\Data\Form\Element\Fieldset;
14+
use Magento\Framework\Event\ManagerInterface;
15+
use Magento\Framework\Filesystem;
16+
use Magento\Framework\Filesystem\Directory\ReadInterface;
1117
use Magento\Framework\Registry;
1218
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1319
use Magento\Framework\View\Element\BlockInterface;
20+
use Magento\Framework\View\Element\Template\File\Resolver;
21+
use Magento\Framework\View\Element\Template\File\Validator;
1422
use Magento\Framework\View\LayoutInterface;
23+
use Magento\Framework\View\TemplateEngineInterface;
24+
use Magento\Framework\View\TemplateEnginePool;
25+
use Magento\Rule\Model\Condition\Combine;
26+
use Magento\Widget\Model\Widget\Instance;
27+
use PHPUnit\Framework\MockObject\MockObject;
28+
use PHPUnit\Framework\TestCase;
1529

1630
/**
1731
* Test class for \Magento\CatalogWidget\Block\Product\Widget\Conditions
1832
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1933
*/
20-
class ConditionsTest extends \PHPUnit\Framework\TestCase
34+
class ConditionsTest extends TestCase
2135
{
2236
/**
2337
* @var ObjectManagerHelper
2438
*/
2539
private $objectManagerHelper;
2640

2741
/**
28-
* @var Registry|\PHPUnit_Framework_MockObject_MockObject
42+
* @var Registry|MockObject
2943
*/
3044
private $registryMock;
3145

3246
/**
33-
* @var Context|\PHPUnit_Framework_MockObject_MockObject
47+
* @var Context|MockObject
3448
*/
3549
private $contextMock;
3650

3751
/**
38-
* @var Rule|\PHPUnit_Framework_MockObject_MockObject
52+
* @var Rule|MockObject
3953
*/
4054
protected $ruleMock;
4155

4256
/**
43-
* @var LayoutInterface|\PHPUnit_Framework_MockObject_MockObject
57+
* @var LayoutInterface|MockObject
4458
*/
4559
private $layoutMock;
4660

4761
/**
48-
* @var BlockInterface|\PHPUnit_Framework_MockObject_MockObject
62+
* @var BlockInterface|MockObject
4963
*/
5064
private $blockMock;
5165

@@ -57,7 +71,7 @@ class ConditionsTest extends \PHPUnit\Framework\TestCase
5771
/**
5872
* return void
5973
*/
60-
protected function setUp()
74+
protected function setUp(): void
6175
{
6276
$this->objectManagerHelper = new ObjectManagerHelper($this);
6377
$this->ruleMock = $this->getMockBuilder(Rule::class)
@@ -113,8 +127,8 @@ public function testConstructWithWidgetInstance()
113127
{
114128
$widgetParams = ['conditions' => 'some conditions'];
115129

116-
/** @var \Magento\Widget\Model\Widget\Instance|\PHPUnit_Framework_MockObject_MockObject $widgetMock */
117-
$widgetMock = $this->getMockBuilder(\Magento\Widget\Model\Widget\Instance::class)
130+
/** @var Instance|MockObject $widgetMock */
131+
$widgetMock = $this->getMockBuilder(Instance::class)
118132
->disableOriginalConstructor()
119133
->getMock();
120134
$widgetMock->expects($this->once())
@@ -185,19 +199,19 @@ public function testRender()
185199
{
186200
$data = ['area' => 'backend'];
187201
$abstractElementMock = $this->createPartialMock(
188-
\Magento\Framework\Data\Form\Element\AbstractElement::class,
202+
AbstractElement::class,
189203
['getContainer']
190204
);
191-
$eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
192-
$scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
193-
$fieldsetMock = $this->createMock(\Magento\Framework\Data\Form\Element\Fieldset::class);
194-
$combineMock = $this->createMock(\Magento\Rule\Model\Condition\Combine::class);
195-
$resolverMock = $this->createMock(\Magento\Framework\View\Element\Template\File\Resolver::class);
196-
$filesystemMock = $this->createPartialMock(\Magento\Framework\Filesystem::class, ['getDirectoryRead']);
197-
$validatorMock = $this->createMock(\Magento\Framework\View\Element\Template\File\Validator::class);
198-
$templateEnginePoolMock = $this->createMock(\Magento\Framework\View\TemplateEnginePool::class);
199-
$templateEngineMock = $this->createMock(\Magento\Framework\View\TemplateEngineInterface::class);
200-
$directoryReadMock = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadInterface::class);
205+
$eventManagerMock = $this->createMock(ManagerInterface::class);
206+
$scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
207+
$fieldsetMock = $this->createMock(Fieldset::class);
208+
$combineMock = $this->createMock(Combine::class);
209+
$resolverMock = $this->createMock(Resolver::class);
210+
$filesystemMock = $this->createPartialMock(Filesystem::class, ['getDirectoryRead']);
211+
$validatorMock = $this->createMock(Validator::class);
212+
$templateEnginePoolMock = $this->createMock(TemplateEnginePool::class);
213+
$templateEngineMock = $this->createMock(TemplateEngineInterface::class);
214+
$directoryReadMock = $this->createMock(ReadInterface::class);
201215

202216
$this->ruleMock->expects($this->once())->method('getConditions')->willReturn($combineMock);
203217
$combineMock->expects($this->once())->method('setJsFormObject')->willReturnSelf();

0 commit comments

Comments
 (0)