1919use PHPUnit \Framework \TestCase ;
2020use Symfony \Component \HttpFoundation \Request ;
2121use Symfony \Component \HttpFoundation \RequestMatcher ;
22+ use Symfony \Component \HttpFoundation \RequestMatcher \PathRequestMatcher ;
23+ use Symfony \Component \HttpFoundation \RequestMatcherInterface ;
2224use Symfony \Component \HttpFoundation \Response ;
2325use Symfony \Component \HttpKernel \HttpCache \StoreInterface ;
2426use Toflar \Psr6HttpCacheStore \Psr6Store ;
@@ -35,7 +37,7 @@ public function testConstructorOverspecified()
3537 $ this ->expectException (\InvalidArgumentException::class);
3638 $ this ->expectExceptionMessage ('You may not set both a request matcher and an IP ' );
3739 new PurgeListener ([
38- 'client_matcher ' => new RequestMatcher ('/forbidden ' ),
40+ 'client_matcher ' => $ this -> createRequestMatcher ('/forbidden ' ),
3941 'client_ips ' => ['1.2.3.4 ' ],
4042 ]);
4143 }
@@ -129,7 +131,7 @@ public function testPurgeForbiddenMatcher()
129131 {
130132 $ kernel = $ this ->getUnusedKernelMock ();
131133
132- $ matcher = new RequestMatcher ('/forbidden ' );
134+ $ matcher = $ this -> createRequestMatcher ('/forbidden ' );
133135 $ purgeListener = new PurgeListener (['client_matcher ' => $ matcher ]);
134136 $ request = Request::create ('http://example.com/foo ' , 'PURGE ' );
135137 $ event = new CacheEvent ($ kernel , $ request );
@@ -162,7 +164,7 @@ public function testPurgeForbiddenIp()
162164 public function testOtherMethod ()
163165 {
164166 $ kernel = $ this ->getUnusedKernelMock ();
165- $ matcher = \Mockery::mock (RequestMatcher ::class)
167+ $ matcher = \Mockery::mock (RequestMatcherInterface ::class)
166168 ->shouldNotReceive ('isRequestAllowed ' )
167169 ->getMock ();
168170
@@ -184,6 +186,14 @@ public function testInvalidConfiguration()
184186 new PurgeListener (['stuff ' => '1.2.3.4 ' ]);
185187 }
186188
189+ private function createRequestMatcher (string $ path ): RequestMatcherInterface
190+ {
191+ return class_exists (PathRequestMatcher::class)
192+ ? new PathRequestMatcher ($ path )
193+ : new RequestMatcher ($ path )
194+ ;
195+ }
196+
187197 /**
188198 * @return CacheInvalidation|MockInterface
189199 */
0 commit comments