![]() 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-catalog-inventory/Test/Unit/Block/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\CatalogInventory\Test\Unit\Block; use Magento\Catalog\Model\Product; use Magento\CatalogInventory\Api\Data\StockItemInterface; use Magento\CatalogInventory\Api\StockRegistryInterface; use Magento\CatalogInventory\Block\Qtyincrements; use Magento\Framework\Registry; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Store\Model\Store; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** * Unit test for Qtyincrements block */ class QtyincrementsTest extends TestCase { /** * @var Qtyincrements */ protected $block; /** * @var Registry|MockObject */ protected $registryMock; /** * @var StockItemInterface|MockObject */ protected $stockItem; /** * @var StockRegistryInterface|MockObject */ protected $stockRegistry; protected function setUp(): void { $objectManager = new ObjectManager($this); $this->registryMock = $this->createMock(Registry::class); $this->stockItem = $this->getMockBuilder(StockItemInterface::class) ->setMethods(['getQtyIncrements', 'getStockItem']) ->getMockForAbstractClass(); $this->stockItem->expects($this->any())->method('getStockItem')->willReturn(1); $this->stockRegistry = $this->getMockForAbstractClass( StockRegistryInterface::class, ['getStockItem'], '', false ); $this->stockRegistry->expects($this->any())->method('getStockItem')->willReturn($this->stockItem); $this->block = $objectManager->getObject( Qtyincrements::class, [ 'registry' => $this->registryMock, 'stockRegistry' => $this->stockRegistry ] ); } protected function tearDown(): void { $this->block = null; } public function testGetIdentities() { $productTags = ['catalog_product_1']; $product = $this->createMock(Product::class); $product->expects($this->once())->method('getIdentities')->willReturn($productTags); $store = $this->createPartialMock(Store::class, ['getWebsiteId', '__wakeup']); $store->expects($this->any())->method('getWebsiteId')->willReturn(0); $product->expects($this->any())->method('getStore')->willReturn($store); $this->registryMock->expects($this->once()) ->method('registry') ->with('current_product') ->willReturn($product); $this->assertEquals($productTags, $this->block->getIdentities()); } /** * @param int $productId * @param int $qtyInc * @param bool $isSaleable * @param int|bool $result * @dataProvider getProductQtyIncrementsDataProvider */ public function testGetProductQtyIncrements($productId, $qtyInc, $isSaleable, $result) { $this->stockItem->expects($this->once()) ->method('getQtyIncrements') ->willReturn($qtyInc); $product = $this->createMock(Product::class); $product->expects($this->once())->method('getId')->willReturn($productId); $product->expects($this->once())->method('isSaleable')->willReturn($isSaleable); $store = $this->createPartialMock(Store::class, ['getWebsiteId', '__wakeup']); $store->expects($this->any())->method('getWebsiteId')->willReturn(0); $product->expects($this->any())->method('getStore')->willReturn($store); $this->registryMock->expects($this->any()) ->method('registry') ->with('current_product') ->willReturn($product); $this->assertSame($result, $this->block->getProductQtyIncrements()); // test lazy load $this->assertSame($result, $this->block->getProductQtyIncrements()); } /** * @return array */ public function getProductQtyIncrementsDataProvider() { return [ [1, 100, true, 100], [1, 100, false, false], ]; } }