Laravel php测试,称为未定义函数?
我使用laravel 8编写了一个代码,我想为所有模型创建CRUD测试,这样我就可以在每个测试用例中调用它,例如,我有一个扩展了TestCase的操作符测试(CRUD Testing master)ref:,这是我的操作符测试,看起来像Laravel php测试,称为未定义函数?,laravel,phpunit,Laravel,Phpunit,我使用laravel 8编写了一个代码,我想为所有模型创建CRUD测试,这样我就可以在每个测试用例中调用它,例如,我有一个扩展了TestCase的操作符测试(CRUD Testing master)ref:,这是我的操作符测试,看起来像 <?php namespace Tests\Feature; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker;
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class OperatorTest extends TestCase
{
use RefreshDatabase, WithFaker;
public function test_user_can_update_an_operator()
{
$this->setBaseRoute('master.operator');
$this->setBaseModel('App\Models\Operator');
$this->signIn();
$this->attributes = [
'username' => 'test update',
'level' => 1,
'category_id' => 1,
'password' => 'password'
];
$this->update($this->attributes);
}
}
您需要先初始化模型,然后调用模型工厂
第64行未定义create函数
而不是
$model = create($model);
使用下面的代码
$model = app()->make($model)
$model = $model::factory()->create();
有关和的详细信息。之后,我发现了此错误BadMethodCallException
SQLite不支持删除外键(您需要重新创建表)。
您所问的问题与create函数有关,但未定义。
$model = app()->make($model)
$model = $model::factory()->create();