Skip to content

Commit dec0642

Browse files
ENGCOM-6491: [Msrp] Cover MsrpPriceCalculator by Unit Test #26067
- Merge Pull Request #26067 from edenduong/magento2:2.4-testcover/cover_msrp_price_calculator - Merged commits: 1. 6ac1098 2. fb7aa9c 3. 2be8374
2 parents c7a2450 + 2be8374 commit dec0642

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 ProductType;
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+
* @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+
52+
/**
53+
* Test getMrspPriceValue() with the data provider below
54+
*
55+
* @param array $msrpPriceCalculators
56+
* @param Product $productMock
57+
* @param float $expected
58+
* @dataProvider getMsrpPriceValueDataProvider
59+
*/
60+
public function testGetMsrpPriceValue($msrpPriceCalculatorPrice, $productMock, $expected)
61+
{
62+
$this->msrpGroupedCalculatorMock->expects($this->any())
63+
->method('getMsrpPriceValue')->willReturn($msrpPriceCalculatorPrice);
64+
65+
$this->assertEquals($expected, $this->pricing->getMsrpPriceValue($productMock));
66+
}
67+
68+
/**
69+
* Data Provider for test getMrspPriceValue()
70+
*
71+
* @return array
72+
*/
73+
public function getMsrpPriceValueDataProvider()
74+
{
75+
return [
76+
'Get Mrsp Price with product and msrp calculator and the same product type' => [
77+
23.50,
78+
$this->createProductMock(GroupedType::TYPE_CODE, 0),
79+
23.50
80+
],
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),
84+
24.88
85+
]
86+
];
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)