Definition at line 8 of file StockTest.php.
◆ setUp()
Definition at line 30 of file StockTest.php.
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'])
38 $this->stockItemMock = $this->createPartialMock(
39 \
Magento\CatalogInventory\Model\Stock\Item::class,
40 [
'getIsInStock',
'getQty',
'__wakeup']
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]
50 $attribute = $this->createPartialMock(\
Magento\Framework\DataObject::class, [
'getAttributeCode']);
52 ->method(
'getAttributeCode')
53 ->will($this->returnValue(self::ATTRIBUTE_NAME));
◆ testAfterLoad()
Definition at line 57 of file StockTest.php.
61 $this->stockItemMock->expects($this->once())->method(
'getIsInStock')->will($this->returnValue(1));
62 $this->stockItemMock->expects($this->once())->method(
'getQty')->will($this->returnValue(5));
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']);
◆ $model
◆ $objectHelper
◆ $stockItemMock
◆ $stockRegistry
◆ ATTRIBUTE_NAME
const ATTRIBUTE_NAME = 'quantity_and_stock_status' |
The documentation for this class was generated from the following file:
- vendor/magento/module-catalog/Test/Unit/Model/Product/Attribute/Backend/StockTest.php