Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Improvements #263

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"illuminate/validation": "^9.21|^10.0|^11.0"
},
"require-dev": {
"orchestra/testbench": "^7.0|^8.0|^9.0",
"orchestra/testbench": "^7.35|^8.15|^9.0",
"phpunit/phpunit": "^9.3|^10.4|^11.0"
},
"autoload": {
Expand Down
36 changes: 25 additions & 11 deletions tests/AuthBackend/AuthenticatesUsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
namespace Laravel\Ui\Tests\AuthBackend;

use Illuminate\Auth\Events\Attempting;
use Illuminate\Auth\Events\Logout;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\Request;
use Illuminate\Routing\Pipeline;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Event;
use Illuminate\Testing\TestResponse;
use Illuminate\Validation\ValidationException;
use Orchestra\Testbench\Attributes\WithMigration;
use Orchestra\Testbench\Factories\UserFactory;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\Test;

#[WithMigration]
class AuthenticatesUsersTest extends TestCase
{
use AuthenticatesUsers;
use AuthenticatesUsers, RefreshDatabase;

protected function tearDown(): void
{
Expand All @@ -25,16 +29,6 @@ protected function tearDown(): void
parent::tearDown();
}

/**
* Define database migrations.
*
* @return void
*/
protected function defineDatabaseMigrations()
{
$this->loadLaravelMigrations();
}

#[Test]
public function it_can_authenticate_a_user()
{
Expand All @@ -58,6 +52,26 @@ public function it_can_authenticate_a_user()
});
}

#[Test]
public function it_can_deauthenticate_a_user()
{
Event::fake();

$user = UserFactory::new()->create();

$this->actingAs($user);

$request = Request::create('/logout', 'POST', [], [], [], [
'HTTP_ACCEPT' => 'application/json',
]);

$response = $this->handleRequestUsing(
$request, fn ($request) => $this->logout($request)
)->assertStatus(204);

Event::assertDispatched(fn (Logout $event) => $user->is($event->user));
}

#[Test]
public function it_can_authenticate_a_user_with_remember_as_false()
{
Expand Down
15 changes: 4 additions & 11 deletions tests/AuthBackend/RegistersUsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,23 @@

use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Foundation\Auth\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\Request;
use Illuminate\Routing\Pipeline;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Testing\TestResponse;
use Illuminate\Validation\ValidationException;
use Orchestra\Testbench\Attributes\WithMigration;
use Orchestra\Testbench\Factories\UserFactory;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\Test;

#[WithMigration]
class RegistersUsersTest extends TestCase
{
use RegistersUsers;

/**
* Define database migrations.
*
* @return void
*/
protected function defineDatabaseMigrations()
{
$this->loadLaravelMigrations();
}
use RegistersUsers, RefreshDatabase;

#[Test]
public function it_can_register_a_user()
Expand Down