@@ -59,10 +59,11 @@ protected function assertSortingAttribute($sortAttr, $sortDir): void
59
59
60
60
protected function assertNoSortingAttribute ($ sortAttr , $ sortDir ): void
61
61
{
62
- $ this ->assertTrue (! $ this ->hasSortingAttribute ($ sortAttr , $ sortDir ));
62
+ $ this ->assertFalse ( $ this ->hasSortingAttribute ($ sortAttr , $ sortDir ));
63
63
}
64
64
65
- public function testReplicaLimits () {
65
+ public function testReplicaLimits ()
66
+ {
66
67
$ this ->assertEquals (20 , $ this ->replicaManager ->getMaxVirtualReplicasPerIndex ());
67
68
}
68
69
@@ -85,14 +86,8 @@ public function testStandardReplicaConfig(): void
85
86
86
87
$ sortIndexName = $ indexName . '_ ' . $ sortAttr . '_ ' . $ sortDir ;
87
88
88
- $ this ->assertTrue (
89
- (bool ) array_filter (
90
- $ currentSettings ['replicas ' ],
91
- function ($ replica ) use ($ sortIndexName ) {
92
- return str_contains ($ replica , $ sortIndexName );
93
- }
94
- )
95
- );
89
+ $ this ->assertTrue ($ this ->isStandardReplica ($ currentSettings ['replicas ' ], $ sortIndexName ));
90
+ $ this ->assertFalse ($ this ->isVirtualReplica ($ currentSettings ['replicas ' ], $ sortIndexName ));
96
91
97
92
// Assert replica index created
98
93
$ replicaSettings = $ this ->algoliaHelper ->getSettings ($ sortIndexName );
@@ -111,6 +106,11 @@ function($replica) use ($sortIndexName) {
111
106
*/
112
107
public function testVirtualReplicaConfig (): void
113
108
{
109
+ $ indexName = $ this ->getIndexName ('default_ ' );
110
+ $ ogAlgoliaSettings = $ this ->algoliaHelper ->getSettings ($ indexName );
111
+
112
+ $ this ->assertFalse (array_key_exists ('replicas ' , $ ogAlgoliaSettings ));
113
+
114
114
$ productHelper = $ this ->objectManager ->get (ProductHelper::class);
115
115
$ sortAttr = 'color ' ;
116
116
$ sortDir = 'asc ' ;
@@ -121,9 +121,10 @@ public function testVirtualReplicaConfig(): void
121
121
122
122
$ sorting = $ this ->configHelper ->getSorting ();
123
123
$ sorting [] = [
124
- 'attribute ' => $ sortAttr ,
125
- 'sort ' => $ sortDir ,
126
- 'sortLabel ' => $ sortAttr
124
+ 'attribute ' => $ sortAttr ,
125
+ 'sort ' => $ sortDir ,
126
+ 'sortLabel ' => $ sortAttr ,
127
+ 'virtualReplica ' => 1
127
128
];
128
129
$ this ->configHelper ->setSorting ($ sorting );
129
130
@@ -133,6 +134,56 @@ public function testVirtualReplicaConfig(): void
133
134
134
135
$ this ->assertSortingAttribute ($ sortAttr , $ sortDir );
135
136
137
+ // Cannot use config fixture because we have disabled db isolation
138
+ $ this ->setConfig ('algoliasearch_instant/instant/is_instant_enabled ' , 1 );
139
+
140
+ $ this ->indicesConfigurator ->saveConfigurationToAlgolia (1 );
141
+ $ this ->algoliaHelper ->waitLastTask ();
142
+
143
+ // Assert replica config created
144
+ $ currentSettings = $ this ->algoliaHelper ->getSettings ($ indexName );
145
+ $ this ->assertArrayHasKey ('replicas ' , $ currentSettings );
146
+
147
+ $ sortIndexName = $ indexName . '_ ' . $ sortAttr . '_ ' . $ sortDir ;
148
+
149
+ $ this ->assertTrue ($ this ->isVirtualReplica ($ currentSettings ['replicas ' ], $ sortIndexName ));
150
+ $ this ->assertFalse ($ this ->isStandardReplica ($ currentSettings ['replicas ' ], $ sortIndexName ));
151
+
152
+ // Assert replica index created
153
+ $ replicaSettings = $ this ->algoliaHelper ->getSettings ($ sortIndexName );
154
+ $ this ->assertArrayHasKey ('primary ' , $ replicaSettings );
155
+ $ this ->assertEquals ($ indexName , $ replicaSettings ['primary ' ]);
156
+
157
+ // Restore prior state (for this test only)
158
+ $ this ->algoliaHelper ->setSettings ($ indexName , $ ogAlgoliaSettings );
159
+ $ this ->setConfig ('algoliasearch_instant/instant/is_instant_enabled ' , 0 );
160
+
161
+ }
162
+
163
+ /**
164
+ * @param string[] $replicaSetting
165
+ * @param string $replicaIndexName
166
+ * @return bool
167
+ */
168
+ protected function isVirtualReplica (array $ replicaSetting , string $ replicaIndexName ): bool
169
+ {
170
+ return (bool ) array_filter (
171
+ $ replicaSetting ,
172
+ function ($ replica ) use ($ replicaIndexName ) {
173
+ return str_contains ($ replica , "virtual( $ replicaIndexName) " );
174
+ }
175
+ );
176
+ }
177
+
178
+ protected function isStandardReplica (array $ replicaSetting , string $ replicaIndexName ): bool
179
+ {
180
+ return (bool ) array_filter (
181
+ $ replicaSetting ,
182
+ function ($ replica ) use ($ replicaIndexName ) {
183
+ $ regex = '/^ ' . preg_quote ($ replicaIndexName ) . '$/ ' ;
184
+ return preg_match ($ regex , $ replica );
185
+ }
186
+ );
136
187
}
137
188
138
189
public function tearDown (): void
0 commit comments