1. Go to this page and download the library: Download supaapps/supaapps-guard library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Tests\TestCase;
use Supaapps\Guard\Tests\Concerns\GenerateJwtToken;
class CustomTest extends TestCase
{
use GenerateJwtToken;
public function testThatIAmActingAsUser(): void
{
$user = User::factory()->create();
$this->withAccessTokenFor($user);
$this->assertTrue(auth('jwt')->check());
$this->assertTrue($user->id, auth('jwt')->id());
}
}
use Supaapps\Guard\Tests\Concerns\GenerateJwtToken;
trait CreatesApplication
{
use GenerateJwtToken;
public function createApplication(): Application
{
...
$this->setAuthServerUrl();
return $app;
}
}
namespace Tests\Feature;
use Tests\TestCase;
class CustomTest extends TestCase
{
public function itReturnsTheAuthUser(): void
{
$user = User::factory()->create();
$this->withAccessTokenFor($user);
// assume you have /user endpoint that
// - uses auth:jwt middleware
// - and returns auth user
$response = $this->getJson('/user');
$response->assertOk()
->assertJson($user->toArray());
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.