|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ikechukwukalu\Sanctumauthstarter\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
|
6
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase; |
|
7
|
|
|
use Illuminate\Support\Str; |
|
8
|
|
|
use Illuminate\Support\Facades\Hash; |
|
9
|
|
|
use Illuminate\Support\Facades\Notification; |
|
10
|
|
|
use Ikechukwukalu\Sanctumauthstarter\Models\TestUser; |
|
11
|
|
|
use Ikechukwukalu\Sanctumauthstarter\Notifications\PasswordChange; |
|
12
|
|
|
use Ikechukwukalu\Sanctumauthstarter\Notifications\UserLogin; |
|
13
|
|
|
use Ikechukwukalu\Sanctumauthstarter\Notifications\WelcomeUser; |
|
14
|
|
|
|
|
15
|
|
|
class NotificationsTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
use RefreshDatabase; |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
public function test_fires_user_notifications(): void |
|
20
|
|
|
{ |
|
21
|
|
|
Notification::fake(); |
|
22
|
|
|
|
|
23
|
|
|
Notification::assertNothingSent(); |
|
24
|
|
|
|
|
25
|
|
|
$user = TestUser::create([ |
|
26
|
|
|
'name' => str::random(), |
|
27
|
|
|
'email' => Str::random(40) . '@example.com', |
|
28
|
|
|
'password' => Hash::make('password') |
|
29
|
|
|
]); |
|
30
|
|
|
|
|
31
|
|
|
$this->actingAs($user); |
|
32
|
|
|
$user->notify(new PasswordChange()); |
|
33
|
|
|
$user->notify(new WelcomeUser($user)); |
|
34
|
|
|
|
|
35
|
|
|
$time = Carbon::now()->isoFormat('Do of MMMM YYYY, h:mm:ssa'); |
|
36
|
|
|
$user->notify(new UserLogin($time, [])); |
|
37
|
|
|
|
|
38
|
|
|
Notification::assertSentTo( |
|
39
|
|
|
[$user], PasswordChange::class |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
Notification::assertSentTo( |
|
43
|
|
|
[$user], WelcomeUser::class |
|
44
|
|
|
); |
|
45
|
|
|
|
|
46
|
|
|
Notification::assertSentTo( |
|
47
|
|
|
[$user], UserLogin::class |
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
|
|
Notification::assertCount(3); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|