Skip to content

Commit

Permalink
MAGE-1044 Test replica sync command
Browse files Browse the repository at this point in the history
  • Loading branch information
cammonro committed Oct 7, 2024
1 parent 49ea18a commit 8a1a68f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Console/Command/ReplicaSyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Algolia\AlgoliaSearch\Exceptions\ExceededRetriesException;
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
use Algolia\AlgoliaSearch\Service\StoreNameFetcher;
use Magento\Framework\App\State;
use Magento\Framework\App\State as AppState;
use Magento\Framework\Console\Cli;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
Expand All @@ -27,12 +27,12 @@ public function __construct(
protected ReplicaManagerInterface $replicaManager,
protected ProductHelper $productHelper,
protected StoreManagerInterface $storeManager,
State $state,
AppState $appState,
StoreNameFetcher $storeNameFetcher,
?string $name = null
)
{
parent::__construct($state, $storeNameFetcher, $name);
parent::__construct($appState, $storeNameFetcher, $name);
}

protected function getReplicaCommandName(): string
Expand Down
42 changes: 42 additions & 0 deletions Test/Integration/Product/ReplicaIndexingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,48 @@ public function testVirtualReplicaConfig(): void
$this->setConfig('algoliasearch_instant/instant/is_instant_enabled', 0);
}

/**
* @depends testReplicaSync
* @magentoConfigFixture current_store algoliasearch_instant/instant/is_instant_enabled 1
*/
public function testReplicaRebuild(): void
{
$indexName = $this->getIndexName('default_');
$ogAlgoliaSettings = $this->algoliaHelper->getSettings($indexName);

$cmd = $this->objectManager->get(\Algolia\AlgoliaSearch\Console\Command\ReplicaRebuildCommand::class);
$this->assertTrue(true);
}

/**
* @magentoConfigFixture current_store algoliasearch_instant/instant/is_instant_enabled 1
*/
public function testReplicaSync(): void
{
$indexName = $this->getIndexName('default_');
$ogAlgoliaSettings = $this->algoliaHelper->getSettings($indexName);
$this->assertFalse(array_key_exists('replicas', $ogAlgoliaSettings));
$sorting = $this->configHelper->getSorting();

$cmd = $this->objectManager->create(\Algolia\AlgoliaSearch\Console\Command\ReplicaSyncCommand::class);

$this->mockProperty($cmd, 'output', \Symfony\Component\Console\Output\OutputInterface::class);

$cmd->syncReplicas();

// $this->indicesConfigurator->saveConfigurationToAlgolia(1);
// $this->algoliaHelper->waitLastTask();

$currentSettings = $this->algoliaHelper->getSettings($indexName);
$this->assertArrayHasKey('replicas', $currentSettings);

$this->assertTrue(count($currentSettings['replicas']) >= count($sorting));

// reset
$this->algoliaHelper->setSettings($indexName, $ogAlgoliaSettings);
}


/**
* @param string[] $replicaSetting
* @param string $replicaIndexName
Expand Down
12 changes: 12 additions & 0 deletions Test/Integration/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ protected function setConfigFromArray(array $settings): void
}
}

/**
* @throws \ReflectionException
*/
protected function mockProperty($object, $propertyName, $propertyClass): void
{
$mock = $this->createMock($propertyClass);
$reflection = new \ReflectionClass($object);
$property = $reflection->getProperty($propertyName);
$property->setAccessible(true);
$property->setValue($object, $mock);
}

protected function clearIndices()
{
$indices = $this->algoliaHelper->listIndexes();
Expand Down

0 comments on commit 8a1a68f

Please sign in to comment.