1111
1212namespace Symfony \Component \HttpKernel \Tests \EventListener ;
1313
14- use PHPUnit \Framework \Attributes \RequiresMethod ;
1514use PHPUnit \Framework \TestCase ;
16- use Psr \Container \ContainerInterface ;
1715use Symfony \Component \HttpFoundation \Exception \UnsignedUriException ;
1816use Symfony \Component \HttpFoundation \Request ;
1917use Symfony \Component \HttpFoundation \UriSigner ;
2018use Symfony \Component \HttpKernel \Event \ControllerArgumentsEvent ;
2119use Symfony \Component \HttpKernel \EventListener \IsSignatureValidAttributeListener ;
2220use Symfony \Component \HttpKernel \HttpKernelInterface ;
23- use Symfony \Component \HttpKernel \Tests \Fixtures \ExtendedSigner ;
2421use Symfony \Component \HttpKernel \Tests \Fixtures \IsSignatureValidAttributeController ;
2522use Symfony \Component \HttpKernel \Tests \Fixtures \IsSignatureValidAttributeMethodsController ;
2623
27- #[RequiresMethod(UriSigner::class, 'verify ' )]
2824class IsSignatureValidAttributeListenerTest extends TestCase
2925{
3026 public function testInvokableControllerWithValidSignature ()
@@ -34,8 +30,6 @@ public function testInvokableControllerWithValidSignature()
3430 $ signer = $ this ->createMock (UriSigner::class);
3531 $ signer ->expects ($ this ->once ())->method ('verify ' )->with ($ request );
3632 $ kernel = $ this ->createMock (HttpKernelInterface::class);
37- $ container = $ this ->createMock (ContainerInterface::class);
38- $ container ->expects ($ this ->never ())->method ('get ' );
3933
4034 $ event = new ControllerArgumentsEvent (
4135 $ kernel ,
@@ -45,16 +39,15 @@ public function testInvokableControllerWithValidSignature()
4539 null
4640 );
4741
48- $ listener = new IsSignatureValidAttributeListener ($ signer, $ container );
42+ $ listener = new IsSignatureValidAttributeListener ($ signer );
4943 $ listener ->onKernelControllerArguments ($ event );
5044 }
5145
5246 public function testNoAttributeSkipsValidation ()
5347 {
5448 $ kernel = $ this ->createMock (HttpKernelInterface::class);
5549 $ signer = $ this ->createMock (UriSigner::class);
56- $ container = $ this ->createMock (ContainerInterface::class);
57- $ container ->expects ($ this ->never ())->method ('get ' );
50+ $ signer ->expects ($ this ->never ())->method ('verify ' );
5851
5952 $ event = new ControllerArgumentsEvent (
6053 $ kernel ,
@@ -64,7 +57,7 @@ public function testNoAttributeSkipsValidation()
6457 null
6558 );
6659
67- $ listener = new IsSignatureValidAttributeListener ($ signer, $ container );
60+ $ listener = new IsSignatureValidAttributeListener ($ signer );
6861 $ listener ->onKernelControllerArguments ($ event );
6962 }
7063
@@ -74,8 +67,6 @@ public function testDefaultCheckRequestSucceeds()
7467 $ signer = $ this ->createMock (UriSigner::class);
7568 $ signer ->expects ($ this ->once ())->method ('verify ' )->with ($ request );
7669 $ kernel = $ this ->createMock (HttpKernelInterface::class);
77- $ container = $ this ->createMock (ContainerInterface::class);
78- $ container ->expects ($ this ->never ())->method ('get ' );
7970
8071 $ event = new ControllerArgumentsEvent (
8172 $ kernel ,
@@ -85,7 +76,7 @@ public function testDefaultCheckRequestSucceeds()
8576 null
8677 );
8778
88- $ listener = new IsSignatureValidAttributeListener ($ signer, $ container );
79+ $ listener = new IsSignatureValidAttributeListener ($ signer );
8980 $ listener ->onKernelControllerArguments ($ event );
9081 }
9182
@@ -95,8 +86,6 @@ public function testCheckRequestFailsThrowsHttpException()
9586 $ signer = $ this ->createMock (UriSigner::class);
9687 $ signer ->expects ($ this ->once ())->method ('verify ' )->willThrowException (new UnsignedUriException ());
9788 $ kernel = $ this ->createMock (HttpKernelInterface::class);
98- $ container = $ this ->createMock (ContainerInterface::class);
99- $ container ->expects ($ this ->never ())->method ('get ' );
10089
10190 $ event = new ControllerArgumentsEvent (
10291 $ kernel ,
@@ -106,7 +95,7 @@ public function testCheckRequestFailsThrowsHttpException()
10695 null
10796 );
10897
109- $ listener = new IsSignatureValidAttributeListener ($ signer, $ container );
98+ $ listener = new IsSignatureValidAttributeListener ($ signer );
11099
111100 $ this ->expectException (UnsignedUriException::class);
112101 $ listener ->onKernelControllerArguments ($ event );
@@ -119,8 +108,6 @@ public function testMultipleAttributesAllValid()
119108 $ signer = $ this ->createMock (UriSigner::class);
120109 $ signer ->expects ($ this ->exactly (2 ))->method ('verify ' )->with ($ request );
121110 $ kernel = $ this ->createMock (HttpKernelInterface::class);
122- $ container = $ this ->createMock (ContainerInterface::class);
123- $ container ->expects ($ this ->never ())->method ('get ' );
124111
125112 $ event = new ControllerArgumentsEvent (
126113 $ kernel ,
@@ -130,7 +117,7 @@ public function testMultipleAttributesAllValid()
130117 null
131118 );
132119
133- $ listener = new IsSignatureValidAttributeListener ($ signer, $ container );
120+ $ listener = new IsSignatureValidAttributeListener ($ signer );
134121 $ listener ->onKernelControllerArguments ($ event );
135122 }
136123
@@ -141,8 +128,6 @@ public function testValidationWithStringMethod()
141128 $ signer = $ this ->createMock (UriSigner::class);
142129 $ signer ->expects ($ this ->once ())->method ('verify ' )->with ($ request );
143130 $ kernel = $ this ->createMock (HttpKernelInterface::class);
144- $ container = $ this ->createMock (ContainerInterface::class);
145- $ container ->expects ($ this ->never ())->method ('get ' );
146131
147132 $ event = new ControllerArgumentsEvent (
148133 $ kernel ,
@@ -152,7 +137,7 @@ public function testValidationWithStringMethod()
152137 null
153138 );
154139
155- $ listener = new IsSignatureValidAttributeListener ($ signer, $ container );
140+ $ listener = new IsSignatureValidAttributeListener ($ signer );
156141 $ listener ->onKernelControllerArguments ($ event );
157142 }
158143
@@ -163,8 +148,6 @@ public function testValidationWithArrayMethods()
163148 $ signer = $ this ->createMock (UriSigner::class);
164149 $ signer ->expects ($ this ->once ())->method ('verify ' )->with ($ request );
165150 $ kernel = $ this ->createMock (HttpKernelInterface::class);
166- $ container = $ this ->createMock (ContainerInterface::class);
167- $ container ->expects ($ this ->never ())->method ('get ' );
168151
169152 $ event = new ControllerArgumentsEvent (
170153 $ kernel ,
@@ -174,7 +157,7 @@ public function testValidationWithArrayMethods()
174157 null
175158 );
176159
177- $ listener = new IsSignatureValidAttributeListener ($ signer, $ container );
160+ $ listener = new IsSignatureValidAttributeListener ($ signer );
178161 $ listener ->onKernelControllerArguments ($ event );
179162 }
180163
@@ -184,8 +167,7 @@ public function testValidationSkippedForNonMatchingMethod()
184167
185168 $ kernel = $ this ->createMock (HttpKernelInterface::class);
186169 $ signer = $ this ->createMock (UriSigner::class);
187- $ container = $ this ->createMock (ContainerInterface::class);
188- $ container ->expects ($ this ->never ())->method ('get ' );
170+ $ signer ->expects ($ this ->never ())->method ('verify ' );
189171
190172 $ event = new ControllerArgumentsEvent (
191173 $ kernel ,
@@ -195,51 +177,7 @@ public function testValidationSkippedForNonMatchingMethod()
195177 null
196178 );
197179
198- $ listener = new IsSignatureValidAttributeListener ($ signer , $ container );
199- $ listener ->onKernelControllerArguments ($ event );
200- }
201-
202- public function testValidationWithSigner ()
203- {
204- $ request = new Request ();
205- $ signer = $ this ->createMock (UriSigner::class);
206- $ customSigner = $ this ->createMock (UriSigner::class);
207- $ customSigner ->expects ($ this ->once ())->method ('verify ' )->with ($ request );
208- $ kernel = $ this ->createMock (HttpKernelInterface::class);
209- $ container = $ this ->createMock (ContainerInterface::class);
210- $ container ->expects ($ this ->once ())->method ('get ' )->with ('app.test.signer ' )->willReturn ($ customSigner );
211-
212- $ event = new ControllerArgumentsEvent (
213- $ kernel ,
214- [new IsSignatureValidAttributeMethodsController (), 'withCustomSigner ' ],
215- [],
216- $ request ,
217- null
218- );
219-
220- $ listener = new IsSignatureValidAttributeListener ($ signer , $ container );
221- $ listener ->onKernelControllerArguments ($ event );
222- }
223-
224- public function testValidationWithExtendedSigner ()
225- {
226- $ request = new Request ();
227- $ signer = $ this ->createMock (UriSigner::class);
228- $ extendedSigner = $ this ->createMock (ExtendedSigner::class);
229- $ extendedSigner ->expects ($ this ->once ())->method ('verify ' )->with ($ request );
230- $ kernel = $ this ->createMock (HttpKernelInterface::class);
231- $ container = $ this ->createMock (ContainerInterface::class);
232- $ container ->expects ($ this ->once ())->method ('get ' )->with ('app.test.extended_signer ' )->willReturn ($ extendedSigner );
233-
234- $ event = new ControllerArgumentsEvent (
235- $ kernel ,
236- [new IsSignatureValidAttributeMethodsController (), 'withCustomExtendedSigner ' ],
237- [],
238- $ request ,
239- null
240- );
241-
242- $ listener = new IsSignatureValidAttributeListener ($ signer , $ container );
180+ $ listener = new IsSignatureValidAttributeListener ($ signer );
243181 $ listener ->onKernelControllerArguments ($ event );
244182 }
245183}
0 commit comments