29
29
use Prophecy \Prophecy \ObjectProphecy ;
30
30
use Symfony \Component \HttpFoundation \Request ;
31
31
use Symfony \Component \HttpKernel \Event \RequestEvent ;
32
+ use Symfony \Component \HttpKernel \HttpKernelInterface ;
32
33
33
34
class QueryParameterValidateListenerTest extends TestCase
34
35
{
@@ -185,6 +186,30 @@ public function testOnKernelRequestWithRequiredFilter(): void
185
186
$ this ->testedInstance ->onKernelRequest ($ eventProphecy ->reveal ());
186
187
}
187
188
189
+ /**
190
+ * if parameter use_symfony_listeners is true.
191
+ *
192
+ * @group legacy
193
+ */
194
+ public function testDoNothingWhenListenersDisabled (): void
195
+ {
196
+ $ parameterValidator = $ this ->prophesize (ProviderInterface::class);
197
+ $ parameterValidator ->provide ()->shouldNotBeCalled ();
198
+
199
+ $ factory = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
200
+ $ factory ->create (Dummy::class)->willReturn (new ResourceMetadataCollection (Dummy::class, [new ApiResource (operations: ['get ' => new Get (name: 'get ' )])]))->shouldBeCalled ();
201
+
202
+ $ listener = new QueryParameterValidateListener ($ parameterValidator ->reveal (), $ factory ->reveal ());
203
+
204
+ $ event = new RequestEvent (
205
+ $ this ->prophesize (HttpKernelInterface::class)->reveal (),
206
+ new Request ([], [], ['_api_resource_class ' => Dummy::class, '_api_operation_name ' => 'get ' , '_api_platform_disable_listeners ' => true ]),
207
+ \defined (HttpKernelInterface::class.'::MAIN_REQUEST ' ) ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST ,
208
+ );
209
+
210
+ $ listener ->onKernelRequest ($ event );
211
+ }
212
+
188
213
private function setUpWithFilters (array $ filters = []): void
189
214
{
190
215
$ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
@@ -207,7 +232,7 @@ public function testOnKernelRequest(): void
207
232
$ request = new Request (
208
233
[],
209
234
[],
210
- ['_api_resource_class ' => Dummy::class, '_api_operation ' => new GetCollection ()],
235
+ ['_api_resource_class ' => Dummy::class, '_api_operation ' => new GetCollection (), ' _api_operation_name ' => ' get ' ],
211
236
[],
212
237
[],
213
238
['QUERY_STRING ' => 'required=foo ' ]
0 commit comments