Ad
PHPUnit Test Can't Find Factory
I have a unit test that uses a JobFactory
and ClientFactory
.
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
class JobTest extends TestCase
{
/** @test */
function can_display_job_details()
{
$job = create('App\Job', [
'job-number' => 9999,
'site' => 'Homeville',
'client_id' => function(){
return create('App\Client', [
'name' => 'ACME'
])->id;
},
]);
$details = $job->job_details;
$this->assertEquals('EPS-9999-Homeville-RES', $details);
}
}
When I run the test I get this error
InvalidArgumentException : Unable to locate factory with name [default] [App\Job].
I use the factory App\Job (JobFactory) in my feature test with no issues. I use PhpStorm's built in PHPUnit testing function.
I run create and make through a little test helper
<?php
function create($class, $attributes = [], $times = null)
{
return factory($class, $times)->create($attributes);
}
function make($class, $attributes = [], $times = null)
{
return factory($class, $times)->make($attributes);
}
Not sure what I'm doing wrong but I can't seem to get to the bottom of it. Any help greatly appreciated.
Ad
Answer
You are extending the wrong TestCase
class.
Change:
use PHPUnit\Framework\TestCase;
to:
use Tests\TestCase;
Here you can find an example.
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad