Skip to content

Commit 6680e1f

Browse files
committed
fix tests
1 parent 194416a commit 6680e1f

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

src/OpenApi/Storage/OpenAPI/ResponseStorage.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ public function withParameter(SchemaStorage $schema): static
2525

2626
public function addGlobParameters(array $vols): void
2727
{
28-
foreach ($vols as $field => $description){
29-
$parameters = $this->parameter;
28+
$dates = $this->parameter['properties'] ?? [];
29+
$required = $this->parameter['required'] ?? [];
30+
31+
$this->parameter['properties'] = [];
3032

33+
foreach ($vols as $field => $description){
3134
if($description !== 'object'){
3235
$this->parameter['properties'][$field] = [
3336
'type' => 'string',
@@ -37,9 +40,11 @@ public function addGlobParameters(array $vols): void
3740
$this->parameter['properties'][$field] = [
3841
'type' => 'object',
3942
'description' => $description,
40-
'properties' => $parameters,
43+
'properties' => $dates,
44+
'required' => $required,
4145
];
4246
}
47+
4348
}
4449

4550
}

tests/Openapi/BaseGroupOpenApiTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function one(TestBaseGroupRequest $request): void
7878
expect($schema['properties'])->toHaveCount(3)->toHaveKeys(['input_change_group_1_33_2_11', 'input_group_2_22', 'input_group_2_33']);
7979

8080

81-
$schema = $post->responses[200]['content']['application/json']['schema'];
81+
$schema = $post->responses[200]['content']['application/json']['schema']['properties']['data'];
8282
expect($schema['properties'])->toHaveCount(3)->toHaveKeys(['out_group_1_11', 'out_group_1_22', 'out_group_1_33_2_11']);
8383

8484
});

tests/Openapi/EnumOpenApiTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,32 +59,34 @@ public function one(OpenapiEnumRequest $request): void
5959
$requestBody = $post->requestBody;
6060
$schema = $requestBody['content']['application/json']['schema'];
6161

62-
expect($schema['properties'])
62+
63+
expect($schema)->toHaveKey('properties')
64+
->and($schema['properties'])
6365
->toHaveKeys([
6466
'test_enum',
6567
'test_string_enum',
6668
'test_string_2_enum',
6769
'test_one_of_enum',
6870
])
6971
->and($schema['properties']['test_enum'])->toMatchArray([
70-
'type' => 'string',
72+
'type' => 'string',
7173
'description' => 'optional values:ENUM_1、ENUM_2',
72-
'example' => '',
74+
'example' => '',
7375
])
7476
->and($schema['properties']['test_string_enum'])->toMatchArray([
75-
'type' => 'string',
77+
'type' => 'string',
7678
'description' => 'optional values:ENUM_1、ENUM_2、ENUM_3、ENUM_4',
77-
'example' => '',
79+
'example' => '',
7880
])
7981
->and($schema['properties']['test_string_2_enum'])->toMatchArray([
80-
'type' => 'string',
82+
'type' => 'string',
8183
'description' => 'optional values:ENUM_1、ENUM_2、ENUM_3、ENUM_4',
82-
'example' => '',
84+
'example' => '',
8385
])
8486
->and($schema['properties']['test_one_of_enum'])->toMatchArray([
85-
'type' => 'oneOf',
87+
'type' => 'oneOf',
8688
'description' => 'optional values:ENUM_1、ENUM_2、ENUM_3、ENUM_4',
87-
'example' => '',
89+
'example' => '',
8890
])
8991
->and($schema['properties']['test_one_of_enum']['oneOf'])->toBeArray()->toHaveCount(2)
9092
->and($schema['properties']['test_one_of_enum']['oneOf'][0])->toMatchArray(['type' => 'string'])

tests/Openapi/OpenApiTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ public function one(TestOpenApiRequest $request): TestOpenApiResponse
9393
$response200 = $post->responses[200];
9494
expect($response200['description'])->toBe('成功');
9595

96-
$schema = $response200['content']['application/json']['schema'];
97-
expect($schema['properties'])->toHaveKeys(['name', 'id'])
98-
->and($schema['required'])->toHaveCount(1)
99-
->and($schema['required'][0])->toBeString('id');
96+
$data = $response200['content']['application/json']['schema']['properties']['data'];
97+
98+
expect($data['properties'])->toHaveKeys(['name', 'id'])
99+
->and($data['required'])->toHaveCount(1)
100+
->and($data['required'][0])->toBeString('id');
100101

101102
});

0 commit comments

Comments
 (0)