1616
1717class UserManagerTest extends TestCase
1818{
19- /**
20- * @var UserManager
21- */
19+ /** @var UserManager|\PHPUnit_Framework_MockObject_MockObject */
2220 private $ manager ;
21+
22+ /** @var \PHPUnit_Framework_MockObject_MockObject */
2323 private $ passwordUpdater ;
24+
25+ /** @var \PHPUnit_Framework_MockObject_MockObject */
2426 private $ fieldsUpdater ;
2527
2628 protected function setUp ()
@@ -127,7 +129,8 @@ public function testFindUserByUsernameOrEmailWithEmail()
127129 {
128130 $ this ->manager ->expects ($ this ->once ())
129131 ->method ('findUserBy ' )
130- ->with ($ this ->equalTo (array ('emailCanonical ' => 'jack@email.org ' )));
132+ ->with ($ this ->equalTo (array ('emailCanonical ' => 'jack@email.org ' )))
133+ ->willReturn ($ this ->getUser ());
131134 $ this ->fieldsUpdater ->expects ($ this ->once ())
132135 ->method ('canonicalizeEmail ' )
133136 ->with ('JaCk@EmAiL.oRg ' )
@@ -136,6 +139,34 @@ public function testFindUserByUsernameOrEmailWithEmail()
136139 $ this ->manager ->findUserByUsernameOrEmail ('JaCk@EmAiL.oRg ' );
137140 }
138141
142+ public function testFindUserByUsernameOrEmailWithUsernameThatLooksLikeEmail ()
143+ {
144+ $ usernameThatLooksLikeEmail = 'bob@example.com ' ;
145+ $ user = $ this ->getUser ();
146+
147+ $ this ->manager ->expects ($ this ->at (0 ))
148+ ->method ('findUserBy ' )
149+ ->with ($ this ->equalTo (array ('emailCanonical ' => $ usernameThatLooksLikeEmail )))
150+ ->will ($ this ->returnValue (null ));
151+ $ this ->fieldsUpdater ->expects ($ this ->once ())
152+ ->method ('canonicalizeEmail ' )
153+ ->with ($ usernameThatLooksLikeEmail )
154+ ->willReturn ($ usernameThatLooksLikeEmail );
155+
156+ $ this ->manager ->expects ($ this ->at (1 ))
157+ ->method ('findUserBy ' )
158+ ->with ($ this ->equalTo (array ('usernameCanonical ' => $ usernameThatLooksLikeEmail )))
159+ ->will ($ this ->returnValue ($ user ));
160+ $ this ->fieldsUpdater ->expects ($ this ->once ())
161+ ->method ('canonicalizeUsername ' )
162+ ->with ($ usernameThatLooksLikeEmail )
163+ ->willReturn ($ usernameThatLooksLikeEmail );
164+
165+ $ actualUser = $ this ->manager ->findUserByUsernameOrEmail ($ usernameThatLooksLikeEmail );
166+
167+ $ this ->assertSame ($ user , $ actualUser );
168+ }
169+
139170 /**
140171 * @return mixed
141172 */
0 commit comments