2023-03-18 17:33:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Models;
|
|
|
|
|
|
|
|
use App\Models\User;
|
2023-08-01 11:28:27 +02:00
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
2023-03-18 17:33:43 +01:00
|
|
|
use Tests\FeatureTestCase;
|
|
|
|
|
|
|
|
/**
|
2023-08-01 11:28:27 +02:00
|
|
|
* UserModelTest test class
|
2023-03-18 17:33:43 +01:00
|
|
|
*/
|
2023-08-01 11:28:27 +02:00
|
|
|
#[CoversClass(User::class)]
|
2023-03-18 17:33:43 +01:00
|
|
|
class UserModelTest extends FeatureTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function test_admin_scope_returns_only_admin()
|
|
|
|
{
|
|
|
|
User::factory()->count(4)->create();
|
|
|
|
|
|
|
|
$firstAdmin = User::factory()->administrator()->create([
|
|
|
|
'name' => 'first',
|
|
|
|
]);
|
|
|
|
$secondAdmin = User::factory()->administrator()->create([
|
|
|
|
'name' => 'secondAdmin',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$admins = User::admins()->get();
|
|
|
|
|
|
|
|
$this->assertCount(2, $admins);
|
|
|
|
$this->assertEquals($admins[0]->is_admin, true);
|
|
|
|
$this->assertEquals($admins[1]->is_admin, true);
|
|
|
|
$this->assertEquals($admins[0]->name, $firstAdmin->name);
|
|
|
|
$this->assertEquals($admins[1]->name, $secondAdmin->name);
|
|
|
|
}
|
|
|
|
}
|