1. In the program implementation, first request the API to generate a cache identifier. Then request the API again to delete the cache identifier. See Figure 1.

2. To pass the test, the prerequisite is that an explicit cache identifier must exist to serve as the parameter for the delete request.
3. Reference URL: https://learnku.com/laravel/t/22690 . Building a Laravel REST API using TDD. When testing the delete route, it first directly operates the database to generate a record, and then calls the HTTP API to test the delete operation.
// 测试删除路由
public function testDelete(){
$token = $this->authenticate();
$recipe = Recipe::create([
'title' => 'Jollof Rice',
'procedure' => 'Parboil rice, get pepper and mix, and some spice and serve!'
]);
$this->user->recipes()->save($recipe);
$response = $this->withHeaders([
'Authorization' => 'Bearer '. $token,
])->json('POST',route('recipe.delete',['recipe' => $recipe->id]));
$response->assertStatus(200);
// 断言没有食谱
$this->assertEquals(0,$this->user->recipes()->count());
}
4. Therefore, I decided to apply the same design. First directly operate the cache to generate the corresponding cache identifier, and then execute the HTTP API request for testing.
public function testDeleteThemeEditorCode(): void
{
$random = Str::random(36);
$value = [
'theme_id' => 'vogue'
];
Cache::tags([ThemeEditorResolver::TAG_THEME_EDITOR, ThemeEditorResolver::TAG_THEME_EDITOR_CODE])->put($random, $value, 86400);
$response = $this->graphQL('
mutation DeleteThemeEditorCode($themeEditorCode: String!) {
onlineStoreThemeEditorCodeDelete(themeEditorCode: $themeEditorCode) {
deletedThemeEditorCode
}
}
', [
'themeEditorCode' => $random,
]);
$response->assertJson(
[
'data' => [
'onlineStoreThemeEditorCodeDelete' => [
'deletedThemeEditorCode' => $random
],
],
]
);
}
5. Run the test, and the test passes. See Figure 2.

PS E:\wwwroot\object> .\vendor\bin\phpunit .\Modules\ThemeStore\Tests\Functional\GraphQl\ThemeEditorGraphQlApiTest.php
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
.. 2 / 2 (100%)
Time: 1.31 seconds, Memory: 72.00 MB
OK (2 tests, 4 assertions)
