Skip to content

Commit 8a1a68f

Browse files
committed
MAGE-1044 Test replica sync command
1 parent 49ea18a commit 8a1a68f

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

Console/Command/ReplicaSyncCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Algolia\AlgoliaSearch\Exceptions\ExceededRetriesException;
1212
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
1313
use Algolia\AlgoliaSearch\Service\StoreNameFetcher;
14-
use Magento\Framework\App\State;
14+
use Magento\Framework\App\State as AppState;
1515
use Magento\Framework\Console\Cli;
1616
use Magento\Framework\Exception\LocalizedException;
1717
use Magento\Framework\Exception\NoSuchEntityException;
@@ -27,12 +27,12 @@ public function __construct(
2727
protected ReplicaManagerInterface $replicaManager,
2828
protected ProductHelper $productHelper,
2929
protected StoreManagerInterface $storeManager,
30-
State $state,
30+
AppState $appState,
3131
StoreNameFetcher $storeNameFetcher,
3232
?string $name = null
3333
)
3434
{
35-
parent::__construct($state, $storeNameFetcher, $name);
35+
parent::__construct($appState, $storeNameFetcher, $name);
3636
}
3737

3838
protected function getReplicaCommandName(): string

Test/Integration/Product/ReplicaIndexingTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,48 @@ public function testVirtualReplicaConfig(): void
141141
$this->setConfig('algoliasearch_instant/instant/is_instant_enabled', 0);
142142
}
143143

144+
/**
145+
* @depends testReplicaSync
146+
* @magentoConfigFixture current_store algoliasearch_instant/instant/is_instant_enabled 1
147+
*/
148+
public function testReplicaRebuild(): void
149+
{
150+
$indexName = $this->getIndexName('default_');
151+
$ogAlgoliaSettings = $this->algoliaHelper->getSettings($indexName);
152+
153+
$cmd = $this->objectManager->get(\Algolia\AlgoliaSearch\Console\Command\ReplicaRebuildCommand::class);
154+
$this->assertTrue(true);
155+
}
156+
157+
/**
158+
* @magentoConfigFixture current_store algoliasearch_instant/instant/is_instant_enabled 1
159+
*/
160+
public function testReplicaSync(): void
161+
{
162+
$indexName = $this->getIndexName('default_');
163+
$ogAlgoliaSettings = $this->algoliaHelper->getSettings($indexName);
164+
$this->assertFalse(array_key_exists('replicas', $ogAlgoliaSettings));
165+
$sorting = $this->configHelper->getSorting();
166+
167+
$cmd = $this->objectManager->create(\Algolia\AlgoliaSearch\Console\Command\ReplicaSyncCommand::class);
168+
169+
$this->mockProperty($cmd, 'output', \Symfony\Component\Console\Output\OutputInterface::class);
170+
171+
$cmd->syncReplicas();
172+
173+
// $this->indicesConfigurator->saveConfigurationToAlgolia(1);
174+
// $this->algoliaHelper->waitLastTask();
175+
176+
$currentSettings = $this->algoliaHelper->getSettings($indexName);
177+
$this->assertArrayHasKey('replicas', $currentSettings);
178+
179+
$this->assertTrue(count($currentSettings['replicas']) >= count($sorting));
180+
181+
// reset
182+
$this->algoliaHelper->setSettings($indexName, $ogAlgoliaSettings);
183+
}
184+
185+
144186
/**
145187
* @param string[] $replicaSetting
146188
* @param string $replicaIndexName

Test/Integration/TestCase.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ protected function setConfigFromArray(array $settings): void
148148
}
149149
}
150150

151+
/**
152+
* @throws \ReflectionException
153+
*/
154+
protected function mockProperty($object, $propertyName, $propertyClass): void
155+
{
156+
$mock = $this->createMock($propertyClass);
157+
$reflection = new \ReflectionClass($object);
158+
$property = $reflection->getProperty($propertyName);
159+
$property->setAccessible(true);
160+
$property->setValue($object, $mock);
161+
}
162+
151163
protected function clearIndices()
152164
{
153165
$indices = $this->algoliaHelper->listIndexes();

0 commit comments

Comments
 (0)