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/old/vendor/magento/module-wishlist/Test/Unit/ViewModel/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/magento/module-wishlist/Test/Unit/ViewModel/AllowedQuantityTest.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
declare(strict_types=1);

namespace Magento\Wishlist\Test\Unit\ViewModel;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
use Magento\CatalogInventory\Model\StockRegistry;
use Magento\Store\Model\Store;
use Magento\Wishlist\ViewModel\AllowedQuantity;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class AllowedQuantityTest extends TestCase
{
    /**
     * @var AllowedQuantity
     */
    private $sut;

    /**
     * @var StockRegistry|MockObject
     */
    private $stockRegistryMock;

    /**
     * @var ItemInterface|MockObject
     */
    private $itemMock;

    /**
     * @var Product|MockObject
     */
    private $productMock;

    /**
     * @var Store|MockObject
     */
    private $storeMock;

    /**
     * Set Up
     */
    protected function setUp(): void
    {
        $this->stockRegistryMock = $this->createMock(StockRegistry::class);
        $this->itemMock = $this->getMockForAbstractClass(
            ItemInterface::class,
            [],
            '',
            false,
            true,
            true,
            ['getMinSaleQty', 'getMaxSaleQty']
        );
        $this->productMock = $this->getMockBuilder(Product::class)
            ->disableOriginalConstructor()
            ->getMock();
        $this->storeMock = $this->getMockBuilder(Store::class)
            ->disableOriginalConstructor()
            ->getMock();

        $this->sut = new AllowedQuantity(
            $this->stockRegistryMock
        );
        $this->sut->setItem($this->itemMock);
    }

    /**
     * Getting min and max qty test.
     *
     * @dataProvider saleQuantityDataProvider
     *
     * @param int $minSaleQty
     * @param int $maxSaleQty
     * @param array $expectedResult
     */
    public function testGettingMinMaxQty(int $minSaleQty, int $maxSaleQty, array $expectedResult)
    {
        $this->storeMock->expects($this->atLeastOnce())
            ->method('getWebsiteId')
            ->willReturn(1);
        $this->productMock->expects($this->atLeastOnce())
            ->method('getId')
            ->willReturn(1);
        $this->productMock->expects($this->atLeastOnce())
            ->method('getStore')
            ->willReturn($this->storeMock);
        $this->itemMock->expects($this->any())
            ->method('getProduct')
            ->willReturn($this->productMock);
        $this->itemMock->expects($this->any())
            ->method('getMinSaleQty')
            ->willReturn($minSaleQty);
        $this->itemMock->expects($this->any())
            ->method('getMaxSaleQty')
            ->willReturn($maxSaleQty);
        $this->stockRegistryMock->expects($this->any())
            ->method('getStockItem')
            ->willReturn($this->itemMock);

        $result = $this->sut->getMinMaxQty();

        $this->assertEquals($result, $expectedResult);
    }

    /**
     * Sales quantity provider
     *
     * @return array
     */
    public function saleQuantityDataProvider(): array
    {
        return [
            [
                1,
                10,
                [
                    'minAllowed' => 1,
                    'maxAllowed' => 10
                ]
            ], [
                1,
                0,
                [
                    'minAllowed' => 1,
                    'maxAllowed' => 99999999
                ]
            ]
        ];
    }
}

Spamworldpro Mini