问题描述
我创建了功能测试api。
CategoryApiTest.PHP
namespace Tests\Feature;
use App\Models\Category;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\JsonResponse;
use Tests\TestCase;
class CategoryApiTest extends TestCase
{
use RefreshDatabase;
protected $faker;
public function setUp(): void
{
parent::setUp(); // Todo: Change the autogenerated stub
$this->user = $this->faker = Category::factory()
->create([
'name' => 'Food','description' => 'This is the food category','menu' => true,'image' => 'IMG_4985','parent_id' => '1'
]);
}
...
public function testUpdateCategory()
{
$response = $this->putJson('/api/categories/1',[
'name' => 'Water Update','description' => 'This is the water category update','image' => 'IMG_56898','parent_id' => '1'
]);
$response->assertStatus(JsonResponse::HTTP_OK)
->assertJsonFragment([
'name' => 'Water Update','slug' => 'water-update','parent_id' => 1
]);
}
...
}
这种情况总是返回失败,因为无法使用id = 1
找到类别。
我检查了列表类别,然后看到:
我创建了文件.env.testing
和database_test,但是我认为PHPunit.xml
不使用文件.env.testing
,因此RefreshDatabase
无法正常工作。
数据测试不refresh
。出了点问题,请帮我解决。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)