12
12
use Magento \Framework \DB \Adapter \AdapterInterface ;
13
13
use Magento \Framework \DB \Select ;
14
14
use Magento \Framework \Event \ManagerInterface ;
15
+ use Magento \Framework \EntityManager \MetadataPool ;
15
16
use Magento \Framework \Indexer \CacheContext ;
16
17
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
17
18
use Magento \Catalog \Model \Product ;
@@ -43,6 +44,11 @@ class CacheCleanerTest extends \PHPUnit\Framework\TestCase
43
44
*/
44
45
private $ cacheContextMock ;
45
46
47
+ /**
48
+ * @var MetadataPool |\PHPUnit_Framework_MockObject_MockObject
49
+ */
50
+ private $ metadataPoolMock ;
51
+
46
52
/**
47
53
* @var StockConfigurationInterface|\PHPUnit_Framework_MockObject_MockObject
48
54
*/
@@ -61,6 +67,8 @@ protected function setUp()
61
67
->setMethods (['getStockThresholdQty ' ])->getMockForAbstractClass ();
62
68
$ this ->cacheContextMock = $ this ->getMockBuilder (CacheContext::class)->disableOriginalConstructor ()->getMock ();
63
69
$ this ->eventManagerMock = $ this ->getMockBuilder (ManagerInterface::class)->getMock ();
70
+ $ this ->metadataPoolMock = $ this ->getMockBuilder (MetadataPool::class)
71
+ ->setMethods (['getMetadata ' , 'getLinkField ' ])->disableOriginalConstructor ()->getMock ();
64
72
$ this ->selectMock = $ this ->getMockBuilder (Select::class)->disableOriginalConstructor ()->getMock ();
65
73
66
74
$ this ->resourceMock ->expects ($ this ->any ())
@@ -73,7 +81,8 @@ protected function setUp()
73
81
'resource ' => $ this ->resourceMock ,
74
82
'stockConfiguration ' => $ this ->stockConfigurationMock ,
75
83
'cacheContext ' => $ this ->cacheContextMock ,
76
- 'eventManager ' => $ this ->eventManagerMock
84
+ 'eventManager ' => $ this ->eventManagerMock ,
85
+ 'metadataPool ' => $ this ->metadataPoolMock
77
86
]
78
87
);
79
88
}
@@ -90,6 +99,7 @@ public function testClean($stockStatusBefore, $stockStatusAfter, $qtyAfter, $sto
90
99
$ productId = 123 ;
91
100
$ this ->selectMock ->expects ($ this ->any ())->method ('from ' )->willReturnSelf ();
92
101
$ this ->selectMock ->expects ($ this ->any ())->method ('where ' )->willReturnSelf ();
102
+ $ this ->selectMock ->expects ($ this ->any ())->method ('joinLeft ' )->willReturnSelf ();
93
103
$ this ->connectionMock ->expects ($ this ->exactly (2 ))->method ('select ' )->willReturn ($ this ->selectMock );
94
104
$ this ->connectionMock ->expects ($ this ->exactly (2 ))->method ('fetchAll ' )->willReturnOnConsecutiveCalls (
95
105
[
@@ -105,7 +115,10 @@ public function testClean($stockStatusBefore, $stockStatusAfter, $qtyAfter, $sto
105
115
->with (Product::CACHE_TAG , [$ productId ]);
106
116
$ this ->eventManagerMock ->expects ($ this ->once ())->method ('dispatch ' )
107
117
->with ('clean_cache_by_tags ' , ['object ' => $ this ->cacheContextMock ]);
108
-
118
+ $ this ->metadataPoolMock ->expects ($ this ->exactly (2 ))->method ('getMetadata ' )
119
+ ->willReturnSelf ();
120
+ $ this ->metadataPoolMock ->expects ($ this ->exactly (2 ))->method ('getLinkField ' )
121
+ ->willReturn ('row_id ' );
109
122
$ callback = function () {
110
123
};
111
124
$ this ->unit ->clean ([], $ callback );
@@ -136,6 +149,7 @@ public function testNotCleanCache($stockStatusBefore, $stockStatusAfter, $qtyAft
136
149
$ productId = 123 ;
137
150
$ this ->selectMock ->expects ($ this ->any ())->method ('from ' )->willReturnSelf ();
138
151
$ this ->selectMock ->expects ($ this ->any ())->method ('where ' )->willReturnSelf ();
152
+ $ this ->selectMock ->expects ($ this ->any ())->method ('joinLeft ' )->willReturnSelf ();
139
153
$ this ->connectionMock ->expects ($ this ->exactly (2 ))->method ('select ' )->willReturn ($ this ->selectMock );
140
154
$ this ->connectionMock ->expects ($ this ->exactly (2 ))->method ('fetchAll ' )->willReturnOnConsecutiveCalls (
141
155
[
@@ -149,6 +163,10 @@ public function testNotCleanCache($stockStatusBefore, $stockStatusAfter, $qtyAft
149
163
->willReturn ($ stockThresholdQty );
150
164
$ this ->cacheContextMock ->expects ($ this ->never ())->method ('registerEntities ' );
151
165
$ this ->eventManagerMock ->expects ($ this ->never ())->method ('dispatch ' );
166
+ $ this ->metadataPoolMock ->expects ($ this ->exactly (2 ))->method ('getMetadata ' )
167
+ ->willReturnSelf ();
168
+ $ this ->metadataPoolMock ->expects ($ this ->exactly (2 ))->method ('getLinkField ' )
169
+ ->willReturn ('row_id ' );
152
170
153
171
$ callback = function () {
154
172
};
0 commit comments