When running factories (either in tests or seeder), the factories in database/factories should be properly located.
Actual behaviour
When running this example seeder:
<?php
namespace Database\Seeders;
use App\Entities\User;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*/
public function run(): void
{
entity(User::class)->create();
}
}
with php artisan db:seed following error happens:
InvalidArgumentException
Unable to locate factory with name [default] [App\Entities\User]
at vendor/laravel-doctrine/orm/src/Testing/FactoryBuilder.php:205
201▕ */
202▕ protected function makeInstance(array $attributes = []): mixed
203▕ {
204▕ if (! isset($this->definitions[$this->class][$this->name])) {
➜ 205▕ throw new InvalidArgumentException('Unable to locate factory with name [' . $this->name . '] [' . $this->class . ']');
206▕ }
207▕
208▕ $definition = call_user_func($this->definitions[$this->class][$this->name], $this->faker, $attributes);
209▕
Steps to reproduce
Fresh install of L11 with packages
gedmo/doctrine-extensions
laravel-doctrine/extensions
laravel-doctrine/migrations
laravel-doctrine/orm
Add entity, for example:
<?php
namespace App\Entities;
use App\Traits\MustVerifyEmail;
use DateTime;
use DateTimeImmutable;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Contracts\Auth\MustVerifyEmail as MustVerifyEmailContract;
use LaravelDoctrine\ORM\Notifications\Notifiable;
#[ORM\Entity]
#[ORM\Table(name: "users")]
class User implements Authenticatable, CanResetPasswordContract, MustVerifyEmailContract
{
use CanResetPassword, \LaravelDoctrine\ORM\Auth\Authenticatable, MustVerifyEmail, Notifiable;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: "AUTO")]
#[ORM\Column(type: 'integer')]
protected int $id;
#[ORM\Column(type: 'string', length: 255)]
protected string $name;
#[ORM\Column(type: 'string', length: 255, unique: true)]
protected string $email;
#[ORM\Column(type: 'datetime', nullable: true)]
protected ?DateTime $emailVerifiedAt = null;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
#[Gedmo\Timestampable]
protected ?DateTimeImmutable $createdAt = null;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
#[Gedmo\Timestampable]
protected ?DateTimeImmutable $updatedAt = null;
public function __construct() {}
public function getId(): int
{
return $this->id;
}
public function getKey(): int
{
return $this->getId();
}
public function setId(int $id): void
{
$this->id = $id;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): void
{
$this->name = $name;
}
public function getEmail(): string
{
return $this->email;
}
public function setEmail(string $email): void
{
$this->email = $email;
}
public function getEmailVerifiedAt(): ?DateTime
{
return $this->emailVerifiedAt;
}
public function setEmailVerifiedAt(?DateTime $emailVerifiedAt): void
{
$this->emailVerifiedAt = $emailVerifiedAt;
}
public function getCreatedAt(): DateTimeImmutable
{
return $this->createdAt;
}
public function getUpdatedAt(): DateTimeImmutable
{
return $this->updatedAt;
}
}
Create factory to database/factories/UserFactory.php
<?php
use Faker\Generator as Faker;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
$factory->define(App\Entities\User::class, function (Faker $faker, array $attributes) {
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'password' => Hash::make('password'),
'emailVerifiedAt' => $attributes['emailVerifiedAt'] ?? new DateTime,
'rememberToken' => Str::random(10),
];
});
Create seeder:
<?php
namespace Database\Seeders;
use App\Entities\User;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*/
public function run(): void
{
entity(User::class)->create();
}
}
Run command > php artisan db:seed
The app works normally, no bugs or errors there but the factories are not currently located for some reason.
laravel-doctrine/orm version & Laravel version
Expected behaviour
When running factories (either in tests or seeder), the factories in database/factories should be properly located.
Actual behaviour
When running this example seeder:
with php artisan db:seed following error happens:
InvalidArgumentException
Unable to locate factory with name [default] [App\Entities\User]
at vendor/laravel-doctrine/orm/src/Testing/FactoryBuilder.php:205 201▕ */ 202▕ protected function makeInstance(array $attributes = []): mixed 203▕ { 204▕ if (! isset($this->definitions[$this->class][$this->name])) { ➜ 205▕ throw new InvalidArgumentException('Unable to locate factory with name [' . $this->name . '] [' . $this->class . ']'); 206▕ } 207▕ 208▕ $definition = call_user_func($this->definitions[$this->class][$this->name], $this->faker, $attributes); 209▕
Steps to reproduce
Fresh install of L11 with packages gedmo/doctrine-extensions laravel-doctrine/extensions laravel-doctrine/migrations laravel-doctrine/orm
Add entity, for example:
The app works normally, no bugs or errors there but the factories are not currently located for some reason.
Thanks!