It just seems like you are using an old version of faker.
This is what I have in my composer.json the require-dev list:
"fakerphp/faker": "^1.9.1",
it seems like it works.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm trying to figure out why when I run a test and use Teacher::factory()->create(); it gives me InvalidArgumentException: Unknown formatter "firstName". I'm not sure why. A little background is that I am
<?php
namespace Database\Factories;
use App\Enums\UserRoleEnum;
use App\Models\Teacher;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class TeacherFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Teacher::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'first_name' => $this->faker->firstName(),
'last_name' => $this->faker->lastName,
'title' => $this->faker->optional(0.1)->title,
'email' => $this->faker->unique()->freeEmail,
'email_verified_at' => now(),
'password' => 'yIXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
'role' => UserRoleEnum::TEACHER,
];
}
}
<?php
namespace App\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Parental\HasParent;
class Teacher extends User
{
use HasFactory, HasParent;
}
Make sure that you're using Tests\TestCase in your unit test and not PHPUnit\Framework\TestCase if you want to use factories. This is a recent change in Laravel to increase performance in Unit tests.
Please or to participate in this conversation.