1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Stockbase\Integration\Test\Unit\Model\Inventory; |
5
|
|
|
|
6
|
|
|
use Magento\CatalogInventory\Api\Data\StockItemInterface; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Stockbase\Integration\Model\Inventory\CombinedStockbaseStockItem; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class CombinedStockbaseStockItemTest |
12
|
|
|
*/ |
13
|
|
|
class CombinedStockbaseStockItemTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
/** @var StockItemInterface|\PHPUnit_Framework_MockObject_MockObject */ |
16
|
|
|
private $magentoStockItem; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* {@inheritdoc} |
20
|
|
|
*/ |
21
|
60 |
|
public function setUp() |
22
|
|
|
{ |
23
|
60 |
|
$this->magentoStockItem = $this->createMock(StockItemInterface::class); |
24
|
60 |
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* testGetQty |
28
|
|
|
* @dataProvider getQtyProvider |
29
|
|
|
* |
30
|
|
|
* @param mixed $magentoStockQty |
31
|
|
|
* @param mixed $stockbaseStockQty |
32
|
|
|
* @param mixed $expectedResult |
33
|
|
|
*/ |
34
|
5 |
|
public function testGetQty($magentoStockQty, $stockbaseStockQty, $expectedResult) |
35
|
|
|
{ |
36
|
5 |
|
$this->magentoStockItem->expects($this->once())->method('getQty')->willReturn($magentoStockQty); |
37
|
|
|
|
38
|
5 |
|
$item = new CombinedStockbaseStockItem($this->magentoStockItem, $stockbaseStockQty); |
39
|
5 |
|
$this->assertEquals($expectedResult, $item->getQty()); |
40
|
5 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
|
|
public function getQtyProvider() |
46
|
|
|
{ |
47
|
|
|
return [ |
48
|
|
|
[2, 3, 5], |
49
|
|
|
[0, 2, 2], |
50
|
|
|
[7, 0, 7], |
51
|
|
|
[0, 0, 0], |
52
|
|
|
[null, 1, 1], |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* testSetQty |
58
|
|
|
*/ |
59
|
1 |
|
public function testSetQty() |
60
|
|
|
{ |
61
|
1 |
|
$this->expectException(\Exception::class); |
62
|
1 |
|
$this->expectExceptionMessage('Can not set quantity on combined Stockbase stock item.'); |
63
|
|
|
|
64
|
1 |
|
$item = new CombinedStockbaseStockItem($this->magentoStockItem, 0); |
65
|
1 |
|
$item->setQty(1); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* testMethodPassThrough |
70
|
|
|
* @dataProvider methodPassThroughProvider |
71
|
|
|
* |
72
|
|
|
* @param mixed $method |
73
|
|
|
* @param mixed $arg |
74
|
|
|
* @param mixed $returnSelf |
75
|
|
|
*/ |
76
|
53 |
|
public function testMethodPassThrough($method, $arg, $returnSelf) |
77
|
|
|
{ |
78
|
53 |
|
$item = new CombinedStockbaseStockItem($this->magentoStockItem, 0); |
79
|
|
|
|
80
|
53 |
|
$methodMock = $this->magentoStockItem->expects($this->at(0))->method($method); |
81
|
53 |
|
if ($returnSelf) { |
82
|
26 |
|
$methodMock->willReturnSelf(); |
83
|
26 |
|
$expectedResult = $item; |
84
|
|
|
} else { |
85
|
27 |
|
$methodMock->willReturn('TEST_RESULT'); |
86
|
27 |
|
$expectedResult = 'TEST_RESULT'; |
87
|
|
|
} |
88
|
|
|
|
89
|
53 |
|
if ($arg === null) { |
90
|
27 |
|
$methodMock->with(); |
91
|
27 |
|
$result = $item->{$method}(); |
92
|
|
|
} else { |
93
|
26 |
|
$methodMock->with($arg); |
94
|
26 |
|
$result = $item->{$method}($arg); |
95
|
|
|
} |
96
|
|
|
|
97
|
53 |
|
$this->assertEquals($expectedResult, $result); |
98
|
53 |
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return array |
102
|
|
|
*/ |
103
|
|
|
public function methodPassThroughProvider() |
104
|
|
|
{ |
105
|
|
|
return [ |
106
|
|
|
['getItemId', null, false], |
107
|
|
|
['setItemId', 1111, true], |
108
|
|
|
['getProductId', null, false], |
109
|
|
|
['setProductId', 1111, true], |
110
|
|
|
['getStockId', null, false], |
111
|
|
|
['setStockId', 1111, true], |
112
|
|
|
['getIsInStock', null, false], |
113
|
|
|
['setIsInStock', 1111, true], |
114
|
|
|
['getIsQtyDecimal', null, false], |
115
|
|
|
['setIsQtyDecimal', 1111, true], |
116
|
|
|
['getIsQtyDecimal', null, false], |
117
|
|
|
['setIsQtyDecimal', 1111, true], |
118
|
|
|
['getShowDefaultNotificationMessage', null, false], |
119
|
|
|
['getUseConfigMinQty', null, false], |
120
|
|
|
['setUseConfigMinQty', 1111, true], |
121
|
|
|
['getMinQty', null, false], |
122
|
|
|
['setMinQty', 1111, true], |
123
|
|
|
['getUseConfigMinSaleQty', null, false], |
124
|
|
|
['setUseConfigMinSaleQty', 1111, true], |
125
|
|
|
['getMinSaleQty', null, false], |
126
|
|
|
['setMinSaleQty', 1111, true], |
127
|
|
|
['getUseConfigMaxSaleQty', null, false], |
128
|
|
|
['setUseConfigMaxSaleQty', 1111, true], |
129
|
|
|
['getMaxSaleQty', null, false], |
130
|
|
|
['setMaxSaleQty', 1111, true], |
131
|
|
|
['getUseConfigBackorders', null, false], |
132
|
|
|
['setUseConfigBackorders', 1111, true], |
133
|
|
|
['getBackorders', null, false], |
134
|
|
|
['setBackorders', 1111, true], |
135
|
|
|
['getUseConfigNotifyStockQty', null, false], |
136
|
|
|
['setUseConfigNotifyStockQty', 1111, true], |
137
|
|
|
['getNotifyStockQty', null, false], |
138
|
|
|
['setNotifyStockQty', 1111, true], |
139
|
|
|
['getUseConfigQtyIncrements', null, false], |
140
|
|
|
['setUseConfigQtyIncrements', 1111, true], |
141
|
|
|
['getQtyIncrements', null, false], |
142
|
|
|
['setQtyIncrements', 1111, true], |
143
|
|
|
['getUseConfigEnableQtyInc', null, false], |
144
|
|
|
['setUseConfigEnableQtyInc', 1111, true], |
145
|
|
|
['getEnableQtyIncrements', null, false], |
146
|
|
|
['setEnableQtyIncrements', 1111, true], |
147
|
|
|
['getUseConfigManageStock', null, false], |
148
|
|
|
['setUseConfigManageStock', 1111, true], |
149
|
|
|
['getManageStock', null, false], |
150
|
|
|
['setManageStock', 1111, true], |
151
|
|
|
['getLowStockDate', null, false], |
152
|
|
|
['setLowStockDate', 1111, true], |
153
|
|
|
['getIsDecimalDivided', null, false], |
154
|
|
|
['setIsDecimalDivided', 1111, true], |
155
|
|
|
['getStockStatusChangedAuto', null, false], |
156
|
|
|
['setStockStatusChangedAuto', 1111, true], |
157
|
|
|
['getExtensionAttributes', null, false], |
158
|
|
|
['setExtensionAttributes', $this->getMockBuilder(\Magento\CatalogInventory\Api\Data\StockItemExtensionInterface::class)->getMock(), true], |
159
|
|
|
]; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* testMagicCallPassThrough |
164
|
|
|
*/ |
165
|
1 |
|
public function testMagicCallPassThrough() |
166
|
|
|
{ |
167
|
1 |
|
$magentoStockItem = $this->getMockBuilder(\Magento\CatalogInventory\Model\Stock\Item::class) |
168
|
1 |
|
->disableOriginalConstructor() |
169
|
1 |
|
->setMethods(['nonExistentMethod1', 'nonExistentMethod2']) |
170
|
1 |
|
->getMock(); |
171
|
|
|
|
172
|
1 |
|
$magentoStockItem->expects($this->at(0))->method('nonExistentMethod1')->with(); |
173
|
1 |
|
$magentoStockItem->expects($this->at(1))->method('nonExistentMethod2')->with(1, 2, 3); |
174
|
|
|
|
175
|
1 |
|
$item = new CombinedStockbaseStockItem($magentoStockItem, 0); |
176
|
|
|
|
177
|
1 |
|
$item->{'nonExistentMethod1'}(); |
178
|
1 |
|
$item->{'nonExistentMethod2'}(1, 2, 3); |
179
|
1 |
|
} |
180
|
|
|
} |
181
|
|
|
|