61 $this->stockMock = $this->getMockBuilder(\
Magento\CatalogInventory\Model\Stock::class)
62 ->disableOriginalConstructor()
65 $this->stockResourceMock = $this->getMockBuilder(\
Magento\CatalogInventory\Model\
ResourceModel\Stock::class)
66 ->disableOriginalConstructor()
68 $this->stockFactoryMock = $this->getMockBuilder(
69 \
Magento\CatalogInventory\Model\StockFactory::class
71 ->setMethods([
'create'])
72 ->disableOriginalConstructor()
74 $this->stockCollectionMock = $this->getMockBuilder(
75 \
Magento\CatalogInventory\Api\Data\StockCollectionInterfaceFactory::class
77 ->setMethods([
'create'])
78 ->disableOriginalConstructor()
81 $this->queryBuilderFactoryMock = $this->getMockBuilder(\
Magento\Framework\DB\QueryBuilderFactory::class)
82 ->setMethods([
'create'])
83 ->disableOriginalConstructor()
85 $this->mapperMock = $this->getMockBuilder(\
Magento\Framework\DB\MapperFactory::class)
86 ->disableOriginalConstructor()
88 $this->stockRegistryStorage = $this->getMockBuilder(StockRegistryStorage::class)
89 ->disableOriginalConstructor()
93 StockRepository::class,
95 'resource' => $this->stockResourceMock,
96 'stockFactory' => $this->stockFactoryMock,
97 'collectionFactory' => $this->stockCollectionMock,
98 'queryBuilderFactory' => $this->queryBuilderFactoryMock,
99 'mapperFactory' => $this->mapperMock,
100 'stockRegistryStorage' => $this->stockRegistryStorage,
107 $this->stockResourceMock->expects($this->once())
109 ->with($this->stockMock)
112 $this->assertEquals($this->stockMock, $this->model->save($this->stockMock));
120 $this->stockResourceMock->expects($this->once())
122 ->with($this->stockMock)
123 ->willThrowException(
new \Exception());
125 $this->model->save($this->stockMock);
130 $criteriaMock = $this->getMockBuilder(\
Magento\CatalogInventory\Api\StockCriteriaInterface::class)
132 $queryBuilderMock = $this->getMockBuilder(\
Magento\Framework\DB\QueryBuilder::class)
133 ->disableOriginalConstructor()
134 ->setMethods([
'setCriteria',
'setResource',
'create'])
136 $queryMock = $this->getMockBuilder(\
Magento\Framework\DB\QueryInterface::class)
138 $queryCollectionMock = $this->getMockBuilder(\
Magento\CatalogInventory\Api\Data\StockCollectionInterface::class)
141 $this->queryBuilderFactoryMock->expects($this->once())->method(
'create')->willReturn($queryBuilderMock);
142 $queryBuilderMock->expects($this->once())->method(
'setCriteria')->with($criteriaMock)->willReturnSelf();
143 $queryBuilderMock->expects($this->once())
144 ->method(
'setResource')
145 ->with($this->stockResourceMock)
147 $queryBuilderMock->expects($this->once())->method(
'create')->willReturn($queryMock);
148 $this->stockCollectionMock->expects($this->once())->method(
'create')->willReturn($queryCollectionMock);
150 $this->assertEquals($queryCollectionMock, $this->model->getList($criteriaMock));
155 $this->stockRegistryStorage->expects($this->once())->method(
'removeStock');
157 $this->stockResourceMock->expects($this->once())
159 ->with($this->stockMock)
162 $this->assertTrue($this->model->delete($this->stockMock));
170 $this->stockResourceMock->expects($this->once())
172 ->with($this->stockMock)
173 ->willThrowException(
new \Exception());
175 $this->model->delete($this->stockMock);
182 $this->stockFactoryMock->expects($this->once())->method(
'create')->willReturn($this->stockMock);
183 $this->stockResourceMock->expects($this->once())->method(
'load')->with($this->stockMock,
$id);
184 $this->stockMock->expects($this->once())->method(
'getId')->willReturn(
$id);
186 $this->assertTrue($this->model->deleteById(
$id));
197 $this->stockFactoryMock->expects($this->once())->method(
'create')->willReturn($this->stockMock);
198 $this->stockResourceMock->expects($this->once())->method(
'load')->with($this->stockMock,
$id);
199 $this->stockMock->expects($this->once())->method(
'getId')->willReturn(
null);
201 $this->assertTrue($this->model->deleteById(
$id));
testDeleteByIdException()