@@ -106,10 +106,33 @@ public function testMultipleSearchQueryDepthBuilder()
106
106
* ie when the queryBuilder calls itself once for every search terms of the provided array.
107
107
*/
108
108
$ thesaurusIndex ->method ('getQueryRewrites ' )->willReturn ([]);
109
+ /*
110
+ * withConsecutive removed in PHPUnit 10 without any alternative \o/.
109
111
$thesaurusIndex->expects($this->exactly(2))->method('getQueryRewrites')->withConsecutive(
110
112
[$containerConfig, 'foo', 1],
111
113
[$containerConfig, 'bar', 1],
112
114
);
115
+ */
116
+ $ invokeCount = $ this ->exactly (2 );
117
+ $ numberOfInvocationsCallback = 'numberOfInvocations ' ;
118
+ if (method_exists ($ invokeCount , 'getInvocationCount ' )) {
119
+ // Method 'numberOfInvocations' only exists starting from PHPUnit 10.
120
+ $ numberOfInvocationsCallback = 'getInvocationCount ' ;
121
+ }
122
+ $ thesaurusIndex ->expects ($ invokeCount )->method ('getQueryRewrites ' )->willReturnCallback (
123
+ function (...$ expectedInputParameters ) use ($ invokeCount , $ containerConfig , $ numberOfInvocationsCallback ) {
124
+ if ($ invokeCount ->$ numberOfInvocationsCallback () === 1 ) {
125
+ $ this ->assertEquals ($ containerConfig , $ expectedInputParameters [0 ]);
126
+ $ this ->assertEquals ('foo ' , $ expectedInputParameters [1 ]);
127
+ $ this ->assertEquals (1 , $ expectedInputParameters [2 ]);
128
+ }
129
+ if ($ invokeCount ->$ numberOfInvocationsCallback () === 2 ) {
130
+ $ this ->assertEquals ($ containerConfig , $ expectedInputParameters [0 ]);
131
+ $ this ->assertEquals ('bar ' , $ expectedInputParameters [1 ]);
132
+ $ this ->assertEquals (1 , $ expectedInputParameters [2 ]);
133
+ }
134
+ }
135
+ );
113
136
$ initialQuery = $ queryBuilderInterceptor ->create ($ containerConfig , ['foo ' , 'bar ' ], $ spellingType );
114
137
$ this ->assertEquals (QueryInterface::TYPE_BOOL , $ initialQuery ->getType ());
115
138
@@ -145,16 +168,39 @@ public function testMultipleSearchQueryDepthBuilderWithRewrites()
145
168
$ queryRewritePlugin = new QueryRewrite ($ queryFactory , $ thesaurusConfigFactory , $ thesaurusIndex );
146
169
$ queryBuilderInterceptor = $ this ->getQueryBuilderWithPlugin ($ queryFactory , $ queryRewritePlugin );
147
170
171
+ /*
172
+ * withConsecutive removed in PHPUnit 10 without any alternative \o/.
173
+ * ----
148
174
$thesaurusIndex->expects($this->exactly(2))->method('getQueryRewrites')->withConsecutive(
149
175
[$containerConfig, 'foo', 1],
150
176
[$containerConfig, 'bar', 1],
151
- )->willReturnMap (
152
- [
153
- [$ containerConfig , 'foo ' , 1 , ['foo bar ' => 0.1 ]],
154
- [$ containerConfig , 'bar ' , 1 , ['bar fight ' => 0.1 ]],
155
- ]
156
- );
177
+ */
178
+ $ invokeCount = $ this ->exactly (2 );
179
+ $ numberOfInvocationsCallback = 'numberOfInvocations ' ;
180
+ if (method_exists ($ invokeCount , 'getInvocationCount ' )) {
181
+ // Method 'numberOfInvocations' only exists starting from PHPUnit 10.
182
+ $ numberOfInvocationsCallback = 'getInvocationCount ' ;
183
+ }
184
+ $ thesaurusIndex ->expects ($ invokeCount )->method ('getQueryRewrites ' )->willReturnCallback (
185
+ function (...$ expectedInputParameters ) use ($ invokeCount , $ containerConfig , $ numberOfInvocationsCallback ) {
186
+ if ($ invokeCount ->$ numberOfInvocationsCallback () === 1 ) {
187
+ $ this ->assertEquals ($ containerConfig , $ expectedInputParameters [0 ]);
188
+ $ this ->assertEquals ('foo ' , $ expectedInputParameters [1 ]);
189
+ $ this ->assertEquals (1 , $ expectedInputParameters [2 ]);
190
+
191
+ return ['foo bar ' => 0.1 ];
192
+ }
193
+ if ($ invokeCount ->$ numberOfInvocationsCallback () === 2 ) {
194
+ $ this ->assertEquals ($ containerConfig , $ expectedInputParameters [0 ]);
195
+ $ this ->assertEquals ('bar ' , $ expectedInputParameters [1 ]);
196
+ $ this ->assertEquals (1 , $ expectedInputParameters [2 ]);
157
197
198
+ return ['bar fight ' => 0.1 ];
199
+ }
200
+
201
+ return [];
202
+ }
203
+ );
158
204
$ query = $ queryBuilderInterceptor ->create ($ containerConfig , ['foo ' , 'bar ' ], $ spellingType );
159
205
$ this ->assertEquals (QueryInterface::TYPE_BOOL , $ query ->getType ());
160
206
}
@@ -181,14 +227,12 @@ public function testSingleSearchQueryLimitedRewrites()
181
227
->disableOriginalConstructor ()
182
228
->getMock ();
183
229
184
- // Passing the mock Query Factory to the plugin to count the occurence of calls to 'create'.
230
+ // Passing the mock Query Factory to the plugin to count the occurrence of calls to 'create'.
185
231
$ queryRewritePlugin = new QueryRewrite ($ queryFactoryFullMock , $ thesaurusConfigFactory , $ thesaurusIndex );
186
232
// But passing the real Query Factory (with mocked factories) to the query builder itself.
187
233
$ queryBuilderInterceptor = $ this ->getQueryBuilderWithPlugin ($ queryFactory , $ queryRewritePlugin );
188
234
189
- $ thesaurusIndex ->expects ($ this ->exactly (1 ))->method ('getQueryRewrites ' )->withConsecutive (
190
- [$ containerConfig , 'foo ' , 1 ]
191
- )->willReturnMap (
235
+ $ thesaurusIndex ->expects ($ this ->exactly (1 ))->method ('getQueryRewrites ' )->willReturnMap (
192
236
[
193
237
[$ containerConfig , 'foo ' , 1 , ['foo bar ' => 0.1 , 'foo light ' => 0.1 , 'moo ' => 0.1 , 'moo bar ' => 0.01 ]],
194
238
]
0 commit comments