1. Run the GraphQL Query API, response 200. Mainly test the response of the themeAssets field. As shown in Figure 1.

2. Add the test field: themeAssets. Mainly verify whether the field exists, because the value of the field is unpredictable, and I do not plan to insert a new record. Assert that the response has a given JSON structure, implemented based on $response->assertJsonStructure(array $structure);.
PHP
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. Run the test, the test passes.
Plaintext
PS E:\wwwroot\object> ./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\object>
