I try to test my application for login and logout, with a jwtToken. I'm lost with Laravel Contract and Trait. I read a lot of questions/answers but the solutions cannot work on my code. I understand that contract not work like trait but it's seems to be quite linked. I have been looking for a way out since 3 days, without success.
I have this error since i put ActingAs in my test.
Can you help me please ?
My User Model :
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Auth\UserInterface;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\Role;
use App\Models\UserAddress;
class User extends Authenticatable implements
JWTSubject,
AuthenticatableContract
{
use Notifiable;
use SoftDeletes;
use Authenticatable;
I also try without implements AuthenticatableContract
I also try without the first use, without the second use.
My TestCase :
namespace Tests;
use App\Models\Role;
use App\Models\User;
use Illuminate\Support\Facades\DB;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
/**
* @var User
*/
protected $user;
public static $admin;
public static $faker;
public function setUp(): void
{
parent::setUp();
self::$faker = \Faker\Factory::create('fr_FR');
self::$admin = \App\Models\User::with('role')
->select('*')
->join('roles', 'roles.id_role', '=', 'users.id_role')
->where('slug', 'admin')
->first()->user;
My Account Test :
namespace Tests\Feature;
use Carbon\Carbon;
use Tests\TestCase;
use App\Models\Role;
use App\Models\User;
use Tymon\JWTAuth\JWTAuth;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Contracts\Auth\Authenticatable;
[...]
public function testLogout() {
// $user = User::inRandomOrder()->firstOrFail();
// \Log::debug('user->first_name : ' . $user->first_name);
$this->actingAs(self::$admin)
->json('POST', 'api/auth/logout')
->assertStatus(200);
}```