chore: code refactor via rector
This commit is contained in:
@@ -2,6 +2,15 @@
|
||||
|
||||
namespace Tests\Unit\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Cashier\Billable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Laravel\Sanctum\NewAccessToken;
|
||||
use App\Models\Log;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\UsageLog;
|
||||
@@ -11,6 +20,7 @@ use Tests\TestCase;
|
||||
|
||||
class UserTest extends TestCase
|
||||
{
|
||||
public $user;
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
@@ -19,7 +29,7 @@ class UserTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_create_a_user_with_factory()
|
||||
public function it_can_create_a_user_with_factory(): void
|
||||
{
|
||||
$this->assertInstanceOf(User::class, $this->user);
|
||||
$this->assertIsString($this->user->name);
|
||||
@@ -28,7 +38,7 @@ class UserTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_has_correct_fillable_attributes()
|
||||
public function it_has_correct_fillable_attributes(): void
|
||||
{
|
||||
$userData = [
|
||||
'name' => 'Test User',
|
||||
@@ -36,7 +46,7 @@ class UserTest extends TestCase
|
||||
'password' => 'password',
|
||||
];
|
||||
|
||||
$user = User::create($userData);
|
||||
$user = User::query()->create($userData);
|
||||
|
||||
$this->assertEquals('Test User', $user->name);
|
||||
$this->assertEquals('test@example.com', $user->email);
|
||||
@@ -44,7 +54,7 @@ class UserTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_hides_sensitive_attributes()
|
||||
public function it_hides_sensitive_attributes(): void
|
||||
{
|
||||
$userArray = $this->user->toArray();
|
||||
|
||||
@@ -53,30 +63,30 @@ class UserTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_casts_email_verified_at_to_datetime()
|
||||
public function it_casts_email_verified_at_to_datetime(): void
|
||||
{
|
||||
$this->user->email_verified_at = now();
|
||||
$this->user->save();
|
||||
|
||||
$this->assertInstanceOf(\Carbon\Carbon::class, $this->user->email_verified_at);
|
||||
$this->assertInstanceOf(Carbon::class, $this->user->email_verified_at);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_hashes_password()
|
||||
public function it_hashes_password(): void
|
||||
{
|
||||
$plainPassword = 'password123';
|
||||
$user = User::create([
|
||||
$user = User::query()->create([
|
||||
'name' => 'Test User',
|
||||
'email' => 'test@example.com',
|
||||
'password' => $plainPassword,
|
||||
]);
|
||||
|
||||
$this->assertNotEquals($plainPassword, $user->password);
|
||||
$this->assertTrue(\Illuminate\Support\Facades\Hash::check($plainPassword, $user->password));
|
||||
$this->assertTrue(Hash::check($plainPassword, $user->password));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_generates_initials_correctly()
|
||||
public function it_generates_initials_correctly(): void
|
||||
{
|
||||
$user = User::factory()->create(['name' => 'John Doe']);
|
||||
$this->assertEquals('JD', $user->initials());
|
||||
@@ -89,7 +99,7 @@ class UserTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_access_filament_panel_when_conditions_are_met()
|
||||
public function it_can_access_filament_panel_when_conditions_are_met(): void
|
||||
{
|
||||
$adminUser = User::factory()->create([
|
||||
'email' => 'admin1@zemail.me',
|
||||
@@ -103,7 +113,7 @@ class UserTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_cannot_access_filament_panel_when_email_does_not_end_with_zemail_me()
|
||||
public function it_cannot_access_filament_panel_when_email_does_not_end_with_zemail_me(): void
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'email' => 'user@gmail.com',
|
||||
@@ -117,7 +127,7 @@ class UserTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_cannot_access_filament_panel_when_level_is_not_9()
|
||||
public function it_cannot_access_filament_panel_when_level_is_not_9(): void
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'email' => 'admin2@zemail.me',
|
||||
@@ -131,7 +141,7 @@ class UserTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_cannot_access_filament_panel_when_email_is_not_verified()
|
||||
public function it_cannot_access_filament_panel_when_email_is_not_verified(): void
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'email' => 'admin3@zemail.me',
|
||||
@@ -145,7 +155,7 @@ class UserTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_has_many_tickets_relationship()
|
||||
public function it_has_many_tickets_relationship(): void
|
||||
{
|
||||
$ticket = Ticket::factory()->create(['user_id' => $this->user->id]);
|
||||
|
||||
@@ -154,7 +164,7 @@ class UserTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_has_many_logs_relationship()
|
||||
public function it_has_many_logs_relationship(): void
|
||||
{
|
||||
$log = Log::factory()->create(['user_id' => $this->user->id]);
|
||||
|
||||
@@ -163,7 +173,7 @@ class UserTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_has_many_usage_logs_relationship()
|
||||
public function it_has_many_usage_logs_relationship(): void
|
||||
{
|
||||
$usageLog = UsageLog::factory()->create(['user_id' => $this->user->id]);
|
||||
|
||||
@@ -172,44 +182,44 @@ class UserTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_uses_required_traits()
|
||||
public function it_uses_required_traits(): void
|
||||
{
|
||||
$traits = class_uses(User::class);
|
||||
|
||||
$this->assertArrayHasKey(\Illuminate\Database\Eloquent\Factories\HasFactory::class, $traits);
|
||||
$this->assertArrayHasKey(\Illuminate\Notifications\Notifiable::class, $traits);
|
||||
$this->assertArrayHasKey(\Laravel\Cashier\Billable::class, $traits);
|
||||
$this->assertArrayHasKey(\Laravel\Sanctum\HasApiTokens::class, $traits);
|
||||
$this->assertArrayHasKey(HasFactory::class, $traits);
|
||||
$this->assertArrayHasKey(Notifiable::class, $traits);
|
||||
$this->assertArrayHasKey(Billable::class, $traits);
|
||||
$this->assertArrayHasKey(HasApiTokens::class, $traits);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_implements_required_interfaces()
|
||||
public function it_implements_required_interfaces(): void
|
||||
{
|
||||
$user = new User;
|
||||
|
||||
$this->assertInstanceOf(\Filament\Models\Contracts\FilamentUser::class, $user);
|
||||
$this->assertInstanceOf(\Illuminate\Contracts\Auth\MustVerifyEmail::class, $user);
|
||||
$this->assertInstanceOf(FilamentUser::class, $user);
|
||||
$this->assertInstanceOf(MustVerifyEmail::class, $user);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_extends_authenticatable()
|
||||
public function it_extends_authenticatable(): void
|
||||
{
|
||||
$this->assertInstanceOf(\Illuminate\Foundation\Auth\User::class, $this->user);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_create_api_token()
|
||||
public function it_can_create_api_token(): void
|
||||
{
|
||||
$token = $this->user->createToken('test-token');
|
||||
|
||||
$this->assertInstanceOf(\Laravel\Sanctum\NewAccessToken::class, $token);
|
||||
$this->assertInstanceOf(NewAccessToken::class, $token);
|
||||
$this->assertCount(1, $this->user->tokens);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_delete_tokens()
|
||||
public function it_can_delete_tokens(): void
|
||||
{
|
||||
$token = $this->user->createToken('test-token');
|
||||
$this->user->createToken('test-token');
|
||||
$this->user->tokens()->delete();
|
||||
|
||||
$this->assertCount(0, $this->user->fresh()->tokens);
|
||||
|
||||
Reference in New Issue
Block a user