Skip to content

Commit 3161157

Browse files
committed
feat: add pest
1 parent e256fd9 commit 3161157

11 files changed

+398
-353
lines changed

composer.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"nunomaduro/collision": "^8.6",
2626
"peckphp/peck": "^0.1.3",
2727
"pestphp/pest": "^3.8",
28+
"pestphp/pest-plugin-type-coverage": "^3.5",
2829
"phpstan/extension-installer": "^1.4",
2930
"phpstan/phpstan": "^2.1",
3031
"phpstan/phpstan-deprecation-rules": "^2.0",
@@ -78,6 +79,16 @@
7879
"@php artisan config:clear --ansi",
7980
"vendor/bin/pest"
8081
],
82+
"test:all": [
83+
"@test",
84+
"@test:types",
85+
"@test:coverage"
86+
],
87+
"test:strict": [
88+
"@test",
89+
"@test:types",
90+
"@test:mutate"
91+
],
8192
"prepare": "git config core.hookspath .githooks",
8293
"fmt": "vendor/bin/pint -vv",
8394
"fmt:test": "vendor/bin/pint --test",

composer.lock

Lines changed: 126 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Feature/Auth/AuthenticationTest.php

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,41 @@
55
namespace Tests\Feature\Auth;
66

77
use App\Models\User;
8-
use Illuminate\Foundation\Testing\RefreshDatabase;
9-
use Tests\TestCase;
108

11-
final class AuthenticationTest extends TestCase
12-
{
13-
use RefreshDatabase;
9+
it('can render the login screen', function (): void {
10+
$response = $this->get('/login');
1411

15-
public function test_login_screen_can_be_rendered(): void
16-
{
17-
$response = $this->get('/login');
12+
$response->assertStatus(200);
13+
});
1814

19-
$response->assertStatus(200);
20-
}
15+
it('can authenticate users using the login screen', function (): void {
16+
$user = User::factory()->create();
2117

22-
public function test_users_can_authenticate_using_the_login_screen(): void
23-
{
24-
$user = User::factory()->create();
18+
$response = $this->post('/login', [
19+
'email' => $user->email,
20+
'password' => 'password',
21+
]);
2522

26-
$response = $this->post('/login', [
27-
'email' => $user->email,
28-
'password' => 'password',
29-
]);
23+
$this->assertAuthenticated();
24+
$response->assertRedirect(route('dashboard', absolute: false));
25+
});
3026

31-
$this->assertAuthenticated();
32-
$response->assertRedirect(route('dashboard', absolute: false));
33-
}
27+
it('cannot authenticate users with invalid password', function (): void {
28+
$user = User::factory()->create();
3429

35-
public function test_users_can_not_authenticate_with_invalid_password(): void
36-
{
37-
$user = User::factory()->create();
30+
$this->post('/login', [
31+
'email' => $user->email,
32+
'password' => 'wrong-password',
33+
]);
3834

39-
$this->post('/login', [
40-
'email' => $user->email,
41-
'password' => 'wrong-password',
42-
]);
35+
$this->assertGuest();
36+
});
4337

44-
$this->assertGuest();
45-
}
38+
it('allows users to logout', function (): void {
39+
$user = User::factory()->create();
4640

47-
public function test_users_can_logout(): void
48-
{
49-
$user = User::factory()->create();
41+
$response = $this->actingAs($user)->post('/logout');
5042

51-
$response = $this->actingAs($user)->post('/logout');
52-
53-
$this->assertGuest();
54-
$response->assertRedirect('/');
55-
}
56-
}
43+
$this->assertGuest();
44+
$response->assertRedirect('/');
45+
});

tests/Feature/Auth/EmailVerificationTest.php

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,45 @@
66

77
use App\Models\User;
88
use Illuminate\Auth\Events\Verified;
9-
use Illuminate\Foundation\Testing\RefreshDatabase;
109
use Illuminate\Support\Facades\Event;
1110
use Illuminate\Support\Facades\URL;
12-
use Tests\TestCase;
1311

