Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/cartforge.co/vendor/magento/module-msrp/Test/Unit/Pricing/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/cartforge.co/vendor/magento/module-msrp/Test/Unit/Pricing/MsrpPriceCalculatorTest.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

declare(strict_types=1);

namespace Magento\Msrp\Test\Unit\Pricing;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Type as ProductType;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\GroupedProduct\Model\Product\Type\Grouped as GroupedType;
use Magento\Msrp\Pricing\MsrpPriceCalculator;
use Magento\MsrpGroupedProduct\Pricing\MsrpPriceCalculator as MsrpGroupedCalculator;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class MsrpPriceCalculatorTest extends TestCase
{
    /**
     * @var MsrpPriceCalculator
     */
    private $pricing;

    /**
     * @var MsrpGroupedCalculator|MockObject
     */
    private $msrpGroupedCalculatorMock;

    /**
     * Prepare environment to test
     */
    protected function setUp(): void
    {
        $objectManager = new ObjectManager($this);
        $this->msrpGroupedCalculatorMock = $this->createMock(MsrpGroupedCalculator::class);
        $this->pricing = $objectManager->getObject(
            MsrpPriceCalculator::class,
            [
                'msrpPriceCalculators' => [
                    [
                        'productType' => GroupedType::TYPE_CODE,
                        'priceCalculator' => $this->msrpGroupedCalculatorMock
                    ]
                ]
            ]
        );
    }

    /**
     * Test getMrspPriceValue() with the data provider below
     *
     * @param array $msrpPriceCalculators
     * @param Product $productMock
     * @param float $expected
     * @dataProvider getMsrpPriceValueDataProvider
     */
    public function testGetMsrpPriceValue($msrpPriceCalculatorPrice, $productMock, $expected)
    {
        $this->msrpGroupedCalculatorMock->expects($this->any())
            ->method('getMsrpPriceValue')->willReturn($msrpPriceCalculatorPrice);

        $this->assertEquals($expected, $this->pricing->getMsrpPriceValue($productMock));
    }

    /**
     * Data Provider for test getMrspPriceValue()
     *
     * @return array
     */
    public function getMsrpPriceValueDataProvider()
    {
        return [
            'Get Mrsp Price with product and msrp calculator and the same product type' => [
                23.50,
                $this->createProductMock(GroupedType::TYPE_CODE, 0),
                23.50
            ],
            'Get Mrsp Price with product and msrp calculator and the different product type' => [
                24.88,
                $this->createProductMock(ProductType::TYPE_SIMPLE, 24.88),
                24.88
            ]
        ];
    }

    /**
     * Create Product Mock
     *
     * @param string $typeId
     * @param float $msrp
     * @return MockObject
     */
    private function createProductMock($typeId, $msrp)
    {
        $productMock = $this->getMockBuilder(Product::class)
            ->addMethods(['getMsrp'])
            ->onlyMethods(['getTypeId'])
            ->disableOriginalConstructor()
            ->getMock();
        $productMock->expects($this->any())->method('getTypeId')->willReturn($typeId);
        $productMock->expects($this->any())->method('getMsrp')->willReturn($msrp);
        return $productMock;
    }
}

Spamworldpro Mini