E
E
EVOSandru62021-01-15 16:04:08
Laravel
EVOSandru6, 2021-01-15 16:04:08

What could be the reason for the failure of the faker in the Factory from under the tests?

Good afternoon

I created a factory that works fine in seeders, but when you call it from tests, it works crookedly$this->faker:

class UserFactory extends Factory {

    protected $model = User::class;

    public function definition() {
        
        return [
            'name' => $this->faker->name,
            ...

Call:

UserFactory::new()->create()

InvalidArgumentException: Unknown formatter "name"


What could be the reason for the failure of the faker from under tests?

Temporary solution:

// $faker = $this->faker;
        $faker = \Faker\Factory::create();


But it doesn't work: ReflectionException: Class hash does not exist I don't know if these two problems have one reason or not

app('hash')->make('secret')



Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2021-01-16
@EVOSandru6

in the old version
factory(User::class)->create();
in the new
User::factory()->create();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question