Skip to content

Commit da3811f

Browse files
authored
Test Improvements (#263)
* wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> --------- Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent e0aa889 commit da3811f

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"illuminate/validation": "^9.21|^10.0|^11.0"
1818
},
1919
"require-dev": {
20-
"orchestra/testbench": "^7.0|^8.0|^9.0",
20+
"orchestra/testbench": "^7.35|^8.15|^9.0",
2121
"phpunit/phpunit": "^9.3|^10.4|^11.0"
2222
},
2323
"autoload": {

tests/AuthBackend/AuthenticatesUsersTest.php

+25-11
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33
namespace Laravel\Ui\Tests\AuthBackend;
44

55
use Illuminate\Auth\Events\Attempting;
6+
use Illuminate\Auth\Events\Logout;
67
use Illuminate\Foundation\Auth\AuthenticatesUsers;
8+
use Illuminate\Foundation\Testing\RefreshDatabase;
79
use Illuminate\Http\Request;
810
use Illuminate\Routing\Pipeline;
911
use Illuminate\Support\Facades\Auth;
1012
use Illuminate\Support\Facades\Event;
1113
use Illuminate\Testing\TestResponse;
1214
use Illuminate\Validation\ValidationException;
15+
use Orchestra\Testbench\Attributes\WithMigration;
1316
use Orchestra\Testbench\Factories\UserFactory;
1417
use Orchestra\Testbench\TestCase;
1518
use PHPUnit\Framework\Attributes\Test;
1619

20+
#[WithMigration]
1721
class AuthenticatesUsersTest extends TestCase
1822
{
19-
use AuthenticatesUsers;
23+
use AuthenticatesUsers, RefreshDatabase;
2024

2125
protected function tearDown(): void
2226
{
@@ -25,16 +29,6 @@ protected function tearDown(): void
2529
parent::tearDown();
2630
}
2731

28-
/**
29-
* Define database migrations.
30-
*
31-
* @return void
32-
*/
33-
protected function defineDatabaseMigrations()
34-
{
35-
$this->loadLaravelMigrations();
36-
}
37-
3832
#[Test]
3933
public function it_can_authenticate_a_user()
4034
{
@@ -58,6 +52,26 @@ public function it_can_authenticate_a_user()
5852
});
5953
}
6054

55+
#[Test]
56+
public function it_can_deauthenticate_a_user()
57+
{
58+
Event::fake();
59+
60+
$user = UserFactory::new()->create();
61+
62+
$this->actingAs($user);
63+
64+
$request = Request::create('/logout', 'POST', [], [], [], [
65+
'HTTP_ACCEPT' => 'application/json',
66+
]);
67+
68+
$response = $this->handleRequestUsing(
69+
$request, fn ($request) => $this->logout($request)
70+
)->assertStatus(204);
71+
72+
Event::assertDispatched(fn (Logout $event) => $user->is($event->user));
73+
}
74+
6175
#[Test]
6276
public function it_can_authenticate_a_user_with_remember_as_false()
6377
{

tests/AuthBackend/RegistersUsersTest.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,23 @@
44

55
use Illuminate\Foundation\Auth\RegistersUsers;
66
use Illuminate\Foundation\Auth\User;
7+
use Illuminate\Foundation\Testing\RefreshDatabase;
78
use Illuminate\Http\Request;
89
use Illuminate\Routing\Pipeline;
910
use Illuminate\Support\Facades\Auth;
1011
use Illuminate\Support\Facades\Hash;
1112
use Illuminate\Support\Facades\Validator;
1213
use Illuminate\Testing\TestResponse;
1314
use Illuminate\Validation\ValidationException;
15+
use Orchestra\Testbench\Attributes\WithMigration;
1416
use Orchestra\Testbench\Factories\UserFactory;
1517
use Orchestra\Testbench\TestCase;
1618
use PHPUnit\Framework\Attributes\Test;
1719

20+
#[WithMigration]
1821
class RegistersUsersTest extends TestCase
1922
{
20-
use RegistersUsers;
21-
22-
/**
23-
* Define database migrations.
24-
*
25-
* @return void
26-
*/
27-
protected function defineDatabaseMigrations()
28-
{
29-
$this->loadLaravelMigrations();
30-
}
23+
use RegistersUsers, RefreshDatabase;
3124

3225
#[Test]
3326
public function it_can_register_a_user()

0 commit comments

Comments
 (0)