@@ -119,7 +119,7 @@ public function testLoadUserByUsernameFailsIfMoreThanOneLdapPasswordsInEntry()
119119 ;
120120 $ ldap = $ this ->getMockBuilder (LdapInterface::class)->getMock ();
121121 $ result
122- ->expects ($ this ->exactly ( 2 ))
122+ ->expects ($ this ->once ( ))
123123 ->method ('offsetGet ' )
124124 ->with (0 )
125125 ->will ($ this ->returnValue (new Entry ('foo ' , array (
@@ -151,6 +151,48 @@ public function testLoadUserByUsernameFailsIfMoreThanOneLdapPasswordsInEntry()
151151 );
152152 }
153153
154+ /**
155+ * @expectedException \Symfony\Component\Security\Core\Exception\InvalidArgumentException
156+ */
157+ public function testLoadUserByUsernameFailsIfEntryHasNoUidKeyAttribute ()
158+ {
159+ $ result = $ this ->getMock (CollectionInterface::class);
160+ $ query = $ this ->getMock (QueryInterface::class);
161+ $ query
162+ ->expects ($ this ->once ())
163+ ->method ('execute ' )
164+ ->will ($ this ->returnValue ($ result ))
165+ ;
166+ $ ldap = $ this ->getMock (LdapInterface::class);
167+ $ result
168+ ->expects ($ this ->once ())
169+ ->method ('offsetGet ' )
170+ ->with (0 )
171+ ->will ($ this ->returnValue (new Entry ('foo ' , array ())))
172+ ;
173+ $ result
174+ ->expects ($ this ->once ())
175+ ->method ('count ' )
176+ ->will ($ this ->returnValue (1 ))
177+ ;
178+ $ ldap
179+ ->expects ($ this ->once ())
180+ ->method ('escape ' )
181+ ->will ($ this ->returnValue ('foo ' ))
182+ ;
183+ $ ldap
184+ ->expects ($ this ->once ())
185+ ->method ('query ' )
186+ ->will ($ this ->returnValue ($ query ))
187+ ;
188+
189+ $ provider = new LdapUserProvider ($ ldap , 'ou=MyBusiness,dc=symfony,dc=com ' , null , null , array (), 'sAMAccountName ' , '({uid_key}={username}) ' );
190+ $ this ->assertInstanceOf (
191+ 'Symfony\Component\Security\Core\User\User ' ,
192+ $ provider ->loadUserByUsername ('foo ' )
193+ );
194+ }
195+
154196 /**
155197 * @expectedException \Symfony\Component\Security\Core\Exception\InvalidArgumentException
156198 */
@@ -165,7 +207,7 @@ public function testLoadUserByUsernameFailsIfEntryHasNoPasswordAttribute()
165207 ;
166208 $ ldap = $ this ->getMockBuilder (LdapInterface::class)->getMock ();
167209 $ result
168- ->expects ($ this ->exactly ( 2 ))
210+ ->expects ($ this ->once ( ))
169211 ->method ('offsetGet ' )
170212 ->with (0 )
171213 ->will ($ this ->returnValue (new Entry ('foo ' , array (
@@ -207,7 +249,7 @@ public function testLoadUserByUsernameIsSuccessfulWithoutPasswordAttribute()
207249 ;
208250 $ ldap = $ this ->getMockBuilder (LdapInterface::class)->getMock ();
209251 $ result
210- ->expects ($ this ->exactly ( 2 ))
252+ ->expects ($ this ->once ( ))
211253 ->method ('offsetGet ' )
212254 ->with (0 )
213255 ->will ($ this ->returnValue (new Entry ('foo ' , array (
@@ -249,7 +291,7 @@ public function testLoadUserByUsernameIsSuccessfulWithoutPasswordAttributeAndWro
249291 ;
250292 $ ldap = $ this ->getMockBuilder (LdapInterface::class)->getMock ();
251293 $ result
252- ->expects ($ this ->exactly ( 2 ))
294+ ->expects ($ this ->once ( ))
253295 ->method ('offsetGet ' )
254296 ->with (0 )
255297 ->will ($ this ->returnValue (new Entry ('foo ' , array (
@@ -288,7 +330,7 @@ public function testLoadUserByUsernameIsSuccessfulWithPasswordAttribute()
288330 ;
289331 $ ldap = $ this ->getMock (LdapInterface::class);
290332 $ result
291- ->expects ($ this ->exactly ( 2 ))
333+ ->expects ($ this ->once ( ))
292334 ->method ('offsetGet ' )
293335 ->with (0 )
294336 ->will ($ this ->returnValue (new Entry ('foo ' , array (
0 commit comments