Skip to content

Commit 6ac1098

Browse files
committed
[Msrp] Cover MsrpPriceCalculator by Unit Test
1 parent e8c2526 commit 6ac1098

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Msrp\Test\Unit\Pricing;
10+
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Catalog\Model\Product\Type as Type;
13+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
14+
use Magento\GroupedProduct\Model\Product\Type\Grouped as GroupedType;
15+
use Magento\Msrp\Pricing\MsrpPriceCalculator;
16+
use Magento\MsrpGroupedProduct\Pricing\MsrpPriceCalculator as MsrpGroupedCalculator;
17+
use PHPUnit\Framework\MockObject\MockObject;
18+
use PHPUnit\Framework\TestCase;
19+
20+
class MsrpPriceCalculatorTest extends TestCase
21+
{
22+
/**
23+
* Test getMrspPriceValue() with the data provider below
24+
*
25+
* @param array $msrpPriceCalculators
26+
* @param Product $productMock
27+
* @param float $expected
28+
* @dataProvider getMsrpPriceValueDataProvider
29+
*/
30+
public function testGetMsrpPriceValue($msrpPriceCalculators, $productMock, $expected)
31+
{
32+
$objectManager = new ObjectManager($this);
33+
$pricing = $objectManager->getObject(MsrpPriceCalculator::class,
34+
[
35+
'msrpPriceCalculators' => $msrpPriceCalculators
36+
]
37+
);
38+
39+
$this->assertEquals($expected, $pricing->getMsrpPriceValue($productMock));
40+
}
41+
42+
/**
43+
* Data Provider for test getMrspPriceValue()
44+
*
45+
* @return array
46+
*/
47+
public function getMsrpPriceValueDataProvider()
48+
{
49+
return [
50+
'Get Mrsp Price with grouped product and price calculator is also grouped product type' => [
51+
[
52+
[
53+
'productType' => GroupedType::TYPE_CODE,
54+
'priceCalculator' => $this->createPriceCalculatorMock(
55+
MsrpGroupedCalculator::class, 23.50)
56+
]
57+
],
58+
$this->createProductMock(GroupedType::TYPE_CODE, 0),
59+
23.50
60+
],
61+
'Get Mrsp Price with simple product and price calculator is grouped product type' => [
62+
[
63+
[
64+
'productType' => GroupedType::TYPE_CODE,
65+
'priceCalculator' => $this->createPriceCalculatorMock(
66+
MsrpGroupedCalculator::class, 0)
67+
]
68+
],
69+
$this->createProductMock(Type::TYPE_SIMPLE, 24.88),
70+
24.88
71+
]
72+
];
73+
}
74+
75+
/**
76+
* Create Price Calculator Mock
77+
*
78+
* @param string $class
79+
* @param float $msrpPriceValue
80+
* @return MockObject
81+
*/
82+
private function createPriceCalculatorMock($class, $msrpPriceValue)
83+
{
84+
$priceCalculatorMock = $this->createMock($class);
85+
$priceCalculatorMock->expects($this->any())->method('getMsrpPriceValue')->willReturn($msrpPriceValue);
86+
return $priceCalculatorMock;
87+
}
88+
89+
/**
90+
* Create Product Mock
91+
*
92+
* @param string $typeId
93+
* @param float $msrp
94+
* @return MockObject
95+
*/
96+
private function createProductMock($typeId, $msrp)
97+
{
98+
$productMock = $this->createPartialMock(Product::class, ['getTypeId', 'getMsrp']);
99+
$productMock->expects($this->any())->method('getTypeId')->willReturn($typeId);
100+
$productMock->expects($this->any())->method('getMsrp')->willReturn($msrp);
101+
return $productMock;
102+
}
103+
}

0 commit comments

Comments
 (0)