Joe
Joe

Reputation: 21

Getting Error: InvalidArgumentException: Unable to locate factory with name [default] [App\User]

I'm working in Laravel 5.1 and I keep getting this error when trying to run a test:

invalidArgumentException: Unable to locate factory with name [default] [App\User]

Here is my test code:

namespace tests\unit;

class UserTest extends \TestCase
{

    public function testTheUser() {

        $user = factory(\App\User::class)->make();
        $this->assertTrue(true,'Test Something');

    }

}

Here's my ModelFactory.php

It is located in database/factories/ModelFactory.php

$factory->define(\App\User::class, function (Faker\Generator $faker) {
    static $password;

    return [
        'name' => $faker->name,
        'email' => $faker->unique()->safeEmail,
        'password' => $password ?: $password = bcrypt('secret'),
        'remember_token' => str_random(10),
    ];
});

Just to be thorough this is what TestCase looks like:

 class TestCase extends Illuminate\Foundation\Testing\TestCase {

    protected $baseUrl = 'http://localhost';

    /**
     * Creates the application.
     *
     * @return \Illuminate\Foundation\Application
     */
    public function createApplication()
    {
        $app = require __DIR__.'/../bootstrap/app.php';

        $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

        return $app;
    }

}

It doesn't appear to be loading the ModelFactory.php code. I put a dd() statement in the file to see if it would stop and I get the same error. I also put one in the Eloquent\Factory file as well and it is not even calling the load function to include the files is in the factories folder.

I've even run php artisan tinker with the following command:

>>> factory('\App\User')->make();

InvalidArgumentException with message 'Unable to locate factory with name [default] [\App\User].'

and I get the same error. Not sure where to look at this point. Any help would be appreciated. Thanks!

Upvotes: 0

Views: 1487

Answers (1)

Joe
Joe

Reputation: 21

Okay, I figured it out.

In my app.php I was using the following service provider:

'Ccovey\ODBCDriver\ODBCDriverServiceProvider',

I switched back to the default one:

 'Illuminate\Database\DatabaseServiceProvider',

Works now!

Upvotes: 1

Related Questions