29 private $resourceMock;
34 private $connectionMock;
39 private $eventManagerMock;
44 private $cacheContextMock;
49 private $stockConfigurationMock;
58 $this->resourceMock = $this->getMockBuilder(ResourceConnection::class)->disableOriginalConstructor()->getMock();
59 $this->connectionMock = $this->getMockBuilder(AdapterInterface::class)->getMock();
60 $this->stockConfigurationMock = $this->getMockBuilder(StockConfigurationInterface::class)
61 ->setMethods([
'getStockThresholdQty'])->getMockForAbstractClass();
62 $this->cacheContextMock = $this->getMockBuilder(CacheContext::class)->disableOriginalConstructor()->getMock();
63 $this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)->getMock();
64 $this->selectMock = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock();
66 $this->resourceMock->expects($this->any())
67 ->method(
'getConnection')
68 ->will($this->returnValue($this->connectionMock));
73 'resource' => $this->resourceMock,
74 'stockConfiguration' => $this->stockConfigurationMock,
75 'cacheContext' => $this->cacheContextMock,
76 'eventManager' => $this->eventManagerMock
88 public function testClean($stockStatusBefore, $stockStatusAfter, $qtyAfter, $stockThresholdQty)
91 $this->selectMock->expects($this->any())->method(
'from')->willReturnSelf();
92 $this->selectMock->expects($this->any())->method(
'where')->willReturnSelf();
93 $this->connectionMock->expects($this->exactly(2))->method(
'select')->willReturn($this->selectMock);
94 $this->connectionMock->expects($this->exactly(2))->method(
'fetchAll')->willReturnOnConsecutiveCalls(
96 [
'product_id' =>
$productId,
'stock_status' => $stockStatusBefore],
99 [
'product_id' =>
$productId,
'stock_status' => $stockStatusAfter,
'qty' => $qtyAfter],
102 $this->stockConfigurationMock->expects($this->once())->method(
'getStockThresholdQty')
103 ->willReturn($stockThresholdQty);
104 $this->cacheContextMock->expects($this->once())->method(
'registerEntities')
106 $this->eventManagerMock->expects($this->once())->method(
'dispatch')
107 ->with(
'clean_cache_by_tags', [
'object' => $this->cacheContextMock]);
109 $callback =
function () {
111 $this->unit->clean([], $callback);
120 [
true,
false, 1,
false],
121 [
false,
true, 1,
false],
123 [
false,
false, 1, 2],
134 public function testNotCleanCache($stockStatusBefore, $stockStatusAfter, $qtyAfter, $stockThresholdQty)
137 $this->selectMock->expects($this->any())->method(
'from')->willReturnSelf();
138 $this->selectMock->expects($this->any())->method(
'where')->willReturnSelf();
139 $this->connectionMock->expects($this->exactly(2))->method(
'select')->willReturn($this->selectMock);
140 $this->connectionMock->expects($this->exactly(2))->method(
'fetchAll')->willReturnOnConsecutiveCalls(
142 [
'product_id' =>
$productId,
'stock_status' => $stockStatusBefore],
145 [
'product_id' =>
$productId,
'stock_status' => $stockStatusAfter,
'qty' => $qtyAfter],
148 $this->stockConfigurationMock->expects($this->once())->method(
'getStockThresholdQty')
149 ->willReturn($stockThresholdQty);
150 $this->cacheContextMock->expects($this->never())->method(
'registerEntities');
151 $this->eventManagerMock->expects($this->never())->method(
'dispatch');
153 $callback =
function () {
155 $this->unit->clean([], $callback);
164 [
true,
true, 1,
false],
165 [
false,
false, 1,
false],
testNotCleanCache($stockStatusBefore, $stockStatusAfter, $qtyAfter, $stockThresholdQty)
testClean($stockStatusBefore, $stockStatusAfter, $qtyAfter, $stockThresholdQty)
notCleanCacheDataProvider()