3
3
namespace Algolia \AlgoliaSearch \Test \Integration \Product ;
4
4
5
5
use Algolia \AlgoliaSearch \Api \Product \ReplicaManagerInterface ;
6
+ use Algolia \AlgoliaSearch \Exceptions \AlgoliaException ;
7
+ use Algolia \AlgoliaSearch \Exceptions \ExceededRetriesException ;
6
8
use Algolia \AlgoliaSearch \Helper \ConfigHelper ;
7
9
use Algolia \AlgoliaSearch \Helper \Entity \ProductHelper ;
8
10
use Algolia \AlgoliaSearch \Model \Indexer \Product as ProductIndexer ;
@@ -158,17 +160,43 @@ protected function mockSortUpdate(string $sortAttr, string $sortDir, array $attr
158
160
/**
159
161
* @depends testReplicaSync
160
162
* @magentoConfigFixture current_store algoliasearch_instant/instant/is_instant_enabled 1
163
+ * @throws AlgoliaException
164
+ * @throws ExceededRetriesException
165
+ * @throws \ReflectionException
161
166
*/
162
167
public function testReplicaRebuild (): void
163
168
{
164
169
$ indexName = $ this ->getIndexName ('default_ ' );
165
170
166
- $ cmd = $ this ->objectManager ->get (\Algolia \AlgoliaSearch \Console \Command \ReplicaRebuildCommand::class);
167
- $ this ->assertTrue (true );
171
+ $ this ->mockSortUpdate ('price ' , 'desc ' , ['virtualReplica ' => 1 ]);
172
+ $ sorting = $ this ->objectManager ->get (\Algolia \AlgoliaSearch \Service \Product \SortingTransformer::class)->getSortingIndices (1 , null , null , true );
173
+
174
+ $ syncCmd = $ this ->objectManager ->get (\Algolia \AlgoliaSearch \Console \Command \ReplicaSyncCommand::class);
175
+ $ this ->mockProperty ($ syncCmd , 'output ' , \Symfony \Component \Console \Output \OutputInterface::class);
176
+ $ syncCmd ->syncReplicas ();
177
+ $ this ->algoliaHelper ->waitLastTask ();
178
+
179
+ $ rebuildCmd = $ this ->objectManager ->get (\Algolia \AlgoliaSearch \Console \Command \ReplicaRebuildCommand::class);
180
+ $ this ->callReflectedMethod (
181
+ $ rebuildCmd ,
182
+ 'execute ' ,
183
+ $ this ->createMock (\Symfony \Component \Console \Input \InputInterface::class),
184
+ $ this ->createMock (\Symfony \Component \Console \Output \OutputInterface::class)
185
+ );
186
+ $ this ->algoliaHelper ->waitLastTask ();
187
+
188
+ $ currentSettings = $ this ->algoliaHelper ->getSettings ($ indexName );
189
+ $ this ->assertArrayHasKey ('replicas ' , $ currentSettings );
190
+ $ replicas = $ currentSettings ['replicas ' ];
191
+
192
+ $ this ->assertEquals (count ($ sorting ), count ($ replicas ));
193
+ $ this ->assertSortToReplicaConfigParity ($ indexName , $ sorting , $ replicas );
168
194
}
169
195
170
196
/**
171
197
* @magentoConfigFixture current_store algoliasearch_instant/instant/is_instant_enabled 1
198
+ * @throws AlgoliaException
199
+ * @throws ExceededRetriesException
172
200
* @throws \ReflectionException
173
201
*/
174
202
public function testReplicaSync (): void
@@ -179,7 +207,7 @@ public function testReplicaSync(): void
179
207
180
208
$ sorting = $ this ->objectManager ->get (\Algolia \AlgoliaSearch \Service \Product \SortingTransformer::class)->getSortingIndices (1 , null , null , true );
181
209
182
- $ cmd = $ this ->objectManager ->create (\Algolia \AlgoliaSearch \Console \Command \ReplicaSyncCommand::class);
210
+ $ cmd = $ this ->objectManager ->get (\Algolia \AlgoliaSearch \Console \Command \ReplicaSyncCommand::class);
183
211
184
212
$ this ->mockProperty ($ cmd , 'output ' , \Symfony \Component \Console \Output \OutputInterface::class);
185
213
0 commit comments