Skip to content
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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Adding Factories #106

wants to merge 10 commits into from

Conversation

Kamieljv
Copy link
Owner

No description provided.

@ItaSsa
Copy link
Collaborator

ItaSsa commented May 20, 2024

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.

Copy link
Owner Author

@Kamieljv Kamieljv left a 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.

$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) ;
Copy link
Owner Author

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?

Copy link
Collaborator

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);
Copy link
Owner Author

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

Copy link
Collaborator

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;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used?

Copy link
Collaborator

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants