Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel php测试,称为未定义函数?_Laravel_Phpunit - Fatal编程技术网

Laravel php测试,称为未定义函数?

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;

我使用laravel 8编写了一个代码,我想为所有模型创建CRUD测试,这样我就可以在每个测试用例中调用它,例如,我有一个扩展了TestCase的操作符测试(CRUD Testing master)ref:,这是我的操作符测试,看起来像

<?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();