php - Laravel 功能测试,但数据直到请求后才会出现
问题描述
我遇到了功能测试和数据似乎既存在又不存在的问题,具体取决于从何处以及何时检索该数据。
我的测试似乎只有在我一次运行一个时才有效,但如果将它们一起运行,php artisan test
那么似乎没有数据,所以测试失败
这是我的课:
<?php
namespace Tests\Feature;
use App\AssetGroup;
use Throwable;
use Illuminate\Foundation\Testing\RefreshDatabase;
class AssetGroupTest extends CoreFeatureTest
{
use RefreshDatabase;
public function setUp(): void
{
parent::setUp();
$this->seed();
$this->logMeIn();
}
public function testAssetGroupShow(): void
{
$response = $this->get('/api/asset-group?keyBy=none');
$response->assertStatus(200);
}
public function testAssetGroupDelete(): void
{
$assetGroup = AssetGroup::whereHas('user', function ($query) {
$query->where('user_id', 1);
})->first();
$response = $this->delete('/api/asset-group/' . $assetGroup->uuid);
$response->assertStatus(200);
$this->assertSoftDeleted($assetGroup);
}
}
解决方案
推荐阅读
- css - 在 javascript 插件中封装 CSS 代码
- java - 如果我使用 responde.sendRedirect,如何设置 Headers
- arrays - 通过对象值将本地图像文件路径传递给 React 道具不起作用?
- maven - 如何使用测试工具更改 Maven 插件的包
- android - 支持 jvmTarget 1.8 的 Android 版本是什么?
- .htaccess - 将旧产品网址(无 ID)重定向到具有基本(使用 ID)结构的新网址
- python - 出现“超出最大递归深度”错误,我应该重构我的代码吗?
- sql - 根据 Postgres 中另一列的条件生成整数系列
- java - 持有 RecyclerView 的片段未显示在 MainActivity 中
- python - 如何在 matplotlib 中为散点图和折线图设置动画