Skip to content

Commit ffb15c2

Browse files
authored
Continued Pest mutation testing (#79)
* Add mutation test coverage for `AccountController` * Add mutation test coverage for `DashboardController` * Add mutation test coverage for `LogoutController` * Add missing bits * Update composer.json * Update ResetPasswordControllerTest.php * Update EmailVerificationControllerTest.php * Update Pest to v3.1.0 * Replace `covers()` with `mutates()` * Update composer.json
1 parent 7fe4f01 commit ffb15c2

12 files changed

+144
-116
lines changed

app/Http/Controllers/LoginController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public function store(LoginStoreRequest $request)
2727
])
2828
);
2929

30+
session()->regenerate();
31+
3032
if ($request->validated('redirect')) {
3133
return redirect()->to($request->validated('redirect'));
3234
}

app/Http/Controllers/LogoutController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public function __invoke(Request $request)
1010
{
1111
auth()->guard()->logout();
1212

13-
$request->session()->invalidate();
14-
$request->session()->regenerateToken();
13+
session()->regenerateToken();
14+
session()->invalidate();
1515

1616
return redirect()->route('login');
1717
}

app/Http/Controllers/ResetPasswordController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public function store(ResetPasswordStoreRequest $request)
2626
'reset_link' => __($status),
2727
]));
2828

29+
session()->regenerate();
30+
2931
session()->flash('success', __('passwords.sent'));
3032

3133
return redirect()->route('login');

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
"test:coverage": [
6969
"XDEBUG_MODE=coverage ./vendor/bin/pest --parallel --stop-on-failure --coverage --min=85"
7070
],
71+
"test:mutations": [
72+
"XDEBUG_MODE=coverage ./vendor/bin/pest --mutate"
73+
],
7174
"artisan:build": [
7275
"@php artisan horizon:terminate",
7376
"@php artisan cache:clear",

composer.lock

Lines changed: 114 additions & 112 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Feature/Controllers/AccountControllerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use function Pest\Laravel\get;
1010
use function Pest\Laravel\patch;
1111

12+
mutates(\App\Http\Controllers\AccountController::class);
13+
1214
describe('Users', function () {
1315
test('Can access the edit page', function () {
1416
$user = User::factory()->create();

tests/Feature/Controllers/HomeControllerTest.php renamed to tests/Feature/Controllers/DashboardControllerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use function Pest\Laravel\actingAs;
77
use function Pest\Laravel\get;
88

9+
mutates(\App\Http\Controllers\DashboardController::class);
10+
911
describe('Users', function () {
1012
test('Can access the home page', function () {
1113
actingAs(User::factory()->create())

tests/Feature/Controllers/EmailVerificationControllerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use function Pest\Laravel\actingAs;
88
use function Pest\Laravel\get;
99

10+
mutates(\App\Http\Controllers\EmailVerificationController::class);
11+
1012
describe('Users', function () {
1113
test('Can access the verification page', function () {
1214
actingAs(User::factory()->unverified()->create())

tests/Feature/Controllers/LoginControllerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use function Pest\Laravel\get;
1212
use function Pest\Laravel\post;
1313

14+
mutates(App\Http\Controllers\LoginController::class);
15+
1416
describe('Users', function () {
1517
test("Can't access the login page", function () {
1618
actingAs(User::factory()->create())

tests/Feature/Controllers/LogoutControllerTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,28 @@
33
use App\Models\User;
44

55
use function Pest\Laravel\actingAs;
6-
use function Pest\Laravel\assertAuthenticated;
76
use function Pest\Laravel\assertGuest;
87
use function Pest\Laravel\post;
98

9+
mutates(\App\Http\Controllers\LogoutController::class);
10+
1011
describe('Users', function () {
1112
test('Can logout', function () {
13+
session()->regenerateToken();
14+
1215
actingAs(User::factory()->create());
1316

14-
assertAuthenticated();
17+
$token = session()->token();
18+
session()->put('test', 'data');
1519

1620
post(route('logout'))
1721
->assertSessionDoesntHaveErrors()
1822
->assertRedirectToRoute('login');
1923

2024
assertGuest();
25+
26+
expect(session()->token())->not->toEqual($token);
27+
expect(session()->get('test'))->toBeNull();
2128
});
2229
});
2330

tests/Feature/Controllers/RegisterControllerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use function Pest\Laravel\get;
1313
use function Pest\Laravel\post;
1414

15+
mutates(App\Http\Controllers\RegisterController::class);
16+
1517
describe('Users', function () {
1618
test("Can't access the register page", function () {
1719
actingAs(User::factory()->create())

tests/Feature/Controllers/ResetPasswordControllerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use function Pest\Laravel\get;
1212
use function Pest\Laravel\patch;
1313

14+
mutates(\App\Http\Controllers\ResetPasswordController::class);
15+
1416
test('The forgot password page can be accessed', function () {
1517
get(route('password'))
1618
->assertOk()

0 commit comments

Comments
 (0)