14-
final class EmailVerificationTest extends TestCase
15-
{
16-
use RefreshDatabase;
12+
it('can render the email verification screen', function (): void {
13+
$user = User::factory()->unverified()->create();
1714

18-
public function test_email_verification_screen_can_be_rendered(): void
19-
{
20-
$user = User::factory()->unverified()->create();
15+
$response = $this->actingAs($user)->get('/verify-email');
2116

22-
$response = $this->actingAs($user)->get('/verify-email');
17+
$response->assertStatus(200);
18+
});
2319

24-
$response->assertStatus(200);
25-
}
20+
it('can verify email', function (): void {
21+
$user = User::factory()->unverified()->create();
2622

27-
public function test_email_can_be_verified(): void
28-
{
29-
$user = User::factory()->unverified()->create();
23+
Event::fake();
3024

31-
Event::fake();
25+
$verificationUrl = URL::temporarySignedRoute(
26+
'verification.verify',
27+
now()->addMinutes(60),
28+
['id' => $user->id, 'hash' => sha1((string) $user->email)]
29+
);
3230

33-
$verificationUrl = URL::temporarySignedRoute(
34-
'verification.verify',
35-
now()->addMinutes(60),
36-
['id' => $user->id, 'hash' => sha1((string) $user->email)]
37-
);
31+
$response = $this->actingAs($user)->get($verificationUrl);
3832

39-
$response = $this->actingAs($user)->get($verificationUrl);
33+
Event::assertDispatched(Verified::class);
34+
$this->assertTrue($user->fresh()->hasVerifiedEmail());
35+
$response->assertRedirect(route('dashboard', absolute: false).'?verified=1');
36+
});
4037

41-
Event::assertDispatched(Verified::class);
42-
$this->assertTrue($user->fresh()->hasVerifiedEmail());
43-
$response->assertRedirect(route('dashboard', absolute: false).'?verified=1');
44-
}
38+
it('does not verify email with invalid hash', function (): void {
39+
$user = User::factory()->unverified()->create();
4540

46-
public function test_email_is_not_verified_with_invalid_hash(): void
47-
{
48-
$user = User::factory()->unverified()->create();
41+
$verificationUrl = URL::temporarySignedRoute(
42+
'verification.verify',
43+
now()->addMinutes(60),
44+
['id' => $user->id, 'hash' => sha1('wrong-email')]
45+
);
4946

50-
$verificationUrl = URL::temporarySignedRoute(
51-
'verification.verify',
52-
now()->addMinutes(60),
53-
['id' => $user->id, 'hash' => sha1('wrong-email')]
54-
);
47+
$this->actingAs($user)->get($verificationUrl);
5548

56-
$this->actingAs($user)->get($verificationUrl);
57-
58-
$this->assertFalse($user->fresh()->hasVerifiedEmail());
59-
}
60-
}
49+
$this->assertFalse($user->fresh()->hasVerifiedEmail());
50+
});

tests/Feature/Auth/PasswordConfirmationTest.php

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,32 @@
55
namespace Tests\Feature\Auth;
66

77
use App\Models\User;
8-
use Illuminate\Foundation\Testing\RefreshDatabase;
9-
use Tests\TestCase;
108

11-
final class PasswordConfirmationTest extends TestCase
12-
{
13-
use RefreshDatabase;
9+
it('can render the confirm password screen', function (): void {
10+
$user = User::factory()->create();
1411

15-
public function test_confirm_password_screen_can_be_rendered(): void
16-
{
17-
$user = User::factory()->create();
12+
$response = $this->actingAs($user)->get('/confirm-password');
1813

19-
$response = $this->actingAs($user)->get('/confirm-password');
14+
$response->assertStatus(200);
15+
});
2016

21-
$response->assertStatus(200);
22-
}
17+
it('can confirm password', function (): void {
18+
$user = User::factory()->create();
2319

24-
public function test_password_can_be_confirmed(): void
25-
{
26-
$user = User::factory()->create();
20+
$response = $this->actingAs($user)->post('/confirm-password', [
21+
'password' => 'password',
22+
]);
2723

28-
$response = $this->actingAs($user)->post('/confirm-password', [
29-
'password' => 'password',
30-
]);
24+
$response->assertRedirect();
25+
$response->assertSessionHasNoErrors();
26+
});
3127

32-
$response->assertRedirect();
33-
$response->assertSessionHasNoErrors();
34-
}
28+
it('does not confirm with invalid password', function (): void {
29+
$user = User::factory()->create();
3530

36-
public function test_password_is_not_confirmed_with_invalid_password(): void
37-
{
38-
$user = User::factory()->create();
31+
$response = $this->actingAs($user)->post('/confirm-password', [
32+
'password' => 'wrong-password',
33+
]);
3934

40-
$response = $this->actingAs($user)->post('/confirm-password', [
41-
'password' => 'wrong-password',
42-
]);
43-
44-
$response->assertSessionHasErrors();
45-
}
46-
}
35+
$response->assertSessionHasErrors();
36+
});

0 commit comments

Comments
 (0)