php - Laravel 测试生命周期钩子
问题描述
我有一个在创建的生命周期钩子上记录活动的特征。在我的测试类中,如果我运行任何给定的单个测试, RefreshDatabase
它会失败,说表是空的。如果我在没有 RefreshDatabase
通过的情况下运行测试,但由于明显的原因下次失败。如果我运行整个测试类, RefreshDatabase
只有第一个失败,其余通过。如果我在没有 RefreshDatabase
第一个通过的情况下运行整个测试类,而其余的由于明显的原因(重复键错误)而失败。
这是以这种方式运行的测试之一:
/** @test */
public function user_can_access_their_own_activity()
{
$this->jsonAs($this->user, 'POST', route('team.store'), [
'display_name' => 'Test Team',
])->assertStatus(200);
$this->assertDatabaseHas('activities', [
'user_id' => $this->user->getKey(),
'type' => 'created_team',
]);
$response = $this->jsonAs($this->user, 'GET', route('activity.index'))
->assertStatus(200);
$response->assertJsonFragment([
'type' => 'created_team',
'uuid' => $this->user->uuid,
]);
}
如果我需要分享更多信息,请告诉我。谢谢!
解决方案
推荐阅读
- angular - 如何配置 Jhipster 现有应用程序以使用“ng build”构建?
- excel - 使用嵌入在单元格文本中的变量
- sql - 获取上个月的交易,无论日期和时间
- python - 如何使用 Python 从指向子 URL 的 URL 下载 pdf 文件
- typescript - Typescript 模块中的动态导出
- sql - 位于两个日期之间的 SQL 总和
- javascript - Phaser:如何为 this.image.load 设置回退
- laravel - Vuejs 安装与否?
- javascript - 响应式导航栏(vanilla javascript)不起作用
- c# - 使用没有 VBA 的 OpenXML 库 VS2017 在 Office Excel 中自动插入自定义功能区