@@ -44,14 +44,19 @@ public function testAuthenticationExceptionWithoutEntryPoint(\Exception $excepti
44
44
/**
45
45
* @dataProvider getAuthenticationExceptionProvider
46
46
*/
47
- public function testAuthenticationExceptionWithEntryPoint (\Exception $ exception, \ Exception $ eventException = null )
47
+ public function testAuthenticationExceptionWithEntryPoint (\Exception $ exception )
48
48
{
49
- $ event = $ this ->createEvent ($ exception = new AuthenticationException ());
49
+ $ event = $ this ->createEvent ($ exception );
50
+
51
+ $ response = new Response ('Forbidden ' , 403 );
50
52
51
- $ listener = $ this ->createExceptionListener (null , null , null , $ this ->createEntryPoint ());
53
+ $ listener = $ this ->createExceptionListener (null , null , null , $ this ->createEntryPoint ($ response ));
52
54
$ listener ->onKernelException ($ event );
53
55
54
- $ this ->assertEquals ('OK ' , $ event ->getResponse ()->getContent ());
56
+ $ this ->assertTrue ($ event ->isAllowingCustomResponseCode ());
57
+
58
+ $ this ->assertEquals ('Forbidden ' , $ event ->getResponse ()->getContent ());
59
+ $ this ->assertEquals (403 , $ event ->getResponse ()->getStatusCode ());
55
60
$ this ->assertSame ($ exception , $ event ->getException ());
56
61
}
57
62
@@ -100,7 +105,7 @@ public function testAccessDeniedExceptionFullFledgedAndWithoutAccessDeniedHandle
100
105
public function testAccessDeniedExceptionFullFledgedAndWithoutAccessDeniedHandlerAndWithErrorPage (\Exception $ exception , \Exception $ eventException = null )
101
106
{
102
107
$ kernel = $ this ->getMockBuilder ('Symfony\Component\HttpKernel\HttpKernelInterface ' )->getMock ();
103
- $ kernel ->expects ($ this ->once ())->method ('handle ' )->will ($ this ->returnValue (new Response ('error ' )));
108
+ $ kernel ->expects ($ this ->once ())->method ('handle ' )->will ($ this ->returnValue (new Response ('Unauthorized ' , 401 )));
104
109
105
110
$ event = $ this ->createEvent ($ exception , $ kernel );
106
111
@@ -110,7 +115,10 @@ public function testAccessDeniedExceptionFullFledgedAndWithoutAccessDeniedHandle
110
115
$ listener = $ this ->createExceptionListener (null , $ this ->createTrustResolver (true ), $ httpUtils , null , '/error ' );
111
116
$ listener ->onKernelException ($ event );
112
117
113
- $ this ->assertEquals ('error ' , $ event ->getResponse ()->getContent ());
118
+ $ this ->assertTrue ($ event ->isAllowingCustomResponseCode ());
119
+
120
+ $ this ->assertEquals ('Unauthorized ' , $ event ->getResponse ()->getContent ());
121
+ $ this ->assertEquals (401 , $ event ->getResponse ()->getStatusCode ());
114
122
$ this ->assertSame (null === $ eventException ? $ exception : $ eventException , $ event ->getException ()->getPrevious ());
115
123
}
116
124
@@ -159,10 +167,10 @@ public function getAccessDeniedExceptionProvider()
159
167
);
160
168
}
161
169
162
- private function createEntryPoint ()
170
+ private function createEntryPoint (Response $ response = null )
163
171
{
164
172
$ entryPoint = $ this ->getMockBuilder ('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface ' )->getMock ();
165
- $ entryPoint ->expects ($ this ->once ())->method ('start ' )->will ($ this ->returnValue (new Response ('OK ' )));
173
+ $ entryPoint ->expects ($ this ->once ())->method ('start ' )->will ($ this ->returnValue ($ response ?: new Response ('OK ' )));
166
174
167
175
return $ entryPoint ;
168
176
}
0 commit comments