I'm trying to add a Factory to help increment my test coverage on some controllers. I've been using Factories with no issues till now, where I find no reason for this message and I can't figure out what is different from the rest of the factories, which are working perfectly.
The error is:
1) GuestBusinessControllerTest::it_presents_a_domain_home
InvalidArgumentException: Unable to locate factory with name [default] [App\Models\Domain].
I reference the useful files as follows:
My Controller Test trying to use the Factory (Through a trait)
<?php
use Illuminate\Foundation\Testing\DatabaseTransactions;
class GuestBusinessControllerTest extends TestCase
{
use DatabaseTransactions;
use CreateBusiness, CreateDomain;
// ...
/** @test */
public function it_presents_a_domain_home()
{
$domain = $this->createDomain();
// ...
}
}
The trait using the factory
<?php
use App\Models\Domain;
trait CreateDomain
{
private function createDomain($overrides = [])
{
return factory(Domain::class)->create($overrides);
}
// ...
}
The factory definition
// ...
$factory('App\Models\Domain', function ($faker) {
return [
'slug' => str_slug($faker->sentence(3)),
'owner_id' => 'factory:App\Models\User',
];
});
// ...
I'm using "laracasts/testdummy": "~2.0"
// ...
"require-dev": {
// ...
"laracasts/testdummy": "~2.0",
// ...
},
// ...
Sidenotes:
Yes, I did
composer dump-autoload
(Else, the error message would be different)I tried to define the factory in another helper file, and
dump-autoload
. (Just in case)I also tried renaming my model, thinking that
Domain
might be a conflicting keyword, but that seems not to be the issue.
How may I solve this error?