@@ -131,8 +131,10 @@ public function testAccessDeniedExceptionFullFledgedAndWithAccessDeniedHandlerAn
131
131
{
132
132
$ event = $ this ->createEvent ($ exception );
133
133
134
- $ listener = $ this ->createExceptionListener (null , $ this ->createTrustResolver (true ), null , null , null , $ this ->createCustomAccessDeniedHandler (new Response ('error ' )));
134
+ $ accessDeniedHandler = $ this ->getMockBuilder ('Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface ' )->getMock ();
135
+ $ accessDeniedHandler ->expects ($ this ->once ())->method ('handle ' )->will ($ this ->returnValue (new Response ('error ' )));
135
136
137
+ $ listener = $ this ->createExceptionListener (null , $ this ->createTrustResolver (true ), null , null , null , $ accessDeniedHandler );
136
138
$ listener ->onKernelException ($ event );
137
139
138
140
$ this ->assertEquals ('error ' , $ event ->getResponse ()->getContent ());
@@ -146,48 +148,13 @@ public function testAccessDeniedExceptionNotFullFledged(\Exception $exception, \
146
148
{
147
149
$ event = $ this ->createEvent ($ exception );
148
150
149
- $ listener = $ this ->createExceptionListener ($ this ->createTokenStorage (), $ this ->createTrustResolver (false ), null , $ this ->createEntryPoint ());
150
- $ listener ->onKernelException ($ event );
151
-
152
- $ this ->assertEquals ('OK ' , $ event ->getResponse ()->getContent ());
153
- $ this ->assertSame (null === $ eventException ? $ exception : $ eventException , $ event ->getException ()->getPrevious ());
154
- }
155
-
156
- /**
157
- * @dataProvider getAccessDeniedExceptionProvider
158
- */
159
- public function testAccessDeniedExceptionNotFullFledgedAndWithAccessDeniedHandlerAndWithoutErrorPage (\Exception $ exception , \Exception $ eventException = null )
160
- {
161
- $ event = $ this ->createEvent ($ exception );
162
-
163
- $ listener = $ this ->createExceptionListener ($ this ->createTokenStorage (), $ this ->createTrustResolver (false ), null , $ this ->createEntryPoint (), null , $ this ->createCustomAccessDeniedHandler (new Response ('denied ' , 403 )));
164
- $ listener ->onKernelException ($ event );
165
-
166
- $ this ->assertEquals ('denied ' , $ event ->getResponse ()->getContent ());
167
- $ this ->assertEquals (403 , $ event ->getResponse ()->getStatusCode ());
168
- $ this ->assertSame (null === $ eventException ? $ exception : $ eventException , $ event ->getException ()->getPrevious ());
169
- }
170
-
171
- /**
172
- * @dataProvider getAccessDeniedExceptionProvider
173
- */
174
- public function testAccessDeniedExceptionNotFullFledgedAndWithoutAccessDeniedHandlerAndWithErrorPage (\Exception $ exception , \Exception $ eventException = null )
175
- {
176
- $ kernel = $ this ->getMockBuilder ('Symfony\Component\HttpKernel\HttpKernelInterface ' )->getMock ();
177
- $ kernel ->expects ($ this ->once ())->method ('handle ' )->will ($ this ->returnValue (new Response ('Unauthorized ' , 401 )));
178
-
179
- $ event = $ this ->createEvent ($ exception , $ kernel );
180
-
181
- $ httpUtils = $ this ->getMockBuilder ('Symfony\Component\Security\Http\HttpUtils ' )->getMock ();
182
- $ httpUtils ->expects ($ this ->once ())->method ('createRequest ' )->will ($ this ->returnValue (Request::create ('/error ' )));
151
+ $ tokenStorage = $ this ->getMockBuilder ('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface ' )->getMock ();
152
+ $ tokenStorage ->expects ($ this ->once ())->method ('getToken ' )->will ($ this ->returnValue ($ this ->getMockBuilder ('Symfony\Component\Security\Core\Authentication\Token\TokenInterface ' )->getMock ()));
183
153
184
- $ listener = $ this ->createExceptionListener ($ this -> createTokenStorage () , $ this ->createTrustResolver (true ), $ httpUtils , null , ' /error ' );
154
+ $ listener = $ this ->createExceptionListener ($ tokenStorage , $ this ->createTrustResolver (false ), null , $ this -> createEntryPoint () );
185
155
$ listener ->onKernelException ($ event );
186
156
187
- $ this ->assertTrue ($ event ->isAllowingCustomResponseCode ());
188
-
189
- $ this ->assertEquals ('Unauthorized ' , $ event ->getResponse ()->getContent ());
190
- $ this ->assertEquals (401 , $ event ->getResponse ()->getStatusCode ());
157
+ $ this ->assertEquals ('OK ' , $ event ->getResponse ()->getContent ());
191
158
$ this ->assertSame (null === $ eventException ? $ exception : $ eventException , $ event ->getException ()->getPrevious ());
192
159
}
193
160
@@ -202,22 +169,6 @@ public function getAccessDeniedExceptionProvider()
202
169
];
203
170
}
204
171
205
- private function createTokenStorage ()
206
- {
207
- $ tokenStorage = $ this ->getMockBuilder ('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface ' )->getMock ();
208
- $ tokenStorage ->expects ($ this ->once ())->method ('getToken ' )->will ($ this ->returnValue ($ this ->getMockBuilder ('Symfony\Component\Security\Core\Authentication\Token\TokenInterface ' )->getMock ()));
209
-
210
- return $ tokenStorage ;
211
- }
212
-
213
- private function createCustomAccessDeniedHandler (Response $ response )
214
- {
215
- $ accessDeniedHandler = $ this ->getMockBuilder ('Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface ' )->getMock ();
216
- $ accessDeniedHandler ->expects ($ this ->once ())->method ('handle ' )->will ($ this ->returnValue ($ response ));
217
-
218
- return $ accessDeniedHandler ;
219
- }
220
-
221
172
private function createEntryPoint (Response $ response = null )
222
173
{
223
174
$ entryPoint = $ this ->getMockBuilder ('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface ' )->getMock ();
0 commit comments