Php Laravel中的单元测试:设置当前经过身份验证的用户时出错
在我的Laravel单元测试中,我使用下面的代码设置当前经过身份验证的用户。这正是拉威尔在他们的网站上记录的。我使用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->
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'];
你可以