我已经尝试了所有可能的方法,但是我无法弄清我做错了什么。我试图用虚拟数据加载我的数据库,但是我一直得到未知的格式化程序"描述"。描述是我正在使用的变量之一。
下面是我的工厂代码和我的播种机编码器
use Faker\Generator as Faker;
use Analytics\Blockgrant;
$factory->define(Blockgrant::class, function (Faker $faker) {
return [
'description' => $faker->description,
'value' => $faker->value
];
});
<?php
use Faker\Generator as Faker;
use Universityobfanalytics\Blockgrantcomponents;
$factory->define(Blockgrantcomponents::class, function (Faker $faker) {
return [
'blockgrants_id' => $faker->blockgrants_id,
'description' => $faker->description,
'percentage' => $faker->percentage,
'value' => $faker->value
];
});
<?php
use Illuminate\Database\Seeder;
use Analytics\Blockgrant;
use Analytics\Blockgrantcomponents;
class BlockgrantSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
factory(Blockgrant::class, 10)->create()->each(function ($blockgrant) {
$blockgrant->blockgrantcomponents()->save(factory(Blockgrantcomponents::class)->create());
});
}
}
我使用的是一对一的hasOne
和belongsTo
关系
有人能帮忙告诉我哪里做错了吗?
4条答案
按热度按时间ac1kyiln1#
这可能是因为您在测试中使用的是
PHPUnit\Framework\TestCase
而不是Tests\TestCase
。lymnna712#
faker库没有您试图访问的属性。
您只能使用如下格式化程序:
您最好浏览faker文档,查看可用格式化程序here的完整列表
6ss1mwsb3#
我正在使用Pest,当尝试在我的项目中编写单元测试时,我的解决方案也出现了同样的错误:
在
tests/Pest.php
文件中,我有这样一行:我把它改成了这个,它起作用了
在类
Test/TestCase
中,记住在构造函数中调用parent::setup()
,如下所示:4ngedf3f4#
您需要创建自己的TestCase类,该类将使用您创建的CreatesApplication特征。
所有这一切看起来像这样: