1、运行 GraphQL Query API,响应 200。主要测试字段:themeAssets 的响应。如图1
2、添加测试字段:themeAssets 。主要验证字段是否存在。因为字段的值无法预测。也不准备插入一条新记录。断言响应具有给定的 JSON 结构,基于 $response->assertJsonStructure(array $structure); 实现
public function testGetThemeById(): void
{
$response = $this->graphQL('
query GetThemeById($id: ID!) {
onlineStoreTheme(themeId: $id) {
id
editable
createdAt
name
themeAssets {
id
themeId
version
key
mimeType
category
schema
createdAt
updatedAt
}
}
}
',
[
'id' => 'vogue',
]
);
$response->assertJson(
[
'data' => [
'onlineStoreTheme' => [
'id' => 'vogue'
],
],
]
)->assertJsonStructure([
'data' => [
'onlineStoreTheme' => [
'themeAssets' => [
[
'id',
'themeId',
'version',
'key',
'mimeType',
'category',
'schema',
'createdAt',
'updatedAt',
]
]
]
],
]
);
}
3、运行测试,测试通过。
PS E:/wwwroot/wshop/platform> ./vendor/bin/phpunit ./Modules/ThemeStore/Tests/Functional/GraphQl/OnlineStoreThemeGraphQlApiTest.php PHPUnit 7.5.20 by Sebastian Bergmann and contributors. . 1 / 1 (100%) Time: 996 ms, Memory: 60.00 MB OK (1 test, 14 assertions) PS E:/wwwroot/wshop/platform>
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/webdev/250709.html
