1515use FOS \RestBundle \FOSRestBundle ;
1616use FOS \RestBundle \Negotiation \FormatNegotiator ;
1717use PHPUnit \Framework \TestCase ;
18+ use Symfony \Component \HttpFoundation \ChainRequestMatcher ;
1819use Symfony \Component \HttpFoundation \Request ;
1920use Symfony \Component \HttpFoundation \RequestMatcher ;
2021use Symfony \Component \HttpFoundation \RequestStack ;
2122use Symfony \Component \HttpKernel \Event \RequestEvent ;
2223use Symfony \Component \HttpKernel \Exception \HttpException ;
2324use Symfony \Component \HttpKernel \HttpKernelInterface ;
25+ use Symfony \Component \HttpKernel \Kernel ;
2426
2527/**
2628 * Request listener test.
@@ -44,7 +46,7 @@ public function testOnKernelControllerNegotiation()
4446 $ requestStack = new RequestStack ();
4547 $ requestStack ->push ($ request );
4648 $ formatNegotiator = new FormatNegotiator ($ requestStack );
47- $ formatNegotiator ->add (new RequestMatcher ('/ ' ), [
49+ $ formatNegotiator ->add ($ this -> getRequestMatcher ('/ ' ), [
4850 'fallback_format ' => 'xml ' ,
4951 ]);
5052
@@ -72,7 +74,7 @@ public function testOnKernelControllerNoZone()
7274 ->will ($ this ->returnValue ($ request ));
7375
7476 $ formatNegotiator = new FormatNegotiator ($ requestStack );
75- $ formatNegotiator ->add (new RequestMatcher ('/ ' ), ['fallback_format ' => 'json ' ]);
77+ $ formatNegotiator ->add ($ this -> getRequestMatcher ('/ ' ), ['fallback_format ' => 'json ' ]);
7678
7779 $ listener = new FormatListener ($ formatNegotiator );
7880
@@ -98,8 +100,8 @@ public function testOnKernelControllerNegotiationStopped()
98100 ->will ($ this ->returnValue ($ request ));
99101
100102 $ formatNegotiator = new FormatNegotiator ($ requestStack );
101- $ formatNegotiator ->add (new RequestMatcher ('/ ' ), ['stop ' => true ]);
102- $ formatNegotiator ->add (new RequestMatcher ('/ ' ), ['fallback_format ' => 'json ' ]);
103+ $ formatNegotiator ->add ($ this -> getRequestMatcher ('/ ' ), ['stop ' => true ]);
104+ $ formatNegotiator ->add ($ this -> getRequestMatcher ('/ ' ), ['fallback_format ' => 'json ' ]);
103105
104106 $ listener = new FormatListener ($ formatNegotiator );
105107
@@ -157,7 +159,7 @@ public function testUseSpecifiedFormat($format, $result)
157159 $ requestStack = new RequestStack ();
158160 $ requestStack ->push ($ request );
159161 $ formatNegotiator = new FormatNegotiator ($ requestStack );
160- $ formatNegotiator ->add (new RequestMatcher ('/ ' ), [
162+ $ formatNegotiator ->add ($ this -> getRequestMatcher ('/ ' ), [
161163 'fallback_format ' => 'xml ' ,
162164 ]);
163165
@@ -202,7 +204,7 @@ public function testSfFragmentFormat()
202204 $ requestStack = new RequestStack ();
203205 $ requestStack ->push ($ request );
204206 $ formatNegotiator = new FormatNegotiator ($ requestStack );
205- $ formatNegotiator ->add (new RequestMatcher ('/ ' ), [
207+ $ formatNegotiator ->add ($ this -> getRequestMatcher ('/ ' ), [
206208 'fallback_format ' => 'json ' ,
207209 ]);
208210
@@ -212,4 +214,13 @@ public function testSfFragmentFormat()
212214
213215 $ this ->assertEquals ($ request ->getRequestFormat (), 'json ' );
214216 }
217+
218+ private function getRequestMatcher (string $ path )
219+ {
220+ if (Kernel::VERSION_ID < 60200 ) {
221+ return new RequestMatcher ($ path );
222+ }
223+
224+ return new ChainRequestMatcher ([new RequestMatcher \PathRequestMatcher ($ path )]);
225+ }
215226}
0 commit comments