1212use Magento \Framework \DB \Adapter \AdapterInterface ;
1313use Magento \Framework \DB \Select ;
1414use Magento \Framework \Event \ManagerInterface ;
15+ use Magento \Framework \EntityManager \MetadataPool ;
1516use Magento \Framework \Indexer \CacheContext ;
1617use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
1718use Magento \Catalog \Model \Product ;
@@ -43,6 +44,11 @@ class CacheCleanerTest extends \PHPUnit\Framework\TestCase
4344 */
4445 private $ cacheContextMock ;
4546
47+ /**
48+ * @var MetadataPool |\PHPUnit_Framework_MockObject_MockObject
49+ */
50+ private $ metadataPoolMock ;
51+
4652 /**
4753 * @var StockConfigurationInterface|\PHPUnit_Framework_MockObject_MockObject
4854 */
@@ -61,6 +67,8 @@ protected function setUp()
6167 ->setMethods (['getStockThresholdQty ' ])->getMockForAbstractClass ();
6268 $ this ->cacheContextMock = $ this ->getMockBuilder (CacheContext::class)->disableOriginalConstructor ()->getMock ();
6369 $ this ->eventManagerMock = $ this ->getMockBuilder (ManagerInterface::class)->getMock ();
70+ $ this ->metadataPoolMock = $ this ->getMockBuilder (MetadataPool::class)
71+ ->setMethods (['getMetadata ' , 'getLinkField ' ])->disableOriginalConstructor ()->getMock ();
6472 $ this ->selectMock = $ this ->getMockBuilder (Select::class)->disableOriginalConstructor ()->getMock ();
6573
6674 $ this ->resourceMock ->expects ($ this ->any ())
@@ -73,7 +81,8 @@ protected function setUp()
7381 'resource ' => $ this ->resourceMock ,
7482 'stockConfiguration ' => $ this ->stockConfigurationMock ,
7583 'cacheContext ' => $ this ->cacheContextMock ,
76- 'eventManager ' => $ this ->eventManagerMock
84+ 'eventManager ' => $ this ->eventManagerMock ,
85+ 'metadataPool ' => $ this ->metadataPoolMock
7786 ]
7887 );
7988 }
@@ -90,6 +99,7 @@ public function testClean($stockStatusBefore, $stockStatusAfter, $qtyAfter, $sto
9099 $ productId = 123 ;
91100 $ this ->selectMock ->expects ($ this ->any ())->method ('from ' )->willReturnSelf ();
92101 $ this ->selectMock ->expects ($ this ->any ())->method ('where ' )->willReturnSelf ();
102+ $ this ->selectMock ->expects ($ this ->any ())->method ('joinLeft ' )->willReturnSelf ();
93103 $ this ->connectionMock ->expects ($ this ->exactly (2 ))->method ('select ' )->willReturn ($ this ->selectMock );
94104 $ this ->connectionMock ->expects ($ this ->exactly (2 ))->method ('fetchAll ' )->willReturnOnConsecutiveCalls (
95105 [
@@ -105,7 +115,10 @@ public function testClean($stockStatusBefore, $stockStatusAfter, $qtyAfter, $sto
105115 ->with (Product::CACHE_TAG , [$ productId ]);
106116 $ this ->eventManagerMock ->expects ($ this ->once ())->method ('dispatch ' )
107117 ->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 ' );
109122 $ callback = function () {
110123 };
111124 $ this ->unit ->clean ([], $ callback );
@@ -136,6 +149,7 @@ public function testNotCleanCache($stockStatusBefore, $stockStatusAfter, $qtyAft
136149 $ productId = 123 ;
137150 $ this ->selectMock ->expects ($ this ->any ())->method ('from ' )->willReturnSelf ();
138151 $ this ->selectMock ->expects ($ this ->any ())->method ('where ' )->willReturnSelf ();
152+ $ this ->selectMock ->expects ($ this ->any ())->method ('joinLeft ' )->willReturnSelf ();
139153 $ this ->connectionMock ->expects ($ this ->exactly (2 ))->method ('select ' )->willReturn ($ this ->selectMock );
140154 $ this ->connectionMock ->expects ($ this ->exactly (2 ))->method ('fetchAll ' )->willReturnOnConsecutiveCalls (
141155 [
@@ -149,6 +163,10 @@ public function testNotCleanCache($stockStatusBefore, $stockStatusAfter, $qtyAft
149163 ->willReturn ($ stockThresholdQty );
150164 $ this ->cacheContextMock ->expects ($ this ->never ())->method ('registerEntities ' );
151165 $ 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 ' );
152170
153171 $ callback = function () {
154172 };
0 commit comments