|
16 | 16 | use Symfony\Component\HttpFoundation\RequestStack; |
17 | 17 | use Symfony\Component\HttpFoundation\Session\Session; |
18 | 18 | use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; |
| 19 | +use Symfony\Component\Security\Core\Exception\AuthenticationException; |
19 | 20 | use Symfony\Component\Security\Core\Security; |
20 | 21 | use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; |
21 | 22 |
|
22 | 23 | class AuthenticationUtilsTest extends TestCase |
23 | 24 | { |
24 | 25 | public function testLastAuthenticationErrorWhenRequestHasAttribute() |
25 | 26 | { |
| 27 | + $authenticationError = new AuthenticationException(); |
26 | 28 | $request = Request::create('/'); |
27 | | - $request->attributes->set(Security::AUTHENTICATION_ERROR, 'my error'); |
| 29 | + $request->attributes->set(Security::AUTHENTICATION_ERROR, $authenticationError); |
28 | 30 |
|
29 | 31 | $requestStack = new RequestStack(); |
30 | 32 | $requestStack->push($request); |
31 | 33 |
|
32 | 34 | $utils = new AuthenticationUtils($requestStack); |
33 | | - $this->assertSame('my error', $utils->getLastAuthenticationError()); |
| 35 | + $this->assertSame($authenticationError, $utils->getLastAuthenticationError()); |
34 | 36 | } |
35 | 37 |
|
36 | 38 | public function testLastAuthenticationErrorInSession() |
37 | 39 | { |
| 40 | + $authenticationError = new AuthenticationException(); |
| 41 | + |
38 | 42 | $request = Request::create('/'); |
39 | 43 |
|
40 | 44 | $session = new Session(new MockArraySessionStorage()); |
41 | | - $session->set(Security::AUTHENTICATION_ERROR, 'session error'); |
| 45 | + $session->set(Security::AUTHENTICATION_ERROR, $authenticationError); |
42 | 46 | $request->setSession($session); |
43 | 47 |
|
44 | 48 | $requestStack = new RequestStack(); |
45 | 49 | $requestStack->push($request); |
46 | 50 |
|
47 | 51 | $utils = new AuthenticationUtils($requestStack); |
48 | | - $this->assertSame('session error', $utils->getLastAuthenticationError()); |
| 52 | + $this->assertSame($authenticationError, $utils->getLastAuthenticationError()); |
49 | 53 | $this->assertFalse($session->has(Security::AUTHENTICATION_ERROR)); |
50 | 54 | } |
51 | 55 |
|
52 | 56 | public function testLastAuthenticationErrorInSessionWithoutClearing() |
53 | 57 | { |
| 58 | + $authenticationError = new AuthenticationException(); |
| 59 | + |
54 | 60 | $request = Request::create('/'); |
55 | 61 |
|
56 | 62 | $session = new Session(new MockArraySessionStorage()); |
57 | | - $session->set(Security::AUTHENTICATION_ERROR, 'session error'); |
| 63 | + $session->set(Security::AUTHENTICATION_ERROR, $authenticationError); |
58 | 64 | $request->setSession($session); |
59 | 65 |
|
60 | 66 | $requestStack = new RequestStack(); |
61 | 67 | $requestStack->push($request); |
62 | 68 |
|
63 | 69 | $utils = new AuthenticationUtils($requestStack); |
64 | | - $this->assertSame('session error', $utils->getLastAuthenticationError(false)); |
| 70 | + $this->assertSame($authenticationError, $utils->getLastAuthenticationError(false)); |
65 | 71 | $this->assertTrue($session->has(Security::AUTHENTICATION_ERROR)); |
66 | 72 | } |
67 | 73 |
|
|
0 commit comments