Skip to content

Commit 9b7977e

Browse files
committed
updated tests to use pest and installed pest
1 parent cb3c72a commit 9b7977e

13 files changed

+199
-295
lines changed

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"homepage": "https://github.com/dcblogdev/laravel-admintw",
1313
"require": {
14-
"php": "^7.4|^8.0",
14+
"php": "^8.0",
1515
"christophrumpel/missing-livewire-assertions": "^0.3.3",
1616
"illuminate/filesystem": "^8.0",
1717
"illuminate/support": "^8.12",
@@ -25,7 +25,13 @@
2525
"fakerphp/faker": "^1.9.1",
2626
"mockery/mockery": "^1.4.2",
2727
"nunomaduro/collision": "^5.0",
28-
"phpunit/phpunit": "^9.3.3"
28+
"pestphp/pest": "^1.17",
29+
"pestphp/pest-plugin-faker": "^1.0",
30+
"pestphp/pest-plugin-global-assertions": "^1.0",
31+
"pestphp/pest-plugin-laravel": "^1.1",
32+
"pestphp/pest-plugin-mock": "^1.0",
33+
"pestphp/pest-plugin-parallel": "^0.3.0",
34+
"phpunit/phpunit": "^9.5.8"
2935
},
3036
"autoload": {
3137
"psr-4": {
Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
11
<?php
22

3-
namespace Tests\Feature\App;
4-
5-
use Tests\TestCase;
6-
7-
class DashboardTest extends TestCase
8-
{
9-
/** @test **/
10-
public function can_see_dashboard_when_authenticated(): void
11-
{
12-
$this->authenticate();
13-
14-
$response = $this->get(route('app'));
15-
$response->assertStatus(200);
16-
}
17-
18-
/** @test **/
19-
public function is_redirected_when_not_authenticated(): void
20-
{
21-
$response = $this->get(route('app'));
22-
$response->assertStatus(302);
23-
}
24-
}
3+
test('can see dashboard when authenticated', function() {
4+
$this->authenticate();
5+
$this->get(route('app'))->assertOk();
6+
});
7+
8+
test('is redirected when not authenticated', function(){
9+
$this->get(route('app'))->assertRedirect();
10+
});

stubs/tests/Feature/App/UserTest.php

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
11
<?php
22

3-
namespace Tests\Feature\App;
4-
5-
use Tests\TestCase;
6-
7-
class UserTest extends TestCase
8-
{
9-
/** @test **/
10-
public function can_see_edit_page(): void
11-
{
12-
$this->authenticate();
13-
14-
$response = $this->get(route('app.users.edit'));
15-
$response->assertStatus(200);
16-
}
17-
18-
/** @test **/
19-
public function is_redirected_when_not_authenticated(): void
20-
{
21-
$response = $this->get(route('app.users.edit'));
22-
$response->assertStatus(302);
23-
}
24-
}
3+
test('can see edit user page', function(){
4+
$this->authenticate();
5+
$this->get(route('app.users.edit'))->assertOk();
6+
});
7+
8+
test('is redirected when not authenticated', function(){
9+
$this->get(route('app.users.edit'))->assertRedirect();
10+
});
Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,12 @@
11
<?php
22

3-
namespace Tests\Feature\Auth;
4-
53
use App\Models\User;
64
use App\Providers\RouteServiceProvider;
7-
use Illuminate\Foundation\Testing\RefreshDatabase;
8-
use Tests\TestCase;
9-
10-
class AuthenticationTest extends TestCase
11-
{
12-
use RefreshDatabase;
135

14-
/** @test **/
15-
public function login_screen_can_be_rendered(): void
16-
{
17-
$response = $this->get('/login');
6+
test('can see login page')->get('login')->assertOk();
187

19-
$response->assertStatus(200);
20-
}
21-
22-
/** @test **/
23-
public function users_can_authenticate_using_the_login_screen(): void
24-
{
25-
$user = User::factory()->create();
8+
test('can authenticate', function(){
9+
$user = User::factory()->create();
2610

2711
$response = $this->post('/login', [
2812
'email' => $user->email,
@@ -31,18 +15,15 @@ public function users_can_authenticate_using_the_login_screen(): void
3115

3216
$this->assertAuthenticated();
3317
$response->assertRedirect(RouteServiceProvider::HOME);
34-
}
18+
});
3519

36-
/** @test **/
37-
public function users_can_not_authenticate_with_invalid_password(): void
38-
{
39-
$user = User::factory()->create();
20+
test('cannot authenticate with invalid password', function(){
21+
$user = User::factory()->create();
4022

41-
$this->post('/login', [
23+
$response = $this->post('/login', [
4224
'email' => $user->email,
4325
'password' => 'wrong-password',
4426
]);
4527

4628
$this->assertGuest();
47-
}
48-
}
29+
});
Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,53 @@
11
<?php
22

3-
namespace Tests\Feature\Auth;
4-
53
use App\Models\User;
64
use App\Providers\RouteServiceProvider;
75
use Illuminate\Auth\Events\Verified;
8-
use Illuminate\Foundation\Testing\RefreshDatabase;
96
use Illuminate\Support\Facades\Event;
107
use Illuminate\Support\Facades\URL;
11-
use Tests\TestCase;
12-
13-
class EmailVerificationTest extends TestCase
14-
{
15-
use RefreshDatabase;
168

17-
/** @test **/
18-
public function email_verification_screen_can_be_rendered(): void
19-
{
20-
$user = User::factory()->create([
21-
'email_verified_at' => null,
22-
]);
9+
test('email verification screen can be rendered', function () {
10+
$user = User::factory()->create([
11+
'email_verified_at' => null,
12+
]);
2313

24-
$response = $this->actingAs($user)->get('/verify-email');
14+
$response = $this->actingAs($user)->get('/verify-email');
2515

26-
$response->assertStatus(200);
27-
}
16+
$response->assertStatus(200);
17+
});
2818

29-
/** @test **/
30-
public function email_can_be_verified(): void
31-
{
32-
Event::fake();
19+
test('email can be verified', function () {
20+
Event::fake();
3321

34-
$user = User::factory()->create([
35-
'email_verified_at' => null,
36-
]);
22+
$user = User::factory()->create([
23+
'email_verified_at' => null,
24+
]);
3725

38-
$verificationUrl = URL::temporarySignedRoute(
39-
'verification.verify',
40-
now()->addMinutes(60),
41-
['id' => $user->id, 'hash' => sha1($user->email)]
42-
);
26+
$verificationUrl = URL::temporarySignedRoute(
27+
'verification.verify',
28+
now()->addMinutes(60),
29+
['id' => $user->id, 'hash' => sha1($user->email)]
30+
);
4331

44-
$response = $this->actingAs($user)->get($verificationUrl);
32+
$response = $this->actingAs($user)->get($verificationUrl);
4533

46-
Event::assertDispatched(Verified::class);
47-
$this->assertTrue($user->fresh()->hasVerifiedEmail());
48-
$response->assertRedirect(RouteServiceProvider::HOME.'?verified=1');
49-
}
34+
Event::assertDispatched(Verified::class);
35+
$this->assertTrue($user->fresh()->hasVerifiedEmail());
36+
$response->assertRedirect(RouteServiceProvider::HOME.'?verified=1');
37+
});
5038

51-
/** @test **/
52-
public function email_is_not_verified_with_invalid_hash(): void
53-
{
54-
$user = User::factory()->create([
55-
'email_verified_at' => null,
56-
]);
39+
test('email is not verified with invalid hash', function () {
40+
$user = User::factory()->create([
41+
'email_verified_at' => null,
42+
]);
5743

58-
$verificationUrl = URL::temporarySignedRoute(
59-
'verification.verify',
60-
now()->addMinutes(60),
61-
['id' => $user->id, 'hash' => sha1('wrong-email')]
62-
);
44+
$verificationUrl = URL::temporarySignedRoute(
45+
'verification.verify',
46+
now()->addMinutes(60),
47+
['id' => $user->id, 'hash' => sha1('wrong-email')]
48+
);
6349

64-
$this->actingAs($user)->get($verificationUrl);
50+
$this->actingAs($user)->get($verificationUrl);
6551

66-
$this->assertFalse($user->fresh()->hasVerifiedEmail());
67-
}
68-
}
52+
$this->assertFalse($user->fresh()->hasVerifiedEmail());
53+
});
Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,34 @@
11
<?php
22

3-
namespace Tests\Feature\Auth;
4-
53
use App\Models\User;
64
use Illuminate\Foundation\Testing\RefreshDatabase;
75
use Tests\TestCase;
86

9-
class PasswordConfirmationTest extends TestCase
10-
{
11-
use RefreshDatabase;
12-
13-
/** @test **/
14-
public function confirm_password_screen_can_be_rendered(): void
15-
{
16-
$user = User::factory()->create();
7+
test('confirm password screen can be rendered', function () {
8+
$user = User::factory()->create();
179

18-
$response = $this->actingAs($user)->get('/confirm-password');
10+
$response = $this->actingAs($user)->get('/confirm-password');
1911

20-
$response->assertStatus(200);
21-
}
12+
$response->assertStatus(200);
13+
});
2214

23-
/** @test **/
24-
public function password_can_be_confirmed(): void
25-
{
26-
$user = User::factory()->create();
15+
test('password can be confirmed', function () {
16+
$user = User::factory()->create();
2717

28-
$response = $this->actingAs($user)->post('/confirm-password', [
29-
'password' => 'password',
30-
]);
18+
$response = $this->actingAs($user)->post('/confirm-password', [
19+
'password' => 'password',
20+
]);
3121

32-
$response->assertRedirect();
33-
$response->assertSessionHasNoErrors();
34-
}
22+
$response->assertRedirect();
23+
$response->assertSessionHasNoErrors();
24+
});
3525

36-
/** @test **/
37-
public function password_is_not_confirmed_with_invalid_password(): void
38-
{
39-
$user = User::factory()->create();
26+
test('password is not confirmed with invalid password', function () {
27+
$user = User::factory()->create();
4028

41-
$response = $this->actingAs($user)->post('/confirm-password', [
42-
'password' => 'wrong-password',
43-
]);
29+
$response = $this->actingAs($user)->post('/confirm-password', [
30+
'password' => 'wrong-password',
31+
]);
4432

45-
$response->assertSessionHasErrors();
46-
}
47-
}
33+
$response->assertInvalid();
34+
});

0 commit comments

Comments
 (0)