Skip to content

Commit ba66a4e

Browse files
committed
Fix auth test for Laravel 10
1 parent 02df6cb commit ba66a4e

File tree

3 files changed

+25
-47
lines changed

3 files changed

+25
-47
lines changed

src/Auth/PasswordBrokerManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ protected function createTokenRepository(array $config)
1616
$this->app['hash'],
1717
$config['table'],
1818
$this->app['config']['app.key'],
19-
$config['expire']
19+
$config['expire'],
20+
$config['throttle'] ?? 0
2021
);
2122
}
2223
}

src/Auth/PasswordResetServiceProvider.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,6 @@
66

77
class PasswordResetServiceProvider extends BasePasswordResetServiceProvider
88
{
9-
/**
10-
* Register the token repository implementation.
11-
*
12-
* @return void
13-
*/
14-
protected function registerTokenRepository()
15-
{
16-
$this->app->singleton('auth.password.tokens', function ($app) {
17-
$connection = $app['db']->connection();
18-
19-
// The database token repository is an implementation of the token repository
20-
// interface, and is responsible for the actual storing of auth tokens and
21-
// their e-mail addresses. We will inject this table and hash key to it.
22-
$table = $app['config']['auth.password.table'];
23-
24-
$key = $app['config']['app.key'];
25-
26-
$expire = $app['config']->get('auth.password.expire', 60);
27-
28-
return new DatabaseTokenRepository($connection, $table, $key, $expire);
29-
});
30-
}
31-
329
/**
3310
* @inheritdoc
3411
*/

tests/AuthTest.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22

33
use Illuminate\Auth\Passwords\PasswordBroker;
4-
use Illuminate\Foundation\Application;
54
use MongoDB\BSON\UTCDateTime;
65

76
class 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' => '[email protected]']);
37+
$token = null;
38+
39+
$this->assertSame(
40+
PasswordBroker::RESET_LINK_SENT,
41+
$broker->sendResetLink(
42+
['email' => '[email protected]'],
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

Comments
 (0)