Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
StockTest Class Reference
Inheritance diagram for StockTest:

Public Member Functions

 testAfterLoad ()
 

Data Fields

const ATTRIBUTE_NAME = 'quantity_and_stock_status'
 

Protected Member Functions

 setUp ()
 

Protected Attributes

 $model
 
 $objectHelper
 
 $stockItemMock
 
 $stockRegistry
 

Detailed Description

Definition at line 8 of file StockTest.php.

Member Function Documentation

◆ setUp()

setUp ( )
protected

Definition at line 30 of file StockTest.php.

31  {
32  $this->objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
33  $this->stockRegistry = $this->getMockBuilder(\Magento\CatalogInventory\Model\StockRegistry::class)
34  ->disableOriginalConstructor()
35  ->setMethods(['getStockItem', '__wakeup'])
36  ->getMock();
37 
38  $this->stockItemMock = $this->createPartialMock(
39  \Magento\CatalogInventory\Model\Stock\Item::class,
40  ['getIsInStock', 'getQty', '__wakeup']
41  );
42 
43  $this->stockRegistry->expects($this->any())
44  ->method('getStockItem')
45  ->will($this->returnValue($this->stockItemMock));
46  $this->model = $this->objectHelper->getObject(
47  \Magento\Catalog\Model\Product\Attribute\Backend\Stock::class,
48  ['stockRegistry' => $this->stockRegistry]
49  );
50  $attribute = $this->createPartialMock(\Magento\Framework\DataObject::class, ['getAttributeCode']);
51  $attribute->expects($this->atLeastOnce())
52  ->method('getAttributeCode')
53  ->will($this->returnValue(self::ATTRIBUTE_NAME));
54  $this->model->setAttribute($attribute);
55  }

◆ testAfterLoad()

testAfterLoad ( )

Definition at line 57 of file StockTest.php.

58  {
59  $productId = 2;
60 
61  $this->stockItemMock->expects($this->once())->method('getIsInStock')->will($this->returnValue(1));
62  $this->stockItemMock->expects($this->once())->method('getQty')->will($this->returnValue(5));
63 
64  $store = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getWebsiteId', '__wakeup']);
65  $store->expects($this->once())
66  ->method('getWebsiteId')
67  ->will($this->returnValue(10));
68  $object = new \Magento\Framework\DataObject(['id' => $productId, 'store' => $store]);
69  $this->model->afterLoad($object);
70  $data = $object->getData();
71  $this->assertEquals(1, $data[self::ATTRIBUTE_NAME]['is_in_stock']);
72  $this->assertEquals(5, $data[self::ATTRIBUTE_NAME]['qty']);
73  }

Field Documentation

◆ $model

$model
protected

Definition at line 15 of file StockTest.php.

◆ $objectHelper

$objectHelper
protected

Definition at line 20 of file StockTest.php.

◆ $stockItemMock

$stockItemMock
protected

Definition at line 23 of file StockTest.php.

◆ $stockRegistry

$stockRegistry
protected

Definition at line 28 of file StockTest.php.

◆ ATTRIBUTE_NAME

const ATTRIBUTE_NAME = 'quantity_and_stock_status'

Definition at line 10 of file StockTest.php.


The documentation for this class was generated from the following file: