Skip to content

Commit e92aeff

Browse files
committed
test: 💍 fix existing tests
1 parent ad9be8a commit e92aeff

File tree

5 files changed

+72
-76
lines changed

5 files changed

+72
-76
lines changed

tests/Functional/JsonSchema/JsonLdJsonSchemaTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testSubSchemaJsonLd(): void
5151
$expectedBagOfTestsSchema = new \ArrayObject([
5252
'allOf' => [
5353
[
54-
'$ref' => '#/definitions/HydraItemBaseSchema',
54+
'$ref' => '#/definitions/HydraOutputBaseSchema',
5555
],
5656
new \ArrayObject([
5757
'type' => 'object',
@@ -70,11 +70,11 @@ public function testSubSchemaJsonLd(): void
7070
'nonResourceTests' => new \ArrayObject([
7171
'type' => 'array',
7272
'items' => [
73-
'$ref' => '#/definitions/NonResourceTestEntity.jsonld-read',
73+
'$ref' => '#/definitions/NonResourceTestEntity-read',
7474
],
7575
]),
7676
'type' => new \ArrayObject([
77-
'$ref' => '#/definitions/TestEntity.jsonld-read',
77+
'$ref' => '#/definitions/TestEntity-read',
7878
]),
7979
],
8080
]),
@@ -106,7 +106,7 @@ public function testSubSchemaJsonLd(): void
106106
$expectedTestEntitySchema = new \ArrayObject([
107107
'allOf' => [
108108
[
109-
'$ref' => '#/definitions/HydraItemBaseSchema',
109+
'$ref' => '#/definitions/HydraOutputBaseSchema',
110110
],
111111
new \ArrayObject([
112112
'type' => 'object',
@@ -152,7 +152,7 @@ public function testSchemaJsonLdCollection(): void
152152
$this->assertArrayHasKey('BagOfTests.jsonld-read', $schema['definitions']);
153153
$this->assertArrayHasKey('NonResourceTestEntity.jsonld-read', $schema['definitions']);
154154
$this->assertArrayHasKey('TestEntity.jsonld-read', $schema['definitions']);
155-
$this->assertArrayHasKey('HydraItemBaseSchema', $schema['definitions']);
155+
$this->assertArrayHasKey('HydraOutputBaseSchema', $schema['definitions']);
156156
$this->assertArrayHasKey('HydraCollectionBaseSchema', $schema['definitions']);
157157

158158
$this->assertEquals(['$ref' => '#/definitions/HydraCollectionBaseSchema'], $schema['allOf'][0]);
@@ -163,8 +163,8 @@ public function testArraySchemaWithMultipleUnionTypes(): void
163163
{
164164
$schema = $this->schemaFactory->buildSchema(Nest::class, 'jsonld', 'output');
165165

166-
$this->assertContains(['$ref' => '#/definitions/Robin.jsonld'], $schema['definitions']['Nest.jsonld']['allOf'][1]['properties']['owner']['anyOf']);
167-
$this->assertContains(['$ref' => '#/definitions/Wren.jsonld'], $schema['definitions']['Nest.jsonld']['allOf'][1]['properties']['owner']['anyOf']);
166+
$this->assertContains(['$ref' => '#/definitions/Robin'], $schema['definitions']['Nest.jsonld']['allOf'][1]['properties']['owner']['anyOf']);
167+
$this->assertContains(['$ref' => '#/definitions/Wren'], $schema['definitions']['Nest.jsonld']['allOf'][1]['properties']['owner']['anyOf']);
168168
$this->assertContains(['type' => 'null'], $schema['definitions']['Nest.jsonld']['allOf'][1]['properties']['owner']['anyOf']);
169169

170170
$this->assertArrayHasKey('Nest.jsonld', $schema['definitions']);

tests/Functional/JsonSchema/JsonSchemaTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function testArraySchemaWithReference(): void
151151
]));
152152

153153
$this->assertEquals($schema['definitions']['BagOfTests.jsonld-write']['properties']['type'], new \ArrayObject([
154-
'$ref' => '#/definitions/TestEntity.jsonld-write',
154+
'$ref' => '#/definitions/TestEntity.jsonld-write.input',
155155
]));
156156
}
157157

tests/Functional/OpenApiTest.php

Lines changed: 49 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -132,60 +132,47 @@ public function testErrorsAreDocumented(): void
132132
foreach (['title', 'detail', 'instance', 'type', 'status'] as $key) {
133133
$this->assertArrayHasKey($key, $res['components']['schemas']['Error']['properties']);
134134
}
135+
$this->assertSame([
136+
'readOnly' => true,
137+
'description' => 'A short, human-readable summary of the problem.',
138+
'type' => [
139+
0 => 'string',
140+
1 => 'null',
141+
],
142+
], $res['components']['schemas']['Error']['properties']['title']);
143+
$this->assertSame([
144+
'readOnly' => true,
145+
'description' => 'A human-readable explanation specific to this occurrence of the problem.',
146+
'type' => [
147+
0 => 'string',
148+
1 => 'null',
149+
],
150+
], $res['components']['schemas']['Error']['properties']['detail']);
151+
$this->assertSame([
152+
'readOnly' => true,
153+
'description' => 'A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced.',
154+
'type' => [
155+
0 => 'string',
156+
1 => 'null',
157+
],
158+
], $res['components']['schemas']['Error']['properties']['instance']);
159+
$this->assertSame([
160+
'readOnly' => true,
161+
'description' => 'A URI reference that identifies the problem type',
162+
'type' => 'string',
163+
], $res['components']['schemas']['Error']['properties']['type']);
164+
$this->assertSame([
165+
'type' => 'number',
166+
'examples' => [
167+
0 => 404,
168+
],
169+
'default' => 400,
170+
], $res['components']['schemas']['Error']['properties']['status']);
135171

136-
foreach (['title', 'detail', 'instance', 'type', 'status', '@id', '@type', '@context'] as $key) {
137-
$this->assertSame(['allOf' => [
138-
['$ref' => '#/components/schemas/HydraItemBaseSchema'],
139-
[
140-
'type' => 'object',
141-
'properties' => [
142-
'title' => [
143-
'readOnly' => true,
144-
'description' => 'A short, human-readable summary of the problem.',
145-
'type' => [
146-
0 => 'string',
147-
1 => 'null',
148-
],
149-
],
150-
'detail' => [
151-
'readOnly' => true,
152-
'description' => 'A human-readable explanation specific to this occurrence of the problem.',
153-
'type' => [
154-
0 => 'string',
155-
1 => 'null',
156-
],
157-
],
158-
'status' => [
159-
'type' => 'number',
160-
'examples' => [
161-
0 => 404,
162-
],
163-
'default' => 400,
164-
],
165-
'instance' => [
166-
'readOnly' => true,
167-
'description' => 'A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced.',
168-
'type' => [
169-
0 => 'string',
170-
1 => 'null',
171-
],
172-
],
173-
'type' => [
174-
'readOnly' => true,
175-
'description' => 'A URI reference that identifies the problem type',
176-
'type' => 'string',
177-
],
178-
'description' => [
179-
'readOnly' => true,
180-
'type' => [
181-
0 => 'string',
182-
1 => 'null',
183-
],
184-
],
185-
],
186-
],
187-
], 'description' => 'A representation of common errors.'], $res['components']['schemas']['Error.jsonld']);
188-
}
172+
$this->assertSame(['allOf' => [
173+
['$ref' => '#/components/schemas/HydraOutputBaseSchema'],
174+
['$ref' => '#/components/schemas/Error'],
175+
], 'description' => 'A representation of common errors.'], $res['components']['schemas']['Error.jsonld']);
189176

190177
foreach (['id', 'title', 'detail', 'instance', 'type', 'status', 'meta', 'source'] as $key) {
191178
$this->assertSame(['allOf' => [
@@ -239,14 +226,16 @@ public function testHasSchemasForMultipleFormats(): void
239226

240227
$res = $response->toArray();
241228
$this->assertArrayHasKey('Crud.jsonld', $res['components']['schemas']);
242-
$this->assertSame(['allOf' => [
243-
['$ref' => '#/components/schemas/HydraItemBaseSchema'],
244-
[
245-
'type' => 'object',
246-
'properties' => [
247-
'id' => ['type' => 'string'],
248-
],
229+
$this->assertSame([
230+
'type' => 'object',
231+
'description' => 'A resource used for OpenAPI tests.',
232+
'properties' => [
233+
'id' => ['type' => 'string'],
249234
],
235+
], $res['components']['schemas']['Crud']);
236+
$this->assertSame(['allOf' => [
237+
['$ref' => '#/components/schemas/HydraOutputBaseSchema'],
238+
['$ref' => '#/components/schemas/Crud'],
250239
], 'description' => 'A resource used for OpenAPI tests.'], $res['components']['schemas']['Crud.jsonld']);
251240
}
252241

tests/JsonSchema/Command/JsonSchemaGenerateCommandTest.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,28 @@ public function testExecuteWithJsonldFormatOption(): void
105105
{
106106
$this->tester->run(['command' => 'api:json-schema:generate', 'resource' => $this->entityClass, '--operation' => '_api_/dummies{._format}_post', '--format' => 'jsonld', '--type' => 'output']);
107107
$result = $this->tester->getDisplay();
108+
$json = json_decode($result, associative: true);
108109

109-
$this->assertStringContainsString('@id', $result);
110-
$this->assertStringContainsString('@context', $result);
111-
$this->assertStringContainsString('@type', $result);
110+
$this->assertArrayHasKey('Dummy.jsonld', $json['definitions']);
111+
$this->assertSame('#/definitions/HydraOutputBaseSchema', $json['definitions']['Dummy.jsonld']['allOf'][0]['$ref']);
112+
$this->assertArrayHasKey('@id', $json['definitions']['HydraOutputBaseSchema']['properties']);
113+
$this->assertArrayHasKey('@context', $json['definitions']['HydraOutputBaseSchema']['properties']);
114+
$this->assertArrayHasKey('@type', $json['definitions']['HydraOutputBaseSchema']['properties']);
115+
$this->assertSame(['@id', '@type'], $json['definitions']['HydraOutputBaseSchema']['required']);
112116
}
113117

114118
public function testExecuteWithJsonldTypeInput(): void
115119
{
116120
$this->tester->run(['command' => 'api:json-schema:generate', 'resource' => $this->entityClass, '--operation' => '_api_/dummies{._format}_post', '--format' => 'jsonld', '--type' => 'input']);
117121
$result = $this->tester->getDisplay();
122+
$json = json_decode($result, associative: true);
118123

119-
$this->assertStringNotContainsString('@id', $result);
120-
$this->assertStringNotContainsString('@context', $result);
121-
$this->assertStringNotContainsString('@type', $result);
124+
$this->assertArrayHasKey('Dummy.jsonld.input', $json['definitions']);
125+
$this->assertSame('#/definitions/HydraItemBaseSchema', $json['definitions']['Dummy.jsonld.input']['allOf'][0]['$ref']);
126+
$this->assertArrayHasKey('@id', $json['definitions']['HydraItemBaseSchema']['properties']);
127+
$this->assertArrayHasKey('@context', $json['definitions']['HydraItemBaseSchema']['properties']);
128+
$this->assertArrayHasKey('@type', $json['definitions']['HydraItemBaseSchema']['properties']);
129+
$this->assertArrayNotHasKey('required', $json['definitions']['HydraItemBaseSchema']);
122130
}
123131

124132
public function testExecuteWithJsonMergePatchTypeInput(): void
@@ -127,8 +135,8 @@ public function testExecuteWithJsonMergePatchTypeInput(): void
127135
$result = $this->tester->getDisplay();
128136
$json = json_decode($result, associative: true);
129137

130-
$this->assertArrayNotHasKey('Dummy', $json['definitions']);
131138
$this->assertArrayHasKey('Dummy.jsonMergePatch', $json['definitions']);
139+
$this->assertArrayNotHasKey('allOf', $json['definitions']['Dummy.jsonMergePatch']);;
132140
$this->assertArrayNotHasKey('required', $json['definitions']['Dummy.jsonMergePatch']);
133141
}
134142

tests/OpenApi/Command/OpenApiCommandTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ public function testBackedEnumExamplesAreNotLost(): void
147147
};
148148

149149
$assertExample($json['components']['schemas']['Issue6317']['properties'], 'id');
150-
$assertExample($json['components']['schemas']['Issue6317.jsonld']['allOf'][1]['properties'], 'id');
151150
$this->assertEquals($json['components']['schemas']['Issue6317.jsonhal']['allOf'][1]['$ref'], '#/components/schemas/Issue6317');
152151
}
153152

0 commit comments

Comments
 (0)