11<?php
22
33use Illuminate \Auth \Passwords \PasswordBroker ;
4- use Illuminate \Foundation \Application ;
54use MongoDB \BSON \UTCDateTime ;
65
76class AuthTest extends TestCase
@@ -10,55 +9,56 @@ public function tearDown(): void
109 {
1110 parent ::setUp ();
1211 User::truncate ();
13- DB ::collection ('password_reminders ' )->truncate ();
12+ DB ::collection ('password_reset_tokens ' )->truncate ();
1413 }
1514
1615 public function testAuthAttempt ()
1716 {
1817 User::create ([
1918 'name ' => 'John Doe ' ,
20- 'email ' => 'john@ doe.com ' ,
19+ 'email ' => 'john. doe@example .com ' ,
2120 'password ' => Hash::make ('foobar ' ),
2221 ]);
2322
24- $ this ->assertTrue (Auth::attempt (['email ' => 'john@ doe.com ' , 'password ' => 'foobar ' ], true ));
23+ $ this ->assertTrue (Auth::attempt (['email ' => 'john. doe@example .com ' , 'password ' => 'foobar ' ], true ));
2524 $ this ->assertTrue (Auth::check ());
2625 }
2726
2827 public function testRemindOld ()
2928 {
30- if (Application::VERSION >= '5.2 ' ) {
31- $ this ->expectNotToPerformAssertions ();
32-
33- return ;
34- }
35-
36- $ mailer = Mockery::mock ('Illuminate\Mail\Mailer ' );
37- $ tokens = $ this ->app ->make ('auth.password.tokens ' );
38- $ users = $ this ->app ['auth ' ]->driver ()->getProvider ();
39-
40- $ broker = new PasswordBroker ($ tokens , $ users , $ mailer , '' );
29+ $ broker = $ this ->app ->make ('auth.password.broker ' );
4130
4231 $ user = User::create ([
4332 'name ' => 'John Doe ' ,
44- 'email ' => 'john@ doe.com ' ,
33+ 'email ' => 'john. doe@example .com ' ,
4534 'password ' => Hash::make ('foobar ' ),
4635 ]);
4736
48- $ mailer ->shouldReceive ('send ' )->once ();
49- $ broker ->sendResetLink (['email ' => 'john@doe.com ' ]);
37+ $ token = null ;
38+
39+ $ this ->assertSame (
40+ PasswordBroker::RESET_LINK_SENT ,
41+ $ broker ->sendResetLink (
42+ ['email ' => 'john.doe@example.com ' ],
43+ function ($ actualUser , $ actualToken ) use ($ user , &$ token ) {
44+ $ this ->assertEquals ($ user ->_id , $ actualUser ->_id );
45+ // Store token for later use
46+ $ token = $ actualToken ;
47+ }
48+ )
49+ );
5050
51- $ this ->assertEquals (1 , DB ::collection ('password_resets ' )->count ());
52- $ reminder = DB ::collection ('password_resets ' )->first ();
53- $ this ->assertEquals ('john@ doe.com ' , $ reminder ['email ' ]);
51+ $ this ->assertEquals (1 , DB ::collection ('password_reset_tokens ' )->count ());
52+ $ reminder = DB ::collection ('password_reset_tokens ' )->first ();
53+ $ this ->assertEquals ('john. doe@example .com ' , $ reminder ['email ' ]);
5454 $ this ->assertNotNull ($ reminder ['token ' ]);
5555 $ this ->assertInstanceOf (UTCDateTime::class, $ reminder ['created_at ' ]);
5656
5757 $ credentials = [
58- 'email ' => 'john@ doe.com ' ,
58+ 'email ' => 'john. doe@example .com ' ,
5959 'password ' => 'foobar ' ,
6060 'password_confirmation ' => 'foobar ' ,
61- 'token ' => $ reminder [ ' token ' ] ,
61+ 'token ' => $ token ,
6262 ];
6363
6464 $ response = $ broker ->reset ($ credentials , function ($ user , $ password ) {
0 commit comments