-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Factories #106
base: main
Are you sure you want to change the base?
Adding Factories #106
Conversation
This reverts commit 2cc71ca.
In the DatabaseSeeder in the Factories branch there was no referenties table and others new ones. The factory to themes table was generating random ids, so the referentie_themes seeder was failing. I change some files and now it is working. Please, let me know if the new tables (Questions, Answres, Referenties , Dimensions, AnswerDimension) should have a factory as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good Itaira!
I have made some edits in ActieFactory.php and placed some comments. Could you have a look at that?
Also, it might be possible to directly create Acties with their relationships (see the documentation). Could you have a look at that? If that is possible, it would not be necessary to manually pick ids from other models.
database/factories/ActieFactory.php
Outdated
$end_time = $end_date_obj->format('H:i:s'); | ||
|
||
#Calculating create date from start date | ||
$create_at_obj = $this->faker->dateTimeBetween( "-2years",$start_date_obj) ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you use '-2year' here? We want to generate actions in the future right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I studied the first seed for this table, I noticed that the minimum year for start_date and create_at was 2022, 2 years ago.
So I did that:
1- Took the start_date from -2years until now(). So, we have start_date until the moment of seed. But I could set the range to picking dates to finishing in now() + 2years, so that we could have Acties with dates in the future. Should I do it?
2- Picked up the create_at, being the date to creation of the record in the table, always before the start_date, limited to -2 years.
# This number is the same in the count parameter in the seeder file | ||
$tot_elements = $this->count; | ||
|
||
$name = $this->faker->unique()->randomElement(static::$names_map); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this variable $name
is used only once, it might be good to just call $this->faker->unique()->randomElement(static::$names_map)
directly in line 37
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using the $name to generate the slug field as well, in the line 38.
public function definition(): array | ||
{ | ||
# This number is the same in the count parameter in the seeder file | ||
$tot_elements = $this->count; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the better function to use in line 48 would be $faker->numberBetween(1,$tot_elements), where $tot_elements is the number of instances to be created, passed as parameter in the seed file, in the count() method.
But, I got a exception when I use it, the exception is below transcripted. In the Stackoverflow there was explanation about this error sometimes occur with small datasets. So I changed to function to
$faker->randomElement(), but I will search other ways to solve it in the future and then use the variable $tot_elements.
Exception : " FAILED Tests\Feature\RouteTest > available routes wit… OverflowException
Maximum retries of 10000 reached without finding a unique value
at vendor/fakerphp/faker/src/Faker/UniqueGenerator.php:80"
No description provided.