@@ -72,6 +72,63 @@ public function testAuthenticateWhenPostChecksFails()
7272$ provider ->authenticate ($ token );
7373 }
7474
75+ /**
76+ * @expectedException \Symfony\Component\Security\Core\Exception\LockedException
77+ */
78+ public function testAuthenticateFromString ()
79+ {
80+ $ user =$ this ->getMockBuilder ('Symfony\Component\Security\Core\User\UserInterface ' )->getMock ();
81+
82+ $ token =$ this ->getMockBuilder ('Symfony\Component\Security\Core\Authentication\Token\TokenInterface ' )->getMock ();
83+ $ token ->expects ($ this ->any ())
84+ ->method ('getUser ' )
85+ ->will ($ this ->returnValue ('foo ' ));
86+
87+ $ userChecker =$ this ->getMockBuilder ('Symfony\Component\Security\Core\User\UserCheckerInterface ' )->getMock ();
88+ $ userChecker ->expects ($ this ->once ())
89+ ->method ('checkPostAuth ' )
90+ ->will ($ this ->throwException (new LockedException ()));
91+
92+ $ authenticator =$ this ->getMockBuilder ('Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface ' )->getMock ();
93+ $ authenticator ->expects ($ this ->once ())
94+ ->method ('authenticateToken ' )
95+ ->will ($ this ->returnValue ($ token ));
96+
97+ $ userProvider =$ this ->getMockBuilder ('Symfony\Component\Security\Core\User\UserProviderInterface ' )->getMock ();
98+ $ userProvider ->expects ($ this ->once ())
99+ ->method ('loadUserByUsername ' )
100+ ->willReturn ($ this ->getMockBuilder ('Symfony\Component\Security\Core\User\UserInterface ' )->getMock ());
101+ $ provider =$ this ->getProvider ($ authenticator ,$ userProvider ,$ userChecker );
102+
103+ $ this ->assertSame ($ token ,$ provider ->authenticate ($ token ));
104+ }
105+
106+ /**
107+ * @expectedException \Symfony\Component\Security\Core\Exception\UsernameNotFoundException
108+ */
109+ public function testUsernameNotFound ()
110+ {
111+ $ user =$ this ->getMockBuilder ('Symfony\Component\Security\Core\User\UserInterface ' )->getMock ();
112+
113+ $ token =$ this ->getMockBuilder ('Symfony\Component\Security\Core\Authentication\Token\TokenInterface ' )->getMock ();
114+ $ token ->expects ($ this ->any ())
115+ ->method ('getUser ' )
116+ ->will ($ this ->returnValue ('foo ' ));
117+
118+ $ authenticator =$ this ->getMockBuilder ('Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface ' )->getMock ();
119+ $ authenticator ->expects ($ this ->once ())
120+ ->method ('authenticateToken ' )
121+ ->will ($ this ->returnValue ($ token ));
122+
123+ $ userProvider =$ this ->getMockBuilder ('Symfony\Component\Security\Core\User\UserProviderInterface ' )->getMock ();
124+ $ userProvider ->expects ($ this ->once ())
125+ ->method ('loadUserByUsername ' )
126+ ->willReturn (null );
127+ $ provider =$ this ->getProvider ($ authenticator ,$ userProvider );
128+
129+ $ this ->assertSame ($ token ,$ provider ->authenticate ($ token ));
130+ }
131+
75132protected function getProvider ($ simpleAuthenticator =null ,$ userProvider =null ,$ userChecker =null ,$ key ='test ' )
76133 {
77134if (null ===$ userChecker ) {