first commit

This commit is contained in:
Noor E Ilahi
2026-01-09 12:54:53 +05:30
commit 7ccf44f7da
1070 changed files with 113036 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
<?php
namespace Tests\Factories;
use App\Models\ProjectsUsers;
use App\Models\User;
use Illuminate\Support\Arr;
use Tests\Facades\ProjectFactory;
use Tests\Facades\UserFactory;
class ProjectUserFactory extends Factory
{
public const USER_ROLE = 2;
public const MANAGER_ROLE = 1;
public const AUDITOR_ROLE = 3;
private ProjectsUsers $projectUser;
private ?User $user = null;
private ?int $roleId = null;
protected function getModelInstance(): ProjectsUsers
{
return $this->projectUser;
}
public function createRandomModelData(): array
{
return $this->createModelDataWithRelations();
}
public function createModelDataWithRelations(): array
{
return [
'project_id' => ProjectFactory::create()->id,
'user_id' => UserFactory::create()->id,
'role_id' =>$this->getRandomRoleId()
];
}
private function defineModelData(): array
{
$this->user ??= UserFactory::create();
$this->roleId ??= $this->getRandomRoleId();
return [
'project_id' => ProjectFactory::create()->id,
'user_id' => $this->user->id,
'role_id' => $this->roleId
];
}
private function getRandomRoleId()
{
return Arr::random([self::USER_ROLE, self::MANAGER_ROLE, self::AUDITOR_ROLE]);
}
public function forUser(User $user): self
{
$this->user = $user;
return $this;
}
public function setRole(int $roleId): self
{
$this->roleId = $roleId;
return $this;
}
public function create(): ProjectsUsers
{
$this->projectUser = ProjectsUsers::create($this->defineModelData());
if ($this->timestampsHidden) {
$this->hideTimestamps();
}
return $this->projectUser;
}
}