Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.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
Php Laravel中的单元测试:设置当前经过身份验证的用户时出错_Php_Testing_Laravel_Tdd_Phpunit - Fatal编程技术网

Php Laravel中的单元测试:设置当前经过身份验证的用户时出错

Php Laravel中的单元测试:设置当前经过身份验证的用户时出错,php,testing,laravel,tdd,phpunit,Php,Testing,Laravel,Tdd,Phpunit,在我的Laravel单元测试中,我使用下面的代码设置当前经过身份验证的用户。这正是拉威尔在他们的网站上记录的。我使用Laravel提供的默认用户模型 public function testLoggedInUserCanCreateCat() { Route::enableFilters(); $user = new User(array( 'name' => 'john' )); $this->

在我的Laravel单元测试中,我使用下面的代码设置当前经过身份验证的用户。这正是拉威尔在他们的网站上记录的。我使用Laravel提供的默认用户模型

public function testLoggedInUserCanCreateCat() {
        Route::enableFilters();
        $user = new User(array(
            'name' => 'john'
        ));
        $this->be($user);
        $this->call('GET', '/cats/create');
        $this->assertResponseOk();
    }
出于某种原因,在SSH中运行phpunit时,会出现以下错误:

1) GlobalTest::testLoggedInUserCanCreateCat
Illuminate\Database\Eloquent\MassAssignmentException: name

有人知道这里出了什么问题吗?我在互联网上搜索了几个小时,但找不到任何帮助。

问题在于错误:

MassAssignmentException:名称

您正在尝试批量分配变量
名称
——但您的模型不允许这样做

从以下位置更改您的用户模型:

protected $fillable = [];
为此:

protected $fillable = ['name'];
你可以