@@ -43,7 +43,7 @@ class FilterScopeTest extends AbstractFiltersTest
43
43
protected function setUp ()
44
44
{
45
45
parent ::setUp ();
46
- $ this ->storeManager = $ this ->objectManager ->create (StoreManagerInterface::class);
46
+ $ this ->storeManager = $ this ->objectManager ->get (StoreManagerInterface::class);
47
47
$ this ->oldStoreId = (int )$ this ->storeManager ->getStore ()->getId ();
48
48
$ this ->currentStoreId = (int )$ this ->storeManager ->getStore ('fixture_second_store ' )->getId ();
49
49
}
@@ -67,15 +67,18 @@ public function testGetFilters(int $scope, array $products, array $expectation):
67
67
);
68
68
$ this ->updateProductsOnStore ($ products );
69
69
$ this ->clearInstanceAndReindexSearch ();
70
- $ this ->storeManager ->setCurrentStore ($ this ->currentStoreId );
71
- $ this ->navigationBlock ->getLayer ()->setCurrentCategory (
72
- $ this ->loadCategory ('Category 999 ' , $ this ->currentStoreId )
73
- );
74
- $ this ->navigationBlock ->setLayout ($ this ->layout );
75
- $ filter = $ this ->getFilterByCode ($ this ->navigationBlock ->getFilters (), $ this ->getAttributeCode ());
76
- $ this ->assertNotNull ($ filter );
77
- $ this ->assertEquals ($ expectation , $ this ->prepareFilterItems ($ filter ));
78
- $ this ->storeManager ->setCurrentStore ($ this ->oldStoreId );
70
+ try {
71
+ $ this ->storeManager ->setCurrentStore ($ this ->currentStoreId );
72
+ $ this ->navigationBlock ->getLayer ()->setCurrentCategory (
73
+ $ this ->loadCategory ('Category 999 ' , $ this ->currentStoreId )
74
+ );
75
+ $ this ->navigationBlock ->setLayout ($ this ->layout );
76
+ $ filter = $ this ->getFilterByCode ($ this ->navigationBlock ->getFilters (), $ this ->getAttributeCode ());
77
+ $ this ->assertNotNull ($ filter );
78
+ $ this ->assertEquals ($ expectation , $ this ->prepareFilterItems ($ filter ));
79
+ } finally {
80
+ $ this ->storeManager ->setCurrentStore ($ this ->oldStoreId );
81
+ }
79
82
}
80
83
81
84
/**
@@ -144,11 +147,14 @@ protected function getAttributeCode(): string
144
147
*/
145
148
private function updateProductsOnStore (array $ productsData ): void
146
149
{
147
- foreach ($ productsData as $ storeCode => $ products ) {
148
- $ storeId = (int )$ this ->storeManager ->getStore ($ storeCode )->getId ();
149
- $ this ->storeManager ->setCurrentStore ($ storeId );
150
- $ this ->updateProducts ($ products , $ this ->getAttributeCode (), $ storeId );
150
+ try {
151
+ foreach ($ productsData as $ storeCode => $ products ) {
152
+ $ storeId = (int )$ this ->storeManager ->getStore ($ storeCode )->getId ();
153
+ $ this ->storeManager ->setCurrentStore ($ storeId );
154
+ $ this ->updateProducts ($ products , $ this ->getAttributeCode (), $ storeId );
155
+ }
156
+ } finally {
157
+ $ this ->storeManager ->setCurrentStore ($ this ->oldStoreId );
151
158
}
152
- $ this ->storeManager ->setCurrentStore ($ this ->oldStoreId );
153
159
}
154
160
}
0 commit comments