@@ -64,15 +64,8 @@ public function testStandardReplicaConfig(): void
64
64
$ this ->assertTrue ($ this ->isStandardReplica ($ currentSettings ['replicas ' ], $ sortIndexName ));
65
65
$ this ->assertFalse ($ this ->isVirtualReplica ($ currentSettings ['replicas ' ], $ sortIndexName ));
66
66
67
- // Assert replica index created
68
- $ replicaSettings = $ this ->algoliaHelper ->getSettings ($ sortIndexName );
69
- $ this ->assertArrayHasKey ('primary ' , $ replicaSettings );
70
- $ this ->assertEquals ($ indexName , $ replicaSettings ['primary ' ]);
71
-
72
- // Assert standard replica ranking config
73
- $ this ->assertArrayHasKey ('ranking ' , $ replicaSettings );
74
- $ this ->assertEquals ("$ sortDir( $ sortAttr) " , array_shift ($ replicaSettings ['ranking ' ]));
75
-
67
+ $ replicaSettings = $ this ->assertReplicaIndexExists ($ indexName , $ sortIndexName );
68
+ $ this ->assertStandardReplicaRanking ($ replicaSettings , $ sortAttr , $ sortDir );
76
69
}
77
70
78
71
/**
@@ -125,13 +118,8 @@ public function testVirtualReplicaConfig(): void
125
118
$ this ->assertFalse ($ this ->isStandardReplica ($ currentSettings ['replicas ' ], $ sortIndexName ));
126
119
127
120
// Assert replica index created
128
- $ replicaSettings = $ this ->algoliaHelper ->getSettings ($ sortIndexName );
129
- $ this ->assertArrayHasKey ('primary ' , $ replicaSettings );
130
- $ this ->assertEquals ($ indexName , $ replicaSettings ['primary ' ]);
131
-
132
- // Assert virtual replica ranking config
133
- $ this ->assertArrayHasKey ('customRanking ' , $ replicaSettings );
134
- $ this ->assertEquals ("$ sortDir( $ sortAttr) " , array_shift ($ replicaSettings ['customRanking ' ]));
121
+ $ replicaSettings = $ this ->assertReplicaIndexExists ($ indexName , $ sortIndexName );
122
+ $ this ->assertVirtualReplicaRanking ($ replicaSettings , $ sortAttr , $ sortDir );
135
123
136
124
// Restore prior state (for this test only)
137
125
$ this ->configHelper ->setSorting ($ ogSortingState );
@@ -202,17 +190,42 @@ public function testReplicaSync(): void
202
190
$ replicas = $ currentSettings ['replicas ' ];
203
191
204
192
$ this ->assertEquals (count ($ sorting ), count ($ replicas ));
193
+ $ this ->assertSortToReplicaConfigParity ($ sorting , $ replicas );
194
+
195
+ // TODO: Test ranking
196
+
197
+ }
205
198
199
+ protected function assertSortToReplicaConfigParity (array $ sorting , array $ replicas ): void
200
+ {
206
201
foreach ($ sorting as $ sortAttr ) {
207
202
$ replicaIndexName = $ sortAttr ['name ' ];
208
203
$ needle = array_key_exists ('virtualReplica ' , $ sortAttr ) && $ sortAttr ['virtualReplica ' ]
209
204
? "virtual( $ replicaIndexName) "
210
205
: $ replicaIndexName ;
211
206
$ this ->assertContains ($ needle , $ replicas );
212
207
}
208
+ }
213
209
210
+ protected function assertReplicaIndexExists (string $ primaryIndexName , string $ replicaIndexName ): array
211
+ {
212
+ $ replicaSettings = $ this ->algoliaHelper ->getSettings ($ replicaIndexName );
213
+ $ this ->assertArrayHasKey ('primary ' , $ replicaSettings );
214
+ $ this ->assertEquals ($ primaryIndexName , $ replicaSettings ['primary ' ]);
215
+ return $ replicaSettings ;
214
216
}
215
217
218
+ protected function assertStandardReplicaRanking (array $ replicaSettings , string $ sortAttr , string $ sortDir ): void
219
+ {
220
+ $ this ->assertArrayHasKey ('ranking ' , $ replicaSettings );
221
+ $ this ->assertEquals ("$ sortDir( $ sortAttr) " , array_shift ($ replicaSettings ['ranking ' ]));
222
+ }
223
+
224
+ protected function assertVirtualReplicaRanking (array $ replicaSettings , string $ sortAttr , string $ sortDir ): void
225
+ {
226
+ $ this ->assertArrayHasKey ('customRanking ' , $ replicaSettings );
227
+ $ this ->assertEquals ("$ sortDir( $ sortAttr) " , array_shift ($ replicaSettings ['customRanking ' ]));
228
+ }
216
229
217
230
/**
218
231
* @param string[] $replicaSetting
0 commit comments