Skip to content

Commit db2a934

Browse files
authored
Test coverage (#63)
* Update AuthServiceProvider.php * Update AppServiceProvider.php * Update EmailVerificationControllerTest.php * Update ResetPasswordController.php * Update ResetPasswordControllerTest.php * Update ResetPasswordController.php * Update EmailVerificationControllerTest.php
1 parent 06e5629 commit db2a934

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

app/Http/Controllers/ResetPasswordController.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ public function store(ResetPasswordStore $request)
2222
{
2323
$status = Password::sendResetLink($request->only('email'));
2424

25-
if ($status !== Password::RESET_LINK_SENT) {
26-
throw ValidationException::withMessages([
27-
'reset_link' => \__($status),
28-
]);
29-
}
25+
\throw_if($status !== Password::RESET_LINK_SENT, ValidationException::withMessages([
26+
'reset_link' => \__($status),
27+
]));
3028

3129
\session()->flash('success', \__('passwords.sent'));
3230

@@ -53,11 +51,9 @@ public function update(ResetPasswordUpdate $request)
5351
\event(new PasswordReset($user));
5452
});
5553

56-
if ($status !== Password::PASSWORD_RESET) {
57-
throw ValidationException::withMessages([
58-
'reset' => __($status),
59-
]);
60-
}
54+
\throw_if($status !== Password::PASSWORD_RESET, ValidationException::withMessages([
55+
'reset' => \__($status),
56+
]));
6157

6258
\session()->flash('success', \__('passwords.reset'));
6359

app/Providers/AppServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public function boot(): void
1414
{
1515
JsonResource::withoutWrapping();
1616

17+
// @codeCoverageIgnoreStart
1718
Carbon::macro('inAppTimezone', function () {
1819
return $this->tz(config('app.timezone_display'));
1920
});
@@ -22,7 +23,6 @@ public function boot(): void
2223
return $this->tz(auth()->user()?->timezone ?? config('app.timezone_display'));
2324
});
2425

25-
// @codeCoverageIgnoreStart
2626
Pulse::users(function ($ids) {
2727
return User::findMany($ids)->map(fn ($user) => [
2828
'id' => $user->id,

app/Providers/AuthServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ class AuthServiceProvider extends ServiceProvider
1111
{
1212
public function boot(): void
1313
{
14+
// @codeCoverageIgnoreStart
1415
Gate::define('viewPulse', function (User $user) {
1516
return $user->hasRole(Role::SUPER_ADMIN->value);
1617
});
18+
// @codeCoverageIgnoreEnd
1719
}
1820
}

tests/Feature/Controllers/EmailVerificationControllerTest.php

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

77
use function Pest\Laravel\actingAs;
88
use function Pest\Laravel\get;
9+
use function Pest\Laravel\withoutExceptionHandling;
910

1011
describe('Users', function () {
1112
test('Can access the verification page', function () {
@@ -17,6 +18,24 @@
1718
);
1819
});
1920

21+
test('Can verify their email address', function () {
22+
withoutExceptionHandling();
23+
24+
$user = User::factory()->unverified()->create();
25+
26+
expect($user->verified_at)->toBeNull();
27+
28+
actingAs($user)
29+
->withoutMiddleware(Illuminate\Routing\Middleware\ValidateSignature::class)
30+
->get(route('verification.verify', [
31+
'id' => $user->getKey(),
32+
'hash' => sha1($user->getEmailForVerification()),
33+
]))
34+
->assertRedirect(route('home'));
35+
36+
expect($user->refresh()->email_verified_at)->not()->toBeNull();
37+
});
38+
2039
test('Can send the verificaiton notice', function () {
2140
Notification::fake();
2241

tests/Feature/Controllers/ResetPasswordControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
);
2121
});
2222

23-
test('A password reset email can be sent', function () {
23+
test('A password reset email can be requested', function () {
2424
Notification::fake();
2525

2626
$user = User::factory()->create();

0 commit comments

Comments
 (0)