2021-11-30 17:39:33 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit;
|
|
|
|
|
2023-03-08 17:43:26 +01:00
|
|
|
use App\Events\GroupDeleted;
|
2022-11-22 15:15:52 +01:00
|
|
|
use App\Events\GroupDeleting;
|
2021-12-02 13:15:53 +01:00
|
|
|
use App\Models\Group;
|
|
|
|
use App\Models\TwoFAccount;
|
2023-03-08 17:43:26 +01:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
2023-08-01 11:28:27 +02:00
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
2021-11-30 17:39:33 +01:00
|
|
|
use Tests\ModelTestCase;
|
|
|
|
|
|
|
|
/**
|
2023-08-01 11:28:27 +02:00
|
|
|
* GroupModelTest test class
|
2021-11-30 17:39:33 +01:00
|
|
|
*/
|
2023-08-01 11:28:27 +02:00
|
|
|
#[CoversClass(Group::class)]
|
2021-11-30 17:39:33 +01:00
|
|
|
class GroupModelTest extends ModelTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function test_model_configuration()
|
|
|
|
{
|
|
|
|
$this->runConfigurationAssertions(
|
|
|
|
new Group(),
|
|
|
|
['name'],
|
|
|
|
['created_at', 'updated_at'],
|
|
|
|
['*'],
|
|
|
|
[],
|
2024-03-14 14:49:49 +01:00
|
|
|
[
|
|
|
|
'id' => 'int',
|
|
|
|
'twofaccounts_count' => 'integer',
|
2024-03-29 09:42:54 +01:00
|
|
|
'user_id' => 'integer',
|
2024-03-14 14:49:49 +01:00
|
|
|
],
|
2023-03-08 17:43:26 +01:00
|
|
|
[
|
|
|
|
'deleting' => GroupDeleting::class,
|
2023-03-10 22:59:46 +01:00
|
|
|
'deleted' => GroupDeleted::class,
|
2023-03-08 17:43:26 +01:00
|
|
|
]
|
2021-11-30 17:39:33 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2023-03-08 17:43:26 +01:00
|
|
|
public function test_twofaccounts_relation()
|
2021-11-30 17:39:33 +01:00
|
|
|
{
|
2022-11-22 15:15:52 +01:00
|
|
|
$group = new Group();
|
2021-11-30 17:39:33 +01:00
|
|
|
$accounts = $group->twofaccounts();
|
|
|
|
$this->assertHasManyRelation($accounts, $group, new TwoFAccount());
|
|
|
|
}
|
2023-03-08 17:43:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function test_user_relation()
|
|
|
|
{
|
2023-03-10 22:59:46 +01:00
|
|
|
$model = new Group;
|
2023-03-08 17:43:26 +01:00
|
|
|
$relation = $model->user();
|
|
|
|
|
|
|
|
$this->assertInstanceOf(BelongsTo::class, $relation);
|
|
|
|
$this->assertEquals('user_id', $relation->getForeignKeyName());
|
|
|
|
}
|
2022-11-22 15:15:52 +01:00
|
|
|
}
|