jelly老师,我运行test的时候出现以下问题
There was 1 error:
1) Tests\Unit\ArticleTest::itFetchesTrendingArticles
InvalidArgumentException: Unable to locate factory with name [default] [App\Article].
奇怪的是,我在tinker里面运行factory方法却一点问题都没有,我试过清除缓存和composer dump-autoload也没有效果,请问老师问题是出现在哪里呢?@jellybool
我的factory方法
$factory->define(App\Article::class, function (Faker $faker) {
return [
'title' => $faker->sentence,
];
});
我的testcase
class ArticleTest extends TestCase {
/** @test */
public function itFetchesTrendingArticles(){
factory(Article::class,3)->create();
factory(Article::class)->create(['read' => 10]);
$mostPopular = factory(Article::class)->create(['read' => 20]);
$articles = Article::trending();
$this->assertEquals($mostPopular->id, $articles->first()->id);
}
}
我的article model
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
public function scopeTrending($query){
}
}