Skip to content

Commit 78ed6c7

Browse files
committed
#27500 PHPUnit9 for Sales module
1 parent 445c022 commit 78ed6c7

File tree

256 files changed

+3158
-2457
lines changed

Some content is hidden

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

256 files changed

+3158
-2457
lines changed

app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Items/AbstractItemsTest.php

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
<?php declare(strict_types=1);
1+
<?php
22
/**
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Sales\Test\Unit\Block\Adminhtml\Items;
79

810
use Magento\Backend\Block\Template\Context;
@@ -40,17 +42,17 @@ protected function setUp(): void
4042
$this->objectManagerHelper = new ObjectManagerHelper($this);
4143
$this->stockRegistry = $this->getMockBuilder(StockRegistry::class)
4244
->disableOriginalConstructor()
43-
->setMethods(['getStockItem', '__wakeup'])
45+
->setMethods(['getStockItem'])
4446
->getMock();
4547

4648
$this->stockItemMock = $this->createPartialMock(
4749
Item::class,
48-
['getManageStock', '__wakeup']
50+
['getManageStock']
4951
);
5052

5153
$this->stockRegistry->expects($this->any())
5254
->method('getStockItem')
53-
->will($this->returnValue($this->stockItemMock));
55+
->willReturn($this->stockItemMock);
5456
}
5557

5658
public function testGetItemRenderer()
@@ -62,11 +64,11 @@ public function testGetItemRenderer()
6264
$layout->expects($this->any())
6365
->method('getChildName')
6466
->with(null, 'some-type')
65-
->will($this->returnValue('column_block-name'));
67+
->willReturn('column_block-name');
6668
$layout->expects($this->any())
6769
->method('getGroupChildNames')
6870
->with(null, 'column')
69-
->will($this->returnValue(['column_block-name']));
71+
->willReturn(['column_block-name']);
7072

7173
/** @var DefaultRenderer $renderer */
7274
$renderer = $this->objectManagerHelper
@@ -76,7 +78,7 @@ public function testGetItemRenderer()
7678
$layout->expects($this->any())
7779
->method('getBlock')
7880
->with('column_block-name')
79-
->will($this->returnValue($renderer));
81+
->willReturn($renderer);
8082

8183
/** @var AbstractItems $block */
8284
$block = $this->objectManagerHelper->getObject(AbstractItems::class);
@@ -93,16 +95,16 @@ public function testGetItemRendererThrowsExceptionForNonexistentRenderer()
9395
$renderer = $this->createMock(\stdClass::class);
9496
$layout = $this->createPartialMock(
9597
Layout::class,
96-
['getChildName', 'getBlock', '__wakeup']
98+
['getChildName', 'getBlock']
9799
);
98100
$layout->expects($this->at(0))
99101
->method('getChildName')
100102
->with(null, 'some-type')
101-
->will($this->returnValue('some-block-name'));
103+
->willReturn('some-block-name');
102104
$layout->expects($this->at(1))
103105
->method('getBlock')
104106
->with('some-block-name')
105-
->will($this->returnValue($renderer));
107+
->willReturn($renderer);
106108

