Skip to content

Commit 7d02f1e

Browse files
authored
Merge pull request #27823 from lbajsarowicz/phpunit8/module-Catalog
#27500 Prepare Catalog module Tests for PHPUnit 8
2 parents fedc10e + efa81d7 commit 7d02f1e

File tree

467 files changed

+9685
-6447
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

467 files changed

+9685
-6447
lines changed

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Category/AbstractCategoryTest.php

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,66 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Category;
89

9-
class AbstractCategoryTest extends \PHPUnit\Framework\TestCase
10+
use Magento\Backend\Block\Template\Context;
11+
use Magento\Catalog\Block\Adminhtml\Category\AbstractCategory;
12+
use Magento\Catalog\Model\Category;
13+
use Magento\Framework\App\RequestInterface;
14+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
15+
use Magento\Framework\UrlInterface;
16+
use Magento\Store\Model\Store;
17+
use Magento\Store\Model\StoreManagerInterface;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
21+
class AbstractCategoryTest extends TestCase
1022
{
1123
/**
12-
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
24+
* @var ObjectManager
1325
*/
1426
protected $objectManager;
1527

1628
/**
17-
* @var \PHPUnit_Framework_MockObject_MockObject
29+
* @var MockObject
1830
*/
1931
protected $contextMock;
2032

2133
/**
22-
* @var \PHPUnit_Framework_MockObject_MockObject
34+
* @var MockObject
2335
*/
2436
protected $storeManagerMock;
2537

2638
/**
27-
* @var \PHPUnit_Framework_MockObject_MockObject
39+
* @var MockObject
2840
*/
2941
protected $requestMock;
3042

3143
/**
32-
* @var \PHPUnit_Framework_MockObject_MockObject
44+
* @var MockObject
3345
*/
3446
protected $urlBuilderMock;
3547

3648
/**
37-
* @var \PHPUnit_Framework_MockObject_MockObject
49+
* @var MockObject
3850
*/
3951
protected $storeMock;
4052

4153
/**
42-
* @var \Magento\Catalog\Block\Adminhtml\Category\AbstractCategory
54+
* @var AbstractCategory
4355
*/
4456
protected $category;
4557

46-
protected function setUp()
58+
protected function setUp(): void
4759
{
48-
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
60+
$this->objectManager = new ObjectManager($this);
4961

50-
$this->contextMock = $this->createMock(\Magento\Backend\Block\Template\Context::class);
62+
$this->contextMock = $this->createMock(Context::class);
5163

5264
$this->requestMock = $this->getMockBuilder(
53-
\Magento\Framework\App\RequestInterface::class
65+
RequestInterface::class
5466
)
5567
->disableOriginalConstructor()
5668
->getMock();
@@ -60,13 +72,13 @@ protected function setUp()
6072
->will($this->returnValue($this->requestMock));
6173

6274
$this->urlBuilderMock = $this->getMockBuilder(
63-
\Magento\Framework\UrlInterface::class
75+
UrlInterface::class
6476
)
6577
->disableOriginalConstructor()
6678
->getMock();
6779

6880
$this->storeManagerMock = $this->getMockBuilder(
69-
\Magento\Store\Model\StoreManagerInterface::class
81+
StoreManagerInterface::class
7082
)
7183
->disableOriginalConstructor()
7284
->getMock();
@@ -75,7 +87,7 @@ protected function setUp()
7587
->method('getStoreManager')
7688
->will($this->returnValue($this->storeManagerMock));
7789

78-
$this->storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
90+
$this->storeMock = $this->getMockBuilder(Store::class)
7991
->disableOriginalConstructor()
8092
->getMock();
8193

@@ -84,7 +96,7 @@ protected function setUp()
8496
->will($this->returnValue($this->urlBuilderMock));
8597

8698
$this->category = $this->objectManager->getObject(
87-
\Magento\Catalog\Block\Adminhtml\Category\AbstractCategory::class,
99+
AbstractCategory::class,
88100
[
89101
'context' => $this->contextMock,
90102
]
@@ -129,6 +141,6 @@ public function testGetRootIds()
129141
$this->storeManagerMock->expects($this->once())->method('getGroups')->willReturn([$this->storeMock]);
130142
$this->storeMock->expects($this->once())->method('getRootCategoryId')->willReturn('storeId');
131143

132-
$this->assertEquals([\Magento\Catalog\Model\Category::TREE_ROOT_ID, 'storeId'], $this->category->getRootIds());
144+
$this->assertEquals([Category::TREE_ROOT_ID, 'storeId'], $this->category->getRootIds());
133145
}
134146
}

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Attribute/Button/CancelTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Product\Attribute\Button;
79

810
use Magento\Catalog\Block\Adminhtml\Product\Attribute\Button\Cancel;
911

10-
/**
11-
* Class CancelTest
12-
*/
1312
class CancelTest extends GenericTest
1413
{
1514
/**

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Attribute/Button/GenericTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,26 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Product\Attribute\Button;
79

810
use Magento\Catalog\Block\Adminhtml\Product\Edit\Button\Generic;
911
use Magento\Framework\Registry;
1012
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1113
use Magento\Framework\View\Element\UiComponent\Context;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
1216

13-
/**
14-
* Class GenericTest
15-
*/
16-
class GenericTest extends \PHPUnit\Framework\TestCase
17+
class GenericTest extends TestCase
1718
{
1819
/**
19-
* @var Context|\PHPUnit_Framework_MockObject_MockObject
20+
* @var Context|MockObject
2021
*/
2122
protected $contextMock;
2223

2324
/**
24-
* @var Registry|\PHPUnit_Framework_MockObject_MockObject
25+
* @var Registry|MockObject
2526
*/
2627
protected $registryMock;
2728

@@ -30,7 +31,7 @@ class GenericTest extends \PHPUnit\Framework\TestCase
3031
*/
3132
protected $objectManager;
3233

33-
protected function setUp()
34+
protected function setUp(): void
3435
{
3536
$this->objectManager = new ObjectManager($this);
3637
$this->contextMock = $this->getMockBuilder(Context::class)

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Attribute/Button/SaveTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Product\Attribute\Button;
79

810
use Magento\Catalog\Block\Adminhtml\Product\Attribute\Button\Save;
911

10-
/**
11-
* Class SaveTest
12-
*/
1312
class SaveTest extends GenericTest
1413
{
1514
/**

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Attribute/Edit/Tab/AdvancedTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Product\Attribute\Edit\Tab;
79

810
use Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab\Advanced;
@@ -22,13 +24,14 @@
2224
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
2325
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2426
use PHPUnit\Framework\MockObject\MockObject;
27+
use PHPUnit\Framework\TestCase;
2528

2629
/**
2730
* Test product attribute add/edit advanced form tab
2831
*
2932
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3033
*/
31-
class AdvancedTest extends \PHPUnit\Framework\TestCase
34+
class AdvancedTest extends TestCase
3235
{
3336
/**
3437
* @var Advanced
@@ -73,7 +76,7 @@ class AdvancedTest extends \PHPUnit\Framework\TestCase
7376
/**
7477
* @inheritdoc
7578
*/
76-
protected function setUp()
79+
protected function setUp(): void
7780
{
7881
$objectManager = new ObjectManager($this);
7982
$this->registry = $this->createMock(Registry::class);

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Attribute/GridTest.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,28 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Product\Attribute;
79

8-
class GridTest extends \PHPUnit\Framework\TestCase
10+
use Magento\Backend\Block\Template\Context;
11+
use Magento\Catalog\Block\Adminhtml\Product\Attribute\Grid;
12+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
13+
use Magento\Framework\Filesystem;
14+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
15+
use Magento\Framework\UrlInterface;
16+
use PHPUnit\Framework\TestCase;
17+
18+
class GridTest extends TestCase
919
{
1020
public function testGetRowUrl()
1121
{
12-
$attribute = $this->createMock(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class);
22+
$attribute = $this->createMock(Attribute::class);
1323
$attribute->expects($this->once())->method('getAttributeId')->will($this->returnValue(2));
1424

15-
$filesystem = $this->createMock(\Magento\Framework\Filesystem::class);
25+
$filesystem = $this->createMock(Filesystem::class);
1626

17-
$urlBuilder = $this->createMock(\Magento\Framework\UrlInterface::class);
27+
$urlBuilder = $this->createMock(UrlInterface::class);
1828
$urlBuilder->expects(
1929
$this->once()
2030
)->method(
@@ -26,15 +36,15 @@ public function testGetRowUrl()
2636
$this->returnValue('catalog/product_attribute/edit/id/2')
2737
);
2838

29-
$context = $this->createMock(\Magento\Backend\Block\Template\Context::class);
39+
$context = $this->createMock(Context::class);
3040
$context->expects($this->once())->method('getUrlBuilder')->will($this->returnValue($urlBuilder));
3141
$context->expects($this->any())->method('getFilesystem')->will($this->returnValue($filesystem));
3242

3343
$data = ['context' => $context];
3444

35-
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
36-
/** @var \Magento\Catalog\Block\Adminhtml\Product\Attribute\Grid $block */
37-
$block = $helper->getObject(\Magento\Catalog\Block\Adminhtml\Product\Attribute\Grid::class, $data);
45+
$helper = new ObjectManager($this);
46+
/** @var Grid $block */
47+
$block = $helper->getObject(Grid::class, $data);
3848

3949
$this->assertEquals('catalog/product_attribute/edit/id/2', $block->getRowUrl($attribute));
4050
}

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Composite/Fieldset/OptionsTest.php

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,68 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Product\Composite\Fieldset;
79

10+
use Magento\Catalog\Block\Adminhtml\Product\Composite\Fieldset\Options;
11+
use Magento\Catalog\Model\CategoryFactory;
12+
use Magento\Catalog\Model\Product;
13+
use Magento\Catalog\Model\Product\Configuration\Item\OptionFactory;
14+
use Magento\Catalog\Model\ProductFactory;
15+
use Magento\Catalog\Model\ResourceModel\Product\Option;
16+
use Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory;
17+
use Magento\Framework\Data\CollectionFactory;
18+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
19+
use Magento\Framework\View\Element\Template\Context;
20+
use Magento\Framework\View\Layout;
21+
use PHPUnit\Framework\TestCase;
22+
823
/**
924
* Test class for \Magento\Catalog\Block\Adminhtml\Product\Composite\Fieldset\Options
1025
*
1126
* @SuppressWarnings(PHPMD.LongVariable)
1227
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1328
*/
14-
class OptionsTest extends \PHPUnit\Framework\TestCase
29+
class OptionsTest extends TestCase
1530
{
1631
/**
17-
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
32+
* @var ObjectManager
1833
*/
1934
protected $_objectHelper;
2035

2136
/**
22-
* @var \Magento\Catalog\Block\Adminhtml\Product\Composite\Fieldset\Options
37+
* @var Options
2338
*/
2439
protected $_optionsBlock;
2540

2641
/**
27-
* @var \Magento\Catalog\Model\ResourceModel\Product\Option
42+
* @var Option
2843
*/
2944
protected $_optionResource;
3045

31-
protected function setUp()
46+
protected function setUp(): void
3247
{
33-
$this->_objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
34-
$this->_optionResource = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product\Option::class);
48+
$this->_objectHelper = new ObjectManager($this);
49+
$this->_optionResource = $this->createMock(Option::class);
3550
}
3651

3752
public function testGetOptionHtml()
3853
{
3954
$layout = $this->createPartialMock(
40-
\Magento\Framework\View\Layout::class,
55+
Layout::class,
4156
['getChildName', 'getBlock', 'renderElement']
4257
);
4358
$context = $this->_objectHelper->getObject(
44-
\Magento\Framework\View\Element\Template\Context::class,
59+
Context::class,
4560
['layout' => $layout]
4661
);
47-
$optionFactoryMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\ValueFactory::class)
48-
->setMethods(['create'])
49-
->disableOriginalConstructor()
50-
->getMock();
51-
62+
$optionFactoryMock = $this->createPartialMock('\Magento\Catalog\Model\Product\Option\ValueFactory', ['create']);
5263
$option = $this->_objectHelper->getObject(
5364
\Magento\Catalog\Model\Product\Option::class,
5465
['resource' => $this->_optionResource, 'optionValueFactory' => $optionFactoryMock]
5566
);
56-
$dateBlock = $this->getMockBuilder(\Magento\Catalog\Block\Adminhtml\Product\Composite\Fieldset\Options::class)
67+
$dateBlock = $this->getMockBuilder(Options::class)
5768
->setMethods(['setSkipJsReloadPrice'])
5869
->setConstructorArgs(['context' => $context, 'option' => $option])
5970
->disableOriginalConstructor()
@@ -65,26 +76,26 @@ public function testGetOptionHtml()
6576
$layout->expects($this->any())->method('renderElement')->with('date', false)->will($this->returnValue('html'));
6677

6778
$this->_optionsBlock = $this->_objectHelper->getObject(
68-
\Magento\Catalog\Block\Adminhtml\Product\Composite\Fieldset\Options::class,
79+
Options::class,
6980
['context' => $context, 'option' => $option]
7081
);
7182

7283
$itemOptFactoryMock = $this->createPartialMock(
73-
\Magento\Catalog\Model\Product\Configuration\Item\OptionFactory::class,
84+
OptionFactory::class,
7485
['create']
7586
);
7687
$stockItemFactoryMock = $this->createPartialMock(
77-
\Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory::class,
88+
StockItemInterfaceFactory::class,
7889
['create']
7990
);
80-
$productFactoryMock = $this->createPartialMock(\Magento\Catalog\Model\ProductFactory::class, ['create']);
81-
$categoryFactoryMock = $this->createPartialMock(\Magento\Catalog\Model\CategoryFactory::class, ['create']);
91+
$productFactoryMock = $this->createPartialMock(ProductFactory::class, ['create']);
92+
$categoryFactoryMock = $this->createPartialMock(CategoryFactory::class, ['create']);
8293

8394
$this->_optionsBlock->setProduct(
8495
$this->_objectHelper->getObject(
85-
\Magento\Catalog\Model\Product::class,
96+
Product::class,
8697
[
87-
'collectionFactory' => $this->createMock(\Magento\Framework\Data\CollectionFactory::class),
98+
'collectionFactory' => $this->createMock(CollectionFactory::class),
8899
'itemOptionFactory' => $itemOptFactoryMock,
89100
'stockItemFactory' => $stockItemFactoryMock,
90101
'productFactory' => $productFactoryMock,

0 commit comments

Comments
 (0)