1
1
<?php
2
2
3
3
use Illuminate \Auth \Passwords \PasswordBroker ;
4
- use Illuminate \Foundation \Application ;
5
4
use MongoDB \BSON \UTCDateTime ;
6
5
7
6
class AuthTest extends TestCase
@@ -10,55 +9,56 @@ public function tearDown(): void
10
9
{
11
10
parent ::setUp ();
12
11
User::truncate ();
13
- DB ::collection ('password_reminders ' )->truncate ();
12
+ DB ::collection ('password_reset_tokens ' )->truncate ();
14
13
}
15
14
16
15
public function testAuthAttempt ()
17
16
{
18
17
User::create ([
19
18
'name ' => 'John Doe ' ,
20
- 'email ' => 'john@ doe.com ' ,
19
+ 'email ' => 'john. doe@example .com ' ,
21
20
'password ' => Hash::make ('foobar ' ),
22
21
]);
23
22
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 ));
25
24
$ this ->assertTrue (Auth::check ());
26
25
}
27
26
28
27
public function testRemindOld ()
29
28
{
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 ' );
41
30
42
31
$ user = User::create ([
43
32
'name ' => 'John Doe ' ,
44
- 'email ' => 'john@ doe.com ' ,
33
+ 'email ' => 'john. doe@example .com ' ,
45
34
'password ' => Hash::make ('foobar ' ),
46
35
]);
47
36
48
- $ mailer ->shouldReceive ('send ' )->once ();
49
- $ broker->
sendResetLink ([
'email ' =>
'[email protected] ' ]);
37
+ $ token = null ;
38
+
39
+ $ this ->assertSame (
40
+ PasswordBroker::RESET_LINK_SENT ,
41
+ $ broker ->sendResetLink (
42
+
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
+ );
50
50
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 ' ]);
54
54
$ this ->assertNotNull ($ reminder ['token ' ]);
55
55
$ this ->assertInstanceOf (UTCDateTime::class, $ reminder ['created_at ' ]);
56
56
57
57
$ credentials = [
58
- 'email ' => 'john@ doe.com ' ,
58
+ 'email ' => 'john. doe@example .com ' ,
59
59
'password ' => 'foobar ' ,
60
60
'password_confirmation ' => 'foobar ' ,
61
- 'token ' => $ reminder [ ' token ' ] ,
61
+ 'token ' => $ token ,
62
62
];
63
63
64
64
$ response = $ broker ->reset ($ credentials , function ($ user , $ password ) {
0 commit comments