Skip to content

Commit 49ea18a

Browse files
committed
MAGE-1044 Localize setup/teardown for virtual replica test case
1 parent c53e32b commit 49ea18a

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

Test/Integration/Product/ReplicaIndexingTest.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@ class ReplicaIndexingTest extends IndexingTestCase
1717

1818
protected ?string $indexSuffix = null;
1919

20-
protected ?array $ogSortingState = null;
21-
2220
public function setUp(): void
2321
{
2422
parent::setUp();
2523
$this->productIndexer = $this->objectManager->get(ProductIndexer::class);
2624
$this->replicaManager = $this->objectManager->get(ReplicaManagerInterface::class);
2725
$this->indicesConfigurator = $this->objectManager->get(IndicesConfigurator::class);
2826
$this->indexSuffix = 'products';
29-
30-
$this->ogSortingState = $this->configHelper->getSorting();
3127
}
3228

3329
protected function getIndexName(string $storeIndexPart): string
@@ -40,28 +36,6 @@ public function processFullReindexProducts(): void
4036
$this->processFullReindex($this->productIndexer, $this->indexSuffix);
4137
}
4238

43-
protected function hasSortingAttribute($sortAttr, $sortDir): bool
44-
{
45-
$sorting = $this->configHelper->getSorting();
46-
return (bool) array_filter(
47-
$sorting,
48-
function($sort) use ($sortAttr, $sortDir) {
49-
return $sort['attribute'] == $sortAttr
50-
&& $sort['sort'] == $sortDir;
51-
}
52-
);
53-
}
54-
55-
protected function assertSortingAttribute($sortAttr, $sortDir): void
56-
{
57-
$this->assertTrue($this->hasSortingAttribute($sortAttr, $sortDir));
58-
}
59-
60-
protected function assertNoSortingAttribute($sortAttr, $sortDir): void
61-
{
62-
$this->assertFalse($this->hasSortingAttribute($sortAttr, $sortDir));
63-
}
64-
6539
public function testReplicaLimits()
6640
{
6741
$this->assertEquals(20, $this->replicaManager->getMaxVirtualReplicasPerIndex());
@@ -101,13 +75,16 @@ public function testStandardReplicaConfig(): void
10175
}
10276

10377
/**
78+
* This test involves verifying modifications in the database
79+
* so it must be responsible for its own set up and tear down
10480
* @magentoDbIsolation disabled
10581
* @group virtual
10682
*/
10783
public function testVirtualReplicaConfig(): void
10884
{
10985
$indexName = $this->getIndexName('default_');
11086
$ogAlgoliaSettings = $this->algoliaHelper->getSettings($indexName);
87+
$ogSortingState = $this->configHelper->getSorting();
11188

11289
$this->assertFalse(array_key_exists('replicas', $ogAlgoliaSettings));
11390

@@ -160,8 +137,8 @@ public function testVirtualReplicaConfig(): void
160137

161138
// Restore prior state (for this test only)
162139
$this->algoliaHelper->setSettings($indexName, $ogAlgoliaSettings);
140+
$this->configHelper->setSorting($ogSortingState);
163141
$this->setConfig('algoliasearch_instant/instant/is_instant_enabled', 0);
164-
165142
}
166143

167144
/**
@@ -190,8 +167,31 @@ function ($replica) use ($replicaIndexName) {
190167
);
191168
}
192169

170+
protected function hasSortingAttribute($sortAttr, $sortDir): bool
171+
{
172+
$sorting = $this->configHelper->getSorting();
173+
return (bool) array_filter(
174+
$sorting,
175+
function($sort) use ($sortAttr, $sortDir) {
176+
return $sort['attribute'] == $sortAttr
177+
&& $sort['sort'] == $sortDir;
178+
}
179+
);
180+
}
181+
182+
protected function assertSortingAttribute($sortAttr, $sortDir): void
183+
{
184+
$this->assertTrue($this->hasSortingAttribute($sortAttr, $sortDir));
185+
}
186+
187+
protected function assertNoSortingAttribute($sortAttr, $sortDir): void
188+
{
189+
$this->assertFalse($this->hasSortingAttribute($sortAttr, $sortDir));
190+
}
191+
193192
public function tearDown(): void
194193
{
195-
$this->configHelper->setSorting($this->ogSortingState);
194+
parent::tearDown();
196195
}
196+
197197
}

0 commit comments

Comments
 (0)