1616use Magento \Framework \EntityManager \EntityMetadataInterface ;
1717use Magento \Framework \EntityManager \MetadataPool ;
1818use Magento \Framework \Session \SessionManagerInterface ;
19+ use Magento \Store \Api \Data \StoreInterface ;
20+ use Magento \Store \Model \StoreManagerInterface ;
1921use PHPUnit \Framework \MockObject \MockObject ;
2022use PHPUnit \Framework \TestCase ;
2123
24+ /**
25+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26+ */
2227class SpecialPriceBulkResolverTest extends TestCase
2328{
2429 /**
@@ -37,10 +42,15 @@ class SpecialPriceBulkResolverTest extends TestCase
3742 private SpecialPriceBulkResolver $ specialPriceBulkResolver ;
3843
3944 /**
40- * @var SessionManagerInterface
45+ * @var SessionManagerInterface|MockObject
4146 */
4247 private SessionManagerInterface $ customerSession ;
4348
49+ /**
50+ * @var StoreManagerInterface|MockObject
51+ */
52+ private StoreManagerInterface $ storeManager ;
53+
4454 /**
4555 * @return void
4656 */
@@ -52,11 +62,12 @@ protected function setUp(): void
5262 ->disableOriginalConstructor ()
5363 ->addMethods (['getCustomerGroupId ' ])
5464 ->getMockForAbstractClass ();
55-
65+ $ this -> storeManager = $ this -> createMock (StoreManagerInterface::class);
5666 $ this ->specialPriceBulkResolver = new SpecialPriceBulkResolver (
5767 $ this ->resource ,
5868 $ this ->metadataPool ,
59- $ this ->customerSession
69+ $ this ->customerSession ,
70+ $ this ->storeManager
6071 );
6172 }
6273
@@ -75,9 +86,19 @@ public function testGenerateSpecialPriceMapNoCollection(): void
7586 */
7687 public function testGenerateSpecialPriceMapCollection (): void
7788 {
89+ $ storeId = 2 ;
90+ $ websiteId = 1 ;
91+ $ customerGroupId = 3 ;
7892 $ product = $ this ->createMock (Product::class);
79-
80- $ this ->customerSession ->expects ($ this ->once ())->method ('getCustomerGroupId ' )->willReturn (1 );
93+ $ store = $ this ->createMock (StoreInterface::class);
94+ $ store ->expects ($ this ->once ())->method ('getWebsiteId ' )->willReturn ($ websiteId );
95+ $ this ->storeManager ->expects ($ this ->once ())
96+ ->method ('getStore ' )
97+ ->with ($ storeId )
98+ ->willReturn ($ store );
99+ $ this ->customerSession ->expects ($ this ->once ())
100+ ->method ('getCustomerGroupId ' )
101+ ->willReturn ($ customerGroupId );
81102 $ collection = $ this ->getMockBuilder (AbstractCollection::class)
82103 ->disableOriginalConstructor ()
83104 ->onlyMethods (['getAllIds ' , 'getIterator ' ])
@@ -92,14 +113,13 @@ public function testGenerateSpecialPriceMapCollection(): void
92113 ->method ('getMetadata ' )
93114 ->with (ProductInterface::class)
94115 ->willReturn ($ metadata );
95-
96116 $ connection = $ this ->getMockBuilder (AdapterInterface::class)
97117 ->addMethods (['from ' , 'joinInner ' , 'where ' , 'columns ' , 'joinLeft ' ])
98118 ->getMockForAbstractClass ();
99119 $ connection ->expects ($ this ->once ())->method ('select ' )->willReturnSelf ();
100120 $ connection ->expects ($ this ->once ())
101121 ->method ('from ' )
102- ->with (['e ' => 'catalog_product_super_link ' ])
122+ ->with (['e ' => 'catalog_product_entity ' ])
103123 ->willReturnSelf ();
104124 $ connection ->expects ($ this ->exactly (3 ))
105125 ->method ('joinLeft ' )
@@ -130,12 +150,13 @@ public function testGenerateSpecialPriceMapCollection(): void
130150 $ this ->resource ->expects ($ this ->exactly (4 ))
131151 ->method ('getTableName ' )
132152 ->willReturnOnConsecutiveCalls (
133- 'catalog_product_super_link ' ,
134153 'catalog_product_entity ' ,
154+ 'catalog_product_super_link ' ,
135155 'catalog_product_website ' ,
136156 'catalog_product_index_price '
137157 );
138-
139- $ this ->specialPriceBulkResolver ->generateSpecialPriceMap (1 , $ collection );
158+ $ result = $ this ->specialPriceBulkResolver ->generateSpecialPriceMap ($ storeId , $ collection );
159+ $ expectedResult = [1 => true ];
160+ $ this ->assertEquals ($ expectedResult , $ result );
140161 }
141162}
0 commit comments