@@ -65,7 +65,7 @@ public function testStandardReplicaConfig(): void
65
65
$ this ->assertFalse ($ this ->isVirtualReplica ($ currentSettings ['replicas ' ], $ sortIndexName ));
66
66
67
67
$ replicaSettings = $ this ->assertReplicaIndexExists ($ indexName , $ sortIndexName );
68
- $ this ->assertStandardReplicaRanking ($ replicaSettings , $ sortAttr , $ sortDir );
68
+ $ this ->assertStandardReplicaRanking ($ replicaSettings , " $ sortDir( $ sortAttr ) " );
69
69
}
70
70
71
71
/**
@@ -119,7 +119,7 @@ public function testVirtualReplicaConfig(): void
119
119
120
120
// Assert replica index created
121
121
$ replicaSettings = $ this ->assertReplicaIndexExists ($ indexName , $ sortIndexName );
122
- $ this ->assertVirtualReplicaRanking ($ replicaSettings , $ sortAttr , $ sortDir );
122
+ $ this ->assertVirtualReplicaRanking ($ replicaSettings , " $ sortDir( $ sortAttr ) " );
123
123
124
124
// Restore prior state (for this test only)
125
125
$ this ->configHelper ->setSorting ($ ogSortingState );
@@ -184,26 +184,33 @@ public function testReplicaSync(): void
184
184
$ this ->mockProperty ($ cmd , 'output ' , \Symfony \Component \Console \Output \OutputInterface::class);
185
185
186
186
$ cmd ->syncReplicas ();
187
+ $ this ->algoliaHelper ->waitLastTask ();
187
188
188
189
$ currentSettings = $ this ->algoliaHelper ->getSettings ($ indexName );
189
190
$ this ->assertArrayHasKey ('replicas ' , $ currentSettings );
190
191
$ replicas = $ currentSettings ['replicas ' ];
191
192
192
193
$ this ->assertEquals (count ($ sorting ), count ($ replicas ));
193
- $ this ->assertSortToReplicaConfigParity ($ sorting , $ replicas );
194
-
195
- // TODO: Test ranking
196
-
194
+ $ this ->assertSortToReplicaConfigParity ($ indexName , $ sorting , $ replicas );
197
195
}
198
196
199
- protected function assertSortToReplicaConfigParity (array $ sorting , array $ replicas ): void
197
+ protected function assertSortToReplicaConfigParity (string $ primaryIndexName , array $ sorting , array $ replicas ): void
200
198
{
201
199
foreach ($ sorting as $ sortAttr ) {
202
200
$ replicaIndexName = $ sortAttr ['name ' ];
203
- $ needle = array_key_exists ('virtualReplica ' , $ sortAttr ) && $ sortAttr ['virtualReplica ' ]
201
+ $ isVirtual = array_key_exists ('virtualReplica ' , $ sortAttr ) && $ sortAttr ['virtualReplica ' ];
202
+ $ needle = $ isVirtual
204
203
? "virtual( $ replicaIndexName) "
205
204
: $ replicaIndexName ;
206
205
$ this ->assertContains ($ needle , $ replicas );
206
+
207
+ $ replicaSettings = $ this ->assertReplicaIndexExists ($ primaryIndexName , $ replicaIndexName );
208
+ $ sort = reset ($ sortAttr ['ranking ' ]);
209
+ if ($ isVirtual ) {
210
+ $ this ->assertVirtualReplicaRanking ($ replicaSettings , $ sort );
211
+ } else {
212
+ $ this ->assertStandardReplicaRanking ($ replicaSettings , $ sort );
213
+ }
207
214
}
208
215
}
209
216
@@ -215,13 +222,28 @@ protected function assertReplicaIndexExists(string $primaryIndexName, string $re
215
222
return $ replicaSettings ;
216
223
}
217
224
218
- protected function assertStandardReplicaRanking (array $ replicaSettings , string $ sortAttr , string $ sortDir ): void
225
+ protected function assertReplicaRanking (array $ replicaSettings , string $ rankingKey , string $ sort ) {
226
+ $ this ->assertArrayHasKey ($ rankingKey , $ replicaSettings );
227
+ $ this ->assertEquals ($ sort , reset ($ replicaSettings [$ rankingKey ]));
228
+ }
229
+
230
+ protected function assertStandardReplicaRanking (array $ replicaSettings , string $ sort ): void
231
+ {
232
+ $ this ->assertReplicaRanking ($ replicaSettings , 'ranking ' , $ sort );
233
+ }
234
+
235
+ protected function assertVirtualReplicaRanking (array $ replicaSettings , string $ sort ): void
236
+ {
237
+ $ this ->assertReplicaRanking ($ replicaSettings , 'customRanking ' , $ sort );
238
+ }
239
+
240
+ protected function assertStandardReplicaRankingOld (array $ replicaSettings , string $ sortAttr , string $ sortDir ): void
219
241
{
220
242
$ this ->assertArrayHasKey ('ranking ' , $ replicaSettings );
221
243
$ this ->assertEquals ("$ sortDir( $ sortAttr) " , array_shift ($ replicaSettings ['ranking ' ]));
222
244
}
223
245
224
- protected function assertVirtualReplicaRanking (array $ replicaSettings , string $ sortAttr , string $ sortDir ): void
246
+ protected function assertVirtualReplicaRankingOld (array $ replicaSettings , string $ sortAttr , string $ sortDir ): void
225
247
{
226
248
$ this ->assertArrayHasKey ('customRanking ' , $ replicaSettings );
227
249
$ this ->assertEquals ("$ sortDir( $ sortAttr) " , array_shift ($ replicaSettings ['customRanking ' ]));
0 commit comments