Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AdvancedInventoryTest.php
Go to the documentation of this file.
1 <?php
7 
15 
20 {
24  private $stockRegistryMock;
25 
29  private $stockItemMock;
30 
34  private $stockConfigurationMock;
35 
39  private $serializerMock;
40 
44  private $jsonValidatorMock;
45 
46  protected function setUp()
47  {
48  parent::setUp();
49  $this->stockRegistryMock = $this->getMockBuilder(StockRegistryInterface::class)
50  ->setMethods(['getStockItem'])
51  ->getMockForAbstractClass();
52  $this->storeMock = $this->getMockBuilder(Store::class)
53  ->disableOriginalConstructor()
54  ->getMock();
55  $this->stockItemMock = $this->getMockBuilder(StockItemInterface::class)
56  ->setMethods(['getData'])
57  ->getMockForAbstractClass();
58  $this->stockConfigurationMock = $this->getMockBuilder(StockConfigurationInterface::class)
59  ->disableOriginalConstructor()
60  ->getMockForAbstractClass();
61 
62  $this->stockRegistryMock->expects($this->any())
63  ->method('getStockItem')
64  ->willReturn($this->stockItemMock);
65  $this->productMock->expects($this->any())
66  ->method('getStore')
67  ->willReturn($this->storeMock);
68  $this->serializerMock = $this->createMock(Json::class);
69  $this->jsonValidatorMock = $this->getMockBuilder(\Magento\Framework\Serialize\JsonValidator::class)
70  ->disableOriginalConstructor()
71  ->getMock();
72  }
73 
77  protected function createModel()
78  {
79  return $this->objectManager->getObject(
80  AdvancedInventory::class,
81  [
82  'locator' => $this->locatorMock,
83  'stockRegistry' => $this->stockRegistryMock,
84  'stockConfiguration' => $this->stockConfigurationMock,
85  'arrayManager' => $this->arrayManagerMock,
86  'serializer' => $this->serializerMock,
87  'jsonValidator' => $this->jsonValidatorMock,
88  ]
89  );
90  }
91 
92  public function testModifyMeta()
93  {
94  $this->assertNotEmpty($this->getModel()->modifyMeta(['meta_key' => 'meta_value']));
95  }
96 
106  public function testModifyData(
107  $modelId,
108  $someData,
109  $defaultConfigValue,
110  $unserializedValue = null,
111  $serializeCalledNum = 0,
112  $isValidCalledNum = 0
113  ) {
114  $this->productMock->expects($this->any())
115  ->method('getId')
116  ->willReturn($modelId);
117 
118  $this->stockConfigurationMock->expects($this->any())
119  ->method('getDefaultConfigValue')
120  ->willReturn($defaultConfigValue);
121 
122  $this->serializerMock->expects($this->exactly($serializeCalledNum))
123  ->method('unserialize')
124  ->with($defaultConfigValue)
125  ->willReturn($unserializedValue);
126 
127  $this->jsonValidatorMock->expects($this->exactly($isValidCalledNum))
128  ->method('isValid')
129  ->willReturn(true);
130 
131  $this->stockItemMock->expects($this->once())->method('getData')->willReturn(['someData']);
132  $this->stockItemMock->expects($this->once())->method('getManageStock')->willReturn($someData);
133  $this->stockItemMock->expects($this->once())->method('getQty')->willReturn($someData);
134  $this->stockItemMock->expects($this->once())->method('getMinQty')->willReturn($someData);
135  $this->stockItemMock->expects($this->once())->method('getMinSaleQty')->willReturn($someData);
136  $this->stockItemMock->expects($this->once())->method('getMaxSaleQty')->willReturn($someData);
137  $this->stockItemMock->expects($this->once())->method('getIsQtyDecimal')->willReturn($someData);
138  $this->stockItemMock->expects($this->once())->method('getIsDecimalDivided')->willReturn($someData);
139  $this->stockItemMock->expects($this->once())->method('getBackorders')->willReturn($someData);
140  $this->stockItemMock->expects($this->once())->method('getNotifyStockQty')->willReturn($someData);
141  $this->stockItemMock->expects($this->once())->method('getEnableQtyIncrements')->willReturn($someData);
142  $this->stockItemMock->expects($this->once())->method('getQtyIncrements')->willReturn($someData);
143  $this->stockItemMock->expects($this->once())->method('getIsInStock')->willReturn($someData);
144 
145  $this->arrayManagerMock->expects($this->once())
146  ->method('set')
147  ->with('1/product/stock_data/min_qty_allowed_in_shopping_cart')
148  ->willReturnArgument(1);
149 
150  $this->assertArrayHasKey($modelId, $this->getModel()->modifyData([]));
151  }
152 
156  public function modifyDataProvider()
157  {
158  return [
159  [1, 1, 1],
160  [1, 1, '{"36000":2}', ['36000' => 2], 1, 1]
161  ];
162  }
163 }
testModifyData( $modelId, $someData, $defaultConfigValue, $unserializedValue=null, $serializeCalledNum=0, $isValidCalledNum=0)