107109
/** @var \Magento\Sales\Block\Adminhtml\Items\AbstractItems $block */
108110
$block = $this->objectManagerHelper->getObject(
@@ -128,10 +130,12 @@ public function testCanReturnItemToStock($canReturnToStock, $itemConfig, $result
128130
{
129131
$productId = isset($itemConfig['product_id']) ? $itemConfig['product_id'] : null;
130132
$manageStock = isset($itemConfig['manage_stock']) ? $itemConfig['manage_stock'] : null;
131-
$item = $this->createPartialMock(
132-
\Magento\Sales\Model\Order\Creditmemo\Item::class,
133-
['hasCanReturnToStock', 'getOrderItem', 'setCanReturnToStock', 'getCanReturnToStock', '__wakeup']
134-
);
133+
$item = $this->getMockBuilder(\Magento\Sales\Model\Order\Creditmemo\Item::class)->addMethods(
134+
['hasCanReturnToStock', 'setCanReturnToStock', 'getCanReturnToStock']
135+
)
136+
->onlyMethods(['getOrderItem'])
137+
->disableOriginalConstructor()
138+
->getMock();
135139
$dependencies = $this->prepareServiceMockDependency(
136140
$item,
137141
$canReturnToStock,
@@ -162,45 +166,44 @@ protected function prepareServiceMockDependency($item, $canReturnToStock, $produ
162166

163167
$this->stockItemMock->expects($this->any())
164168
->method('getManageStock')
165-
->will($this->returnValue($manageStock));
169+
->willReturn($manageStock);
166170
$dependencies['stockRegistry'] = $this->stockRegistry;
167171

168172
$item->expects($this->once())
169173
->method('hasCanReturnToStock')
170-
->will($this->returnValue($itemConfig['has_can_return_to_stock']));
174+
->willReturn($itemConfig['has_can_return_to_stock']);
171175
if (!$itemConfig['has_can_return_to_stock']) {
172176
$orderItem = $this->createPartialMock(
173177
\Magento\Sales\Model\Order\Item::class,
174-
['getProductId', '__wakeup', 'getStore']
178+
['getProductId', 'getStore']
175179
);
176180

177181
$store = $this->createPartialMock(Store::class, ['getWebsiteId']);
178182
$store->expects($this->once())
179183
->method('getWebsiteId')
180-
->will($this->returnValue(10));
184+
->willReturn(10);
181185
$orderItem->expects($this->once())
182186
->method('getStore')
183-
->will($this->returnValue($store));
187+
->willReturn($store);
184188

185189
$orderItem->expects($this->once())
186190
->method('getProductId')
187-
->will($this->returnValue($productId));
191+
->willReturn($productId);
188192
$item->expects($this->any())
189193
->method('getOrderItem')
190-
->will($this->returnValue($orderItem));
194+
->willReturn($orderItem);
191195
if ($productId && $manageStock) {
192196
$canReturn = true;
193197
} else {
194198
$canReturn = false;
195199
}
196200
$item->expects($this->once())
197201
->method('setCanReturnToStock')
198-
->with($this->equalTo($canReturn))
199-
->will($this->returnSelf());
202+
->with($canReturn)->willReturnSelf();
200203
}
201204
$item->expects($this->once())
202205
->method('getCanReturnToStock')
203-
->will($this->returnValue($canReturnToStock));
206+
->willReturn($canReturnToStock);
204207

205208
return $dependencies;
206209
}
@@ -209,11 +212,11 @@ public function testCanReturnItemToStockEmpty()
209212
{
210213
$stockConfiguration = $this->getMockBuilder(Configuration::class)
211214
->disableOriginalConstructor()
212-
->setMethods(['canSubtractQty', '__wakeup'])
215+
->setMethods(['canSubtractQty'])
213216
->getMock();
214217
$stockConfiguration->expects($this->once())
215218
->method('canSubtractQty')
216-
->will($this->returnValue(true));
219+
->willReturn(true);
217220

218221
/** @var \Magento\Sales\Block\Adminhtml\Items\AbstractItems $block */
219222
$block = $this->objectManagerHelper->getObject(

app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Items/AbstractTest.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
<?php declare(strict_types=1);
1+
<?php
22
/**
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Sales\Test\Unit\Block\Adminhtml\Items;
79

810
use Magento\Backend\Block\Template\Context;
@@ -27,7 +29,7 @@ public function testGetItemRenderer()
2729
$renderer = $this->createMock(AbstractBlock::class);
2830
$layout = $this->createPartialMock(
2931
Layout::class,
30-
['getChildName', 'getBlock', 'getGroupChildNames', '__wakeup']
32+
['getChildName', 'getBlock', 'getGroupChildNames']
3133
);
3234
$layout->expects(
3335
$this->at(0)
@@ -36,17 +38,17 @@ public function testGetItemRenderer()
3638
)->with(
3739
null,
3840
'some-type'
39-
)->will(
40-
$this->returnValue('some-block-name')
41+
)->willReturn(
42+
'some-block-name'
4143
);
4244
$layout->expects(
4345
$this->at(1)
4446
)->method(
4547
'getBlock'
4648
)->with(
4749
'some-block-name'
48-
)->will(
49-
$this->returnValue($renderer)
50+
)->willReturn(
51+
$renderer
5052
);
5153

5254
/** @var AbstractItems $block */
@@ -70,7 +72,7 @@ public function testGetItemRendererThrowsExceptionForNonexistentRenderer()
7072
$renderer = $this->createMock(\stdClass::class);
7173
$layout = $this->createPartialMock(
7274
Layout::class,
73-
['getChildName', 'getBlock', '__wakeup']
75+
['getChildName', 'getBlock']
7476
);
7577
$layout->expects(
7678
$this->at(0)
@@ -79,17 +81,17 @@ public function testGetItemRendererThrowsExceptionForNonexistentRenderer()
7981
)->with(
8082
null,
8183
'some-type'
82-
)->will(
83-
$this->returnValue('some-block-name')
84+
)->willReturn(
85+
'some-block-name'
8486
);
8587
$layout->expects(
8688
$this->at(1)
8789
)->method(
8890
'getBlock'
8991
)->with(
9092
'some-block-name'
91-
)->will(
92-
$this->returnValue($renderer)
93+
)->willReturn(
94+
$renderer
9395
);
9496

9597
/** @var AbstractItems $block */

app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Items/Column/DefaultColumnTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
<?php declare(strict_types=1);
1+
<?php
22
/**
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Sales\Test\Unit\Block\Adminhtml\Items\Column;
79

810
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
@@ -34,7 +36,7 @@ protected function setUp(): void
3436
);
3537
$this->itemMock = $this->getMockBuilder(Item::class)
3638
->disableOriginalConstructor()
37-
->setMethods(['getRowTotal', 'getDiscountAmount', 'getBaseRowTotal', 'getBaseDiscountAmount', '__wakeup'])
39+
->setMethods(['getRowTotal', 'getDiscountAmount', 'getBaseRowTotal', 'getBaseDiscountAmount'])
3840
->getMock();
3941
}
4042

@@ -45,10 +47,10 @@ public function testGetTotalAmount()
4547
$expectedResult = 8;
4648
$this->itemMock->expects($this->once())
4749
->method('getRowTotal')
48-
->will($this->returnValue($rowTotal));
50+
->willReturn($rowTotal);
4951
$this->itemMock->expects($this->once())
5052
->method('getDiscountAmount')
51-
->will($this->returnValue($discountAmount));
53+
->willReturn($discountAmount);
5254
$this->assertEquals($expectedResult, $this->defaultColumn->getTotalAmount($this->itemMock));
5355
}
5456

@@ -59,10 +61,10 @@ public function testGetBaseTotalAmount()
5961
$expectedResult = 8;
6062
$this->itemMock->expects($this->once())
6163
->method('getBaseRowTotal')
62-
->will($this->returnValue($baseRowTotal));
64+
->willReturn($baseRowTotal);
6365
$this->itemMock->expects($this->once())
6466
->method('getBaseDiscountAmount')
65-
->will($this->returnValue($baseDiscountAmount));
67+
->willReturn($baseDiscountAmount);
6668
$this->assertEquals($expectedResult, $this->defaultColumn->getBaseTotalAmount($this->itemMock));
6769
}
6870
}

app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Comments/ViewTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
<?php declare(strict_types=1);
1+
<?php
22
/**
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Sales\Test\Unit\Block\Adminhtml\Order\Comments;
79

810
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
@@ -48,7 +50,7 @@ public function testEscapeHtml($data, $expected, $allowedTags = null)
4850
$this->adminHelperMock
4951
->expects($this->any())
5052
->method('escapeHtmlWithLinks')
51-
->will($this->returnValue($expected));
53+
->willReturn($expected);
5254
$actual = $this->commentsView->escapeHtml($data, $allowedTags);
5355
$this->assertEquals($expected, $actual);
5456
}

app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Create/AbstractCreateTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
<?php declare(strict_types=1);
1+
<?php
22
/**
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Sales\Test\Unit\Block\Adminhtml\Order\Create;
89

app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Create/CustomerTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
<?php declare(strict_types=1);
1+
<?php
22
/**
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Sales\Test\Unit\Block\Adminhtml\Order\Create;
79

810
use Magento\Backend\Block\Template\Context;
@@ -17,7 +19,7 @@ public function testGetButtonsHtml()
1719
{
1820
$contextMock = $this->createPartialMock(Context::class, ['getAuthorization']);
1921
$authorizationMock = $this->createMock(AuthorizationInterface::class);
20-
$contextMock->expects($this->any())->method('getAuthorization')->will($this->returnValue($authorizationMock));
22+
$contextMock->expects($this->any())->method('getAuthorization')->willReturn($authorizationMock);
2123
$arguments = ['context' => $contextMock];
2224

2325
$helper = new ObjectManager($this);
@@ -27,7 +29,7 @@ public function testGetButtonsHtml()
2729
$authorizationMock->expects($this->atLeastOnce())
2830
->method('isAllowed')
2931
->with('Magento_Customer::manage')
30-
->will($this->returnValue(false));
32+
->willReturn(false);
3133

3234
$this->assertEmpty($block->getButtonsHtml());
3335
}

0 commit comments

Comments
 (0)