@@ -60,9 +60,11 @@ public function testIsHiddenDefault()
60
60
self ::assertFalse ($ this ->question ->isHidden ());
61
61
}
62
62
63
- public function testSetHiddenWithAutocompleterValues ()
63
+ public function testSetHiddenWithAutocompleterCallback ()
64
64
{
65
- $ this ->question ->setAutocompleterValues (['a ' , 'b ' ]);
65
+ $ this ->question ->setAutocompleterCallback (
66
+ function (string $ input ): array { return []; }
67
+ );
66
68
67
69
$ this ->expectException (\LogicException::class);
68
70
$ this ->expectExceptionMessage (
@@ -72,10 +74,12 @@ public function testSetHiddenWithAutocompleterValues()
72
74
$ this ->question ->setHidden (true );
73
75
}
74
76
75
- public function testSetHiddenWithNoAutocompleterValues ()
77
+ public function testSetHiddenWithNoAutocompleterCallback ()
76
78
{
77
- $ this ->question ->setAutocompleterValues (['a ' , 'b ' ]);
78
- $ this ->question ->setAutocompleterValues (null );
79
+ $ this ->question ->setAutocompleterCallback (
80
+ function (string $ input ): array { return []; }
81
+ );
82
+ $ this ->question ->setAutocompleterCallback (null );
79
83
80
84
$ exception = null ;
81
85
try {
@@ -154,7 +158,51 @@ public function testSetAutocompleterValuesInvalid($values)
154
158
$ this ->question ->setAutocompleterValues ($ values );
155
159
}
156
160
157
- public function testSetAutocompleterValuesWhenHidden ()
161
+ public function testSetAutocompleterValuesWithTraversable ()
162
+ {
163
+ $ question1 = new Question ('Test question 1 ' );
164
+ $ iterator1 = $ this ->getMockForAbstractClass (\IteratorAggregate::class);
165
+ $ iterator1
166
+ ->expects ($ this ->once ())
167
+ ->method ('getIterator ' )
168
+ ->willReturn (new \ArrayIterator (['Potato ' ]));
169
+ $ question1 ->setAutocompleterValues ($ iterator1 );
170
+
171
+ $ question2 = new Question ('Test question 2 ' );
172
+ $ iterator2 = $ this ->getMockForAbstractClass (\IteratorAggregate::class);
173
+ $ iterator2
174
+ ->expects ($ this ->once ())
175
+ ->method ('getIterator ' )
176
+ ->willReturn (new \ArrayIterator (['Carrot ' ]));
177
+ $ question2 ->setAutocompleterValues ($ iterator2 );
178
+
179
+ // Call multiple times to verify that Traversable result is cached, and
180
+ // that there is no crosstalk between cached copies.
181
+ self ::assertSame (['Potato ' ], $ question1 ->getAutocompleterValues ());
182
+ self ::assertSame (['Carrot ' ], $ question2 ->getAutocompleterValues ());
183
+ self ::assertSame (['Potato ' ], $ question1 ->getAutocompleterValues ());
184
+ self ::assertSame (['Carrot ' ], $ question2 ->getAutocompleterValues ());
185
+ }
186
+
187
+ public function testGetAutocompleterValuesDefault ()
188
+ {
189
+ self ::assertNull ($ this ->question ->getAutocompleterValues ());
190
+ }
191
+
192
+ public function testGetSetAutocompleterCallback ()
193
+ {
194
+ $ callback = function (string $ input ): array { return []; };
195
+
196
+ $ this ->question ->setAutocompleterCallback ($ callback );
197
+ self ::assertSame ($ callback , $ this ->question ->getAutocompleterCallback ());
198
+ }
199
+
200
+ public function testGetAutocompleterCallbackDefault ()
201
+ {
202
+ self ::assertNull ($ this ->question ->getAutocompleterCallback ());
203
+ }
204
+
205
+ public function testSetAutocompleterCallbackWhenHidden ()
158
206
{
159
207
$ this ->question ->setHidden (true );
160
208
@@ -163,29 +211,28 @@ public function testSetAutocompleterValuesWhenHidden()
163
211
'A hidden question cannot use the autocompleter. '
164
212
);
165
213
166
- $ this ->question ->setAutocompleterValues (['a ' , 'b ' ]);
214
+ $ this ->question ->setAutocompleterCallback (
215
+ function (string $ input ): array { return []; }
216
+ );
167
217
}
168
218
169
- public function testSetAutocompleterValuesWhenNotHidden ()
219
+ public function testSetAutocompleterCallbackWhenNotHidden ()
170
220
{
171
221
$ this ->question ->setHidden (true );
172
222
$ this ->question ->setHidden (false );
173
223
174
224
$ exception = null ;
175
225
try {
176
- $ this ->question ->setAutocompleterValues (['a ' , 'b ' ]);
226
+ $ this ->question ->setAutocompleterCallback (
227
+ function (string $ input ): array { return []; }
228
+ );
177
229
} catch (\Exception $ exception ) {
178
230
// Do nothing
179
231
}
180
232
181
233
$ this ->assertNull ($ exception );
182
234
}
183
235
184
- public function testGetAutocompleterValuesDefault ()
185
- {
186
- self ::assertNull ($ this ->question ->getAutocompleterValues ());
187
- }
188
-
189
236
public function providerGetSetValidator ()
190
237
{
191
238
return [
0 commit comments