Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
CatalogInventoryTest.php
Go to the documentation of this file.
1 <?php
7 
8 class CatalogInventoryTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $model;
14 
18  protected $productMock;
19 
23  protected $duplicateMock;
24 
28  protected $stockItemDoMock;
29 
33  protected $objectManager;
34 
38  protected $stockRegistry;
39 
40  protected function setUp()
41  {
42  $this->productMock = $this->createPartialMock(\Magento\Catalog\Model\Product::class, ['__wakeup', 'getStore']);
43  $store = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getWebsiteId', '__wakeup']);
44  $store->expects($this->any())->method('getWebsiteId')->willReturn(0);
45  $this->productMock->expects($this->any())->method('getStore')->willReturn($store);
46 
47  $this->duplicateMock = $this->createPartialMock(
48  \Magento\Catalog\Model\Product::class,
49  ['setStockData', '__wakeup']
50  );
51 
52  $this->stockItemDoMock = $this->getMockForAbstractClass(
53  \Magento\CatalogInventory\Api\Data\StockItemInterface::class,
54  [
55  'getItemId',
56  'getUseConfigEnableQtyInc',
57  'getEnableQtyIncrements',
58  'gerUseConfigQtyIncrements',
59  'getQtyIncrements'
60  ]
61  );
62 
63  $this->stockRegistry = $this->getMockForAbstractClass(
64  \Magento\CatalogInventory\Api\StockRegistryInterface::class,
65  ['getStockItem']
66  );
67 
68  $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
69  $this->model = $this->objectManager->getObject(
70  \Magento\CatalogInventory\Model\Product\CopyConstructor\CatalogInventory::class,
71  ['stockRegistry' => $this->stockRegistry]
72  );
73  }
74 
76  {
77  $expectedData = [
78  'use_config_min_qty' => 1,
79  'use_config_min_sale_qty' => 1,
80  'use_config_max_sale_qty' => 1,
81  'use_config_backorders' => 1,
82  'use_config_notify_stock_qty' => 1,
83  ];
84  $this->stockItemDoMock->expects($this->any())->method('getStockId')->will($this->returnValue(false));
85 
86  $this->stockRegistry->expects($this->once())
87  ->method('getStockItem')
88  ->will($this->returnValue($this->stockItemDoMock));
89 
90  $this->duplicateMock->expects($this->once())->method('setStockData')->with($expectedData);
91  $this->model->build($this->productMock, $this->duplicateMock);
92  }
93 
95  {
96  $expectedData = [
97  'use_config_min_qty' => 1,
98  'use_config_min_sale_qty' => 1,
99  'use_config_max_sale_qty' => 1,
100  'use_config_backorders' => 1,
101  'use_config_notify_stock_qty' => 1,
102  'use_config_enable_qty_inc' => 'use_config_enable_qty_inc',
103  'enable_qty_increments' => 'enable_qty_increments',
104  'use_config_qty_increments' => 'use_config_qty_increments',
105  'qty_increments' => 'qty_increments',
106  ];
107  $this->stockRegistry->expects($this->once())
108  ->method('getStockItem')
109  ->will($this->returnValue($this->stockItemDoMock));
110 
111  $this->stockItemDoMock->expects($this->any())->method('getItemId')->will($this->returnValue(50));
112  $this->stockItemDoMock->expects($this->any())
113  ->method('getUseConfigEnableQtyInc')
114  ->will($this->returnValue('use_config_enable_qty_inc'));
115  $this->stockItemDoMock->expects($this->any())
116  ->method('getEnableQtyIncrements')
117  ->will($this->returnValue('enable_qty_increments'));
118  $this->stockItemDoMock->expects($this->any())
119  ->method('getUseConfigQtyIncrements')
120  ->will($this->returnValue('use_config_qty_increments'));
121  $this->stockItemDoMock->expects($this->any())
122  ->method('getQtyIncrements')
123  ->will($this->returnValue('qty_increments'));
124 
125  $this->duplicateMock->expects($this->once())->method('setStockData')->with($expectedData);
126  $this->model->build($this->productMock, $this->duplicateMock);
127  }
128 }