【发布时间】:2019-07-26 18:37:24
【问题描述】:
我有一个使用JobFactory 和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);
}
}
当我运行测试时出现此错误
InvalidArgumentException : Unable to locate factory with name [default] [App\Job].
我在功能测试中使用工厂 App\Job (JobFactory) 没有任何问题。 我使用 PhpStorm 内置的 PHPUnit 测试功能。
我通过一个小测试助手运行 create 和 make
<?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);
}
不确定我做错了什么,但我似乎无法深入了解它。 非常感谢任何帮助。
【问题讨论】: