2929use Prophecy \Prophecy \ObjectProphecy ;
3030use Symfony \Component \HttpFoundation \Request ;
3131use Symfony \Component \HttpKernel \Event \RequestEvent ;
32+ use Symfony \Component \HttpKernel \HttpKernelInterface ;
3233
3334class QueryParameterValidateListenerTest extends TestCase
3435{
@@ -185,6 +186,30 @@ public function testOnKernelRequestWithRequiredFilter(): void
185186 $ this ->testedInstance ->onKernelRequest ($ eventProphecy ->reveal ());
186187 }
187188
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+
188213 private function setUpWithFilters (array $ filters = []): void
189214 {
190215 $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
@@ -207,7 +232,7 @@ public function testOnKernelRequest(): void
207232 $ request = new Request (
208233 [],
209234 [],
210- ['_api_resource_class ' => Dummy::class, '_api_operation ' => new GetCollection ()],
235+ ['_api_resource_class ' => Dummy::class, '_api_operation ' => new GetCollection (), ' _api_operation_name ' => ' get ' ],
211236 [],
212237 [],
213238 ['QUERY_STRING ' => 'required=foo ' ]
0 commit comments