Skip to content

Commit 2be8374

Browse files
committed
Refactor code
1 parent fb7aa9c commit 2be8374

File tree

1 file changed

+40
-45
lines changed

1 file changed

+40
-45
lines changed

app/code/Magento/Msrp/Test/Unit/Pricing/MsrpPriceCalculatorTest.php

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Magento\Msrp\Test\Unit\Pricing;
1010

1111
use Magento\Catalog\Model\Product;
12-
use Magento\Catalog\Model\Product\Type as Type;
12+
use Magento\Catalog\Model\Product\Type as ProductType;
1313
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1414
use Magento\GroupedProduct\Model\Product\Type\Grouped as GroupedType;
1515
use Magento\Msrp\Pricing\MsrpPriceCalculator;
@@ -19,6 +19,36 @@
1919

2020
class MsrpPriceCalculatorTest extends TestCase
2121
{
22+
/**
23+
* @var MsrpPriceCalculator
24+
*/
25+
private $pricing;
26+
27+
/**
28+
* @var MsrpGroupedCalculator|MockObject
29+
*/
30+
private $msrpGroupedCalculatorMock;
31+
32+
/**
33+
* Prepare environment to test
34+
*/
35+
protected function setUp()
36+
{
37+
$objectManager = new ObjectManager($this);
38+
$this->msrpGroupedCalculatorMock = $this->createMock(MsrpGroupedCalculator::class);
39+
$this->pricing = $objectManager->getObject(
40+
MsrpPriceCalculator::class,
41+
[
42+
'msrpPriceCalculators' => [
43+
[
44+
'productType' => GroupedType::TYPE_CODE,
45+
'priceCalculator' => $this->msrpGroupedCalculatorMock
46+
]
47+
]
48+
]
49+
);
50+
}
51+
2252
/**
2353
* Test getMrspPriceValue() with the data provider below
2454
*
@@ -27,17 +57,12 @@ class MsrpPriceCalculatorTest extends TestCase
2757
* @param float $expected
2858
* @dataProvider getMsrpPriceValueDataProvider
2959
*/
30-
public function testGetMsrpPriceValue($msrpPriceCalculators, $productMock, $expected)
60+
public function testGetMsrpPriceValue($msrpPriceCalculatorPrice, $productMock, $expected)
3161
{
32-
$objectManager = new ObjectManager($this);
33-
$pricing = $objectManager->getObject(
34-
MsrpPriceCalculator::class,
35-
[
36-
'msrpPriceCalculators' => $msrpPriceCalculators
37-
]
38-
);
62+
$this->msrpGroupedCalculatorMock->expects($this->any())
63+
->method('getMsrpPriceValue')->willReturn($msrpPriceCalculatorPrice);
3964

40-
$this->assertEquals($expected, $pricing->getMsrpPriceValue($productMock));
65+
$this->assertEquals($expected, $this->pricing->getMsrpPriceValue($productMock));
4166
}
4267

4368
/**
@@ -48,49 +73,19 @@ public function testGetMsrpPriceValue($msrpPriceCalculators, $productMock, $expe
4873
public function getMsrpPriceValueDataProvider()
4974
{
5075
return [
51-
'Get Mrsp Price with grouped product and price calculator is also grouped product type' => [
52-
[
53-
[
54-
'productType' => GroupedType::TYPE_CODE,
55-
'priceCalculator' => $this->createPriceCalculatorMock(
56-
MsrpGroupedCalculator::class,
57-
23.50
58-
)
59-
]
60-
],
76+
'Get Mrsp Price with product and msrp calculator and the same product type' => [
77+
23.50,
6178
$this->createProductMock(GroupedType::TYPE_CODE, 0),
6279
23.50
6380
],
64-
'Get Mrsp Price with simple product and price calculator is grouped product type' => [
65-
[
66-
[
67-
'productType' => GroupedType::TYPE_CODE,
68-
'priceCalculator' => $this->createPriceCalculatorMock(
69-
MsrpGroupedCalculator::class,
70-
0
71-
)
72-
]
73-
],
74-
$this->createProductMock(Type::TYPE_SIMPLE, 24.88),
81+
'Get Mrsp Price with product and msrp calculator and the different product type' => [
82+
24.88,
83+
$this->createProductMock(ProductType::TYPE_SIMPLE, 24.88),
7584
24.88
7685
]
7786
];
7887
}
7988

80-
/**
81-
* Create Price Calculator Mock
82-
*
83-
* @param string $class
84-
* @param float $msrpPriceValue
85-
* @return MockObject
86-
*/
87-
private function createPriceCalculatorMock($class, $msrpPriceValue)
88-
{
89-
$priceCalculatorMock = $this->createMock($class);
90-
$priceCalculatorMock->expects($this->any())->method('getMsrpPriceValue')->willReturn($msrpPriceValue);
91-
return $priceCalculatorMock;
92-
}
93-
9489
/**
9590
* Create Product Mock
9691
*

0 commit comments

Comments
 (0)