Skip to content

Commit

Permalink
Change Faker uses on factories
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortiix85 committed Jan 20, 2024
1 parent 0b4adb4 commit 676a4f9
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ npm-debug.log
yarn-error.log
/.idea
/.vscode
composer.lock
5 changes: 4 additions & 1 deletion app/Http/Controllers/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ class TaskController extends Controller {
public function show($id) {
$user = AuthUtil::getAuthUser();
$task = Task::find($id);
if(!$task) {
return redirect()->back();
}
$project = Project::all()->find($task->project_id);

if (!$task or !$project or !UserProject::where("project_id", $project->id)->where("user_id", $user->id)->get()->count()) {
if (!$project or !UserProject::where("project_id", $project->id)->where("user_id", $user->id)->get()->count()) {
return redirect()->back();
}

Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions database/factories/CommentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ class CommentFactory extends Factory
*/
public function definition(): array
{
$faker = $this->faker;
return [
"content" => fake()->sentence(10, true),
"user_id" => fake()->randomElement(User::all())->id,
"task_id" => fake()->randomElement(Task::all())->id
"content" => $faker->sentence(10, true),
"user_id" => $faker->randomElement(User::all())->id,
"task_id" => $faker->randomElement(Task::all())->id
];
}
}
9 changes: 5 additions & 4 deletions database/factories/ProjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ class ProjectFactory extends Factory
*/
public function definition(): array
{
$faker = $this->faker;
return [
'name' => ucfirst(fake()->word()),
'description' => fake()->sentence(10, true),
'start_date' => fake()->dateTimeBetween('-1 year', 'now'),
'end_date' => fake()->dateTimeBetween('now', '+1 year')
'name' => ucfirst($faker->word()),
'description' => $faker->sentence(10, true),
'start_date' => $faker->dateTimeBetween('-1 year', 'now'),
'end_date' => $faker->dateTimeBetween('now', '+1 year')
];
}
}
15 changes: 8 additions & 7 deletions database/factories/TaskFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class TaskFactory extends Factory
{
protected static array $possibleTaskNames = [
protected static $possibleTaskNames = [
"Rédiger un plan d'action",
'Planifier la réunion avec les collaborateurs',
'Convoquer Jean Yves',
Expand All @@ -21,7 +21,7 @@ class TaskFactory extends Factory
"Installer Laravel"
];

protected static array $possibleTaskDescription = [
protected static $possibleTaskDescription = [
"Il faut que nous avançions plus vite",
'Les collaborateurs à prévenir sont : Jean Mich et Yves',
'Il faut aussi préparer des arguments pour virer Jean Yves',
Expand All @@ -37,12 +37,13 @@ class TaskFactory extends Factory
*/
public function definition(): array
{
$faker = $this->faker;
return [
'name' => fake()->randomElement(static::$possibleTaskNames),
'description' => fake()->randomElement(static::$possibleTaskDescription),
'deadline'=> fake()->dateTimeBetween('now','+3 months'),
'status' => fake()->numberBetween(0,3),
'priority' => fake()->numberBetween(0,2),
'name' => $faker->randomElement(static::$possibleTaskNames),
'description' => $faker->randomElement(static::$possibleTaskDescription),
'deadline'=> $faker->dateTimeBetween('now','+3 months'),
'status' => $faker->numberBetween(0,3),
'priority' => $faker->numberBetween(0,2),
'project_id'=> Project::all()->random()->id
];
}
Expand Down
12 changes: 7 additions & 5 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@ class UserFactory extends Factory
/**
* The current password being used by the factory.
*/
protected static string $password = "Password1+";
protected static $password = "Password1+";

/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array

{
$faker = $this->faker;
return [
'first_name' => fake()->firstName(),
'last_name'=> fake()->lastName(),
'email' => fake()->unique()->safeEmail(),
'first_name' => $faker->firstName(),
'last_name'=> $faker->lastName(),
'email' => $faker->unique()->safeEmail(),
'password' => static::$password,
'profile_photo_path' => fake()->imageUrl(480, 480, 'people', true)
'profile_photo_path' => $faker->imageUrl(480, 480, 'people', true)
];
}

Expand Down
7 changes: 4 additions & 3 deletions database/factories/UserProjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ public function definition(): array
{
$user_id = null;
$project_id = null;
$faker = $this->faker;

while (true) {
$user_id = fake()->randomElement(User::all())->id;
$project_id = fake()->randomElement(Project::all())->id;
$user_id = $faker->randomElement(User::all())->id;
$project_id = $faker->randomElement(Project::all())->id;

if (!UserProject::where("user_id", $user_id)->where("project_id", $project_id)->exists()) {
break;
Expand All @@ -34,7 +35,7 @@ public function definition(): array
return [
"user_id" => $user_id,
"project_id" => $project_id,
"is_admin" => fake()->boolean(50),
"is_admin" => $faker->boolean(50),
];
}
}
5 changes: 3 additions & 2 deletions database/factories/UserTaskFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class UserTaskFactory extends Factory
*/
public function definition(): array
{
$faker = $this->faker;
return [
"user_id" => fake()->randomElement(User::all())->id,
"task_id" => fake()->randomElement(Task::all())->id,
"user_id" => $faker->randomElement(User::all())->id,
"task_id" => $faker->randomElement(Task::all())->id,
];
}
}

0 comments on commit 676a4f9

Please sign in to comment.