11
11
12
12
namespace Symfony \Component \Security \Http \Tests \Firewall ;
13
13
14
+ use Symfony \Component \Security \Core \Authentication \Token \AnonymousToken ;
14
15
use Symfony \Component \Security \Http \Firewall \AnonymousAuthenticationListener ;
15
16
16
17
class AnonymousAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
@@ -28,7 +29,13 @@ public function testHandleWithContextHavingAToken()
28
29
->method ('setToken ' )
29
30
;
30
31
31
- $ listener = new AnonymousAuthenticationListener ($ context , 'TheKey ' );
32
+ $ authenticationManager = $ this ->getMock ('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface ' );
33
+ $ authenticationManager
34
+ ->expects ($ this ->never ())
35
+ ->method ('authenticate ' )
36
+ ;
37
+
38
+ $ listener = new AnonymousAuthenticationListener ($ context , 'TheKey ' , $ authenticationManager );
32
39
$ listener ->handle ($ this ->getMock ('Symfony\Component\HttpKernel\Event\GetResponseEvent ' , array (), array (), '' , false ));
33
40
}
34
41
@@ -40,16 +47,27 @@ public function testHandleWithContextHavingNoToken()
40
47
->method ('getToken ' )
41
48
->will ($ this ->returnValue (null ))
42
49
;
43
- $ context
50
+
51
+ $ anonymousToken = new AnonymousToken ('TheKey ' , 'anon. ' , array ());
52
+
53
+ $ authenticationManager = $ this ->getMock ('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface ' );
54
+ $ authenticationManager
44
55
->expects ($ this ->once ())
45
- ->method ('setToken ' )
56
+ ->method ('authenticate ' )
46
57
->with (self ::logicalAnd (
47
- $ this ->isInstanceOf ('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken ' ),
48
- $ this ->attributeEqualTo ('key ' , 'TheKey ' )
58
+ $ this ->isInstanceOf ('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken ' ),
59
+ $ this ->attributeEqualTo ('key ' , 'TheKey ' )
49
60
))
61
+ ->will ($ this ->returnValue ($ anonymousToken ))
50
62
;
51
63
52
- $ listener = new AnonymousAuthenticationListener ($ context , 'TheKey ' );
64
+ $ context
65
+ ->expects ($ this ->once ())
66
+ ->method ('setToken ' )
67
+ ->with ($ anonymousToken )
68
+ ;
69
+
70
+ $ listener = new AnonymousAuthenticationListener ($ context , 'TheKey ' , $ authenticationManager );
53
71
$ listener ->handle ($ this ->getMock ('Symfony\Component\HttpKernel\Event\GetResponseEvent ' , array (), array (), '' , false ));
54
72
}
55
73
@@ -66,7 +84,9 @@ public function testHandledEventIsLogged()
66
84
->with ('Populated SecurityContext with an anonymous Token ' )
67
85
;
68
86
69
- $ listener = new AnonymousAuthenticationListener ($ context , 'TheKey ' , $ logger );
87
+ $ authenticationManager = $ this ->getMock ('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface ' );
88
+
89
+ $ listener = new AnonymousAuthenticationListener ($ context , 'TheKey ' , $ authenticationManager , $ logger );
70
90
$ listener ->handle ($ this ->getMock ('Symfony\Component\HttpKernel\Event\GetResponseEvent ' , array (), array (), '' , false ));
71
91
}
72
92
}
0 commit comments