@@ -140,6 +140,43 @@ public function test_can_validate_credentials()
140
140
));
141
141
}
142
142
143
+ public function test_rehash_password_if_required_rehash ()
144
+ {
145
+ $ user = new AuthenticableMock ;
146
+
147
+ $ this ->hasher ->shouldReceive ('needsRehash ' )->once ()->andReturn (true );
148
+ $ this ->hasher ->shouldReceive ('make ' )->once ()->andReturn ('hashedPassword ' );
149
+ $ this ->em ->shouldReceive ('persist ' )->once ();
150
+ $ this ->em ->shouldReceive ('flush ' )->once ();
151
+
152
+ $ this ->provider ->rehashPasswordIfRequired ($ user , ['password ' => 'rawPassword ' ], false );
153
+ $ this ->assertEquals ('hashedPassword ' , $ user ->getPassword ());
154
+ }
155
+
156
+ public function test_rehash_password_if_required_rehash_force ()
157
+ {
158
+ $ user = new AuthenticableMock ;
159
+
160
+ $ this ->hasher ->shouldReceive ('needsRehash ' )->once ()->andReturn (false );
161
+ $ this ->hasher ->shouldReceive ('make ' )->once ()->andReturn ('hashedPassword ' );
162
+ $ this ->em ->shouldReceive ('persist ' )->once ();
163
+ $ this ->em ->shouldReceive ('flush ' )->once ();
164
+
165
+ $ this ->provider ->rehashPasswordIfRequired ($ user , ['password ' => 'rawPassword ' ], true );
166
+ $ this ->assertEquals ('hashedPassword ' , $ user ->getPassword ());
167
+ }
168
+
169
+ public function test_rehash_password_if_required_rehash_norehash_needed ()
170
+ {
171
+ $ user = new AuthenticableMock ;
172
+ $ user ->setPassword ('originalPassword ' );
173
+
174
+ $ this ->hasher ->shouldReceive ('needsRehash ' )->once ()->andReturn (false );
175
+
176
+ $ this ->provider ->rehashPasswordIfRequired ($ user , ['password ' => 'rawPassword ' ], false );
177
+ $ this ->assertEquals ('originalPassword ' , $ user ->getPassword ());
178
+ }
179
+
143
180
protected function mockGetRepository ($ class = AuthenticableMock::class)
144
181
{
145
182
$ this ->em ->shouldReceive ('getRepository ' )
0 commit comments