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