6 declare(strict_types=1);
28 private $stockManagement;
33 private $stockResourceMock;
38 private $stockRegistryProviderMock;
43 private $stockStateMock;
48 private $stockConfigurationMock;
53 private $productRepositoryMock;
58 private $qtyCounterMock;
63 private $stockRegistryStorageMock;
68 private $stockItemInterfaceMock;
73 private $websiteId = 0;
77 $this->stockResourceMock = $this->getMockBuilder(ResourceStock::class)
78 ->disableOriginalConstructor()
80 $this->stockRegistryProviderMock = $this->getMockBuilder(StockRegistryProviderInterface::class)
81 ->disableOriginalConstructor()
82 ->getMockForAbstractClass();
83 $this->stockStateMock = $this->getMockBuilder(StockState::class)
84 ->disableOriginalConstructor()
86 $this->stockConfigurationMock = $this->getMockBuilder(StockConfigurationInterface::class)
87 ->disableOriginalConstructor()
88 ->getMockForAbstractClass();
89 $this->productRepositoryMock = $this->getMockBuilder(ProductRepositoryInterface::class)
90 ->disableOriginalConstructor()
91 ->getMockForAbstractClass();
92 $this->qtyCounterMock = $this->getMockBuilder(QtyCounterInterface::class)
93 ->disableOriginalConstructor()
94 ->getMockForAbstractClass();
95 $this->stockRegistryStorageMock = $this->getMockBuilder(StockRegistryStorage::class)
96 ->disableOriginalConstructor()
98 $this->stockItemInterfaceMock = $this->getMockBuilder(StockItemInterface::class)
99 ->setMethods([
'hasAdminArea',
'getWebsiteId'])
100 ->disableOriginalConstructor()
101 ->getMockForAbstractClass();
102 $this->stockManagement = $this->getMockBuilder(StockManagement::class)
103 ->setMethods([
'getResource',
'canSubtractQty'])
104 ->setConstructorArgs(
106 'stockResource' => $this->stockResourceMock,
107 'stockRegistryProvider' => $this->stockRegistryProviderMock,
108 'stockState' => $this->stockStateMock,
109 'stockConfiguration' => $this->stockConfigurationMock,
110 'productRepository' => $this->productRepositoryMock,
111 'qtyCounter' => $this->qtyCounterMock,
112 'stockRegistryStorage' => $this->stockRegistryStorageMock,
116 $this->stockConfigurationMock
117 ->expects($this->once())
118 ->method(
'getDefaultScopeId')
119 ->willReturn($this->websiteId);
120 $this->stockManagement
121 ->expects($this->any())
122 ->method(
'getResource')
123 ->willReturn($this->stockResourceMock);
124 $this->stockRegistryProviderMock
125 ->expects($this->any())
126 ->method(
'getStockItem')
127 ->willReturn($this->stockItemInterfaceMock);
128 $this->stockItemInterfaceMock
129 ->expects($this->any())
130 ->method(
'hasAdminArea')
150 bool $verifyStock =
true 152 $this->stockResourceMock
153 ->expects($this->once())
154 ->method(
'beginTransaction');
155 $this->stockResourceMock
156 ->expects($this->once())
157 ->method(
'lockProductsStock')
158 ->willReturn([$lockedItems]);
159 $this->stockItemInterfaceMock
160 ->expects($this->any())
161 ->method(
'getItemId')
162 ->willReturn($lockedItems[
'product_id']);
163 $this->stockManagement
164 ->expects($this->any())
165 ->method(
'canSubtractQty')
166 ->willReturn($canSubtract);
167 $this->stockConfigurationMock
168 ->expects($this->any())
170 ->willReturn($isQty);
171 $this->stockItemInterfaceMock
172 ->expects($this->any())
173 ->method(
'getWebsiteId')
174 ->willReturn($this->websiteId);
175 $this->stockStateMock
176 ->expects($this->any())
179 $this->stockStateMock
180 ->expects($this->any())
181 ->method(
'verifyStock')
182 ->willReturn($verifyStock);
183 $this->stockStateMock
184 ->expects($this->any())
185 ->method(
'verifyNotification')
187 $this->stockResourceMock
188 ->expects($this->once())
191 $this->stockManagement->registerProductsSale(
$items, $this->websiteId);
206 $this->stockResourceMock
207 ->expects($this->once())
208 ->method(
'beginTransaction');
209 $this->stockResourceMock
210 ->expects($this->once())
211 ->method(
'lockProductsStock')
212 ->willReturn([$lockedItems]);
213 $this->stockItemInterfaceMock
214 ->expects($this->any())
215 ->method(
'getItemId')
216 ->willReturn($lockedItems[
'product_id']);
217 $this->stockManagement
218 ->expects($this->any())
219 ->method(
'canSubtractQty')
221 $this->stockConfigurationMock
222 ->expects($this->any())
225 $this->stockStateMock
226 ->expects($this->any())
229 $this->stockResourceMock
230 ->expects($this->once())
233 $this->stockManagement->registerProductsSale(
$items, $this->websiteId);
247 'type_id' =>
'simple',
257 'type_id' =>
'simple',
267 'type_id' =>
'simple',
287 'type_id' =>
'simple',
productsWithIncorrectQtyDataProvider()
productsWithCorrectQtyDataProvider()
testRegisterProductsSaleException(array $items, array $lockedItems)
testRegisterProductsSale(array $items, array $lockedItems, bool $canSubtract, bool $isQty, bool $verifyStock=true)