thephpleague / factory-muffin

Enables the rapid creation of objects for testing
https://factory-muffin.thephpleague.com/
MIT License
532 stars 72 forks source link

Question: "The model class is undefined." error. #445

Closed mcddx330 closed 4 years ago

mcddx330 commented 7 years ago

Hello. I found some create dummy data library for lumen project, and then now trying this. But I had exception error.

Here is sample code.

use Faker\Factory;
use League\FactoryMuffin;

class User {
    public static function generate() {
        $fm = new FactoryMuffin\FactoryMuffin();
        $fm->loadFactories(base_path('tests/Factory/factories'));

        $faker = Factory::create('ja_JP');
        $fm->define('Account')->setDefinitions([
            'user_number' => $faker->numberBetween(0, 999),
            'screen_name' => $faker->userName,
            'website' => $faker->url,
            'description' => $faker->text($faker->numberBetween(10, 100)),
            'profile_image_url' => $faker->imageUrl(640, 640),
        });

        return $fm->create('Account');
}

And run this program, output this.

 [League\FactoryMuffin\Exceptions\ModelNotFoundException]  
  The model class 'Account' is undefined.

So what should I do this problem?

GrahamCampbell commented 7 years ago

Is this the full name of your model, or is it actually App\Account?

ctrlaltdylan commented 6 years ago

I had this same issue with a code base that does not have "models" but rather "streams" a.k.a. PyroCMS. I ended up just creating stub model classes so FactoryMuffin could create something:

<?php

class Profile {
  public function save() {
    return true; 
  }
}
GrahamCampbell commented 4 years ago

Closing due to no response from the OP.