Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Kazuto's avatar

fake() vs $this->faker in factories

Hey guys,

I was just writing tests and when using ->count on complex factories I ran into following error

Maximum retries of 10000 reached without finding a unique value while using $this->faker->unique()->words().

Switching to fake()->unique()->words() for some reason works though and now I'm wondering if there is a performance difference between using $this->faker and fake() helper.

Maybe someone can answer me this question :D

0 likes
2 replies
Tray2's avatar

The fake() is basically the same as $this->faker.

Why do you use it for creating tens of thousands of records?

Kazuto's avatar

@Tray2 Thanks for your answer.

I use it for the default values in a factory like the documentation says though I'm not creating thousands of records but I guess some of the factories or their relation nested deeply create those records. Something I have to investigate.

Please or to participate in this conversation.