Laravel TDD 教程 6.3. 辅助函数,数据工厂的 state 方法该如何重构
教程中,形如
$question = factory(Question::class)->create();
的语句可以重构为
$question = create(Question::class);
那么,
$question = factory(Question::class)->state('published')->create();
该如何重构呢?
关于 LearnKu
这个可以新建一个
PublishedQuestionFactory来实现。具体步骤如下:1.添加
PublishedQuestionFactory:database/helpers/PublishedQuestionFactory.php
2.修改
composer.json文件:composer.json
3.加载
helpers目录下的文件:4.替换形如:
的代码为: