• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 10737347263

06 Sep 2024 11:11AM UTC coverage: 7.645% (-0.01%) from 7.655%
10737347263

push

github

web-flow
Merge pull request #6591 from soyuka/merge-34

Merge 3.4

10 of 526 new or added lines in 17 files covered. (1.9%)

9692 existing lines in 300 files now uncovered.

12523 of 163810 relevant lines covered (7.64%)

22.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Hydra/Tests/Serializer/DocumentationNormalizerTest.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Hydra\Tests\Serializer;
15

16
use ApiPlatform\Documentation\Documentation;
17
use ApiPlatform\Hydra\Serializer\DocumentationNormalizer;
18
use ApiPlatform\Hydra\Tests\Fixtures\CustomConverter;
19
use ApiPlatform\JsonLd\ContextBuilder;
20
use ApiPlatform\Metadata\ApiProperty;
21
use ApiPlatform\Metadata\ApiResource;
22
use ApiPlatform\Metadata\Get;
23
use ApiPlatform\Metadata\GetCollection;
24
use ApiPlatform\Metadata\Operations;
25
use ApiPlatform\Metadata\Post;
26
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
27
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
28
use ApiPlatform\Metadata\Property\PropertyNameCollection;
29
use ApiPlatform\Metadata\Put;
30
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
31
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
32
use ApiPlatform\Metadata\Resource\ResourceNameCollection;
33
use ApiPlatform\Metadata\ResourceClassResolverInterface;
34
use ApiPlatform\Metadata\UrlGeneratorInterface;
35
use PHPUnit\Framework\TestCase;
36
use Prophecy\Argument;
37
use Prophecy\PhpUnit\ProphecyTrait;
38
use Symfony\Component\PropertyInfo\Type;
39

40
/**
41
 * @author Amrouche Hamza <hamza.simperfit@gmail.com>
42
 */
43
class DocumentationNormalizerTest extends TestCase
44
{
45
    use ProphecyTrait;
46

47
    public function testNormalize(): void
48
    {
49
        $resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class);
×
50
        $resourceMetadataFactoryProphecy->create('dummy')->shouldBeCalled()->willReturn(new ResourceMetadataCollection('dummy', [
×
51
            (new ApiResource())->withShortName('dummy')->withDescription('dummy')->withTypes(['#dummy'])->withOperations(new Operations([
×
52
                'get' => (new Get())->withHydraContext(['hydra:foo' => 'bar', 'hydra:title' => 'foobar'])->withTypes(['#dummy'])->withShortName('dummy'),
×
53
                'put' => (new Put())->withShortName('dummy'),
×
54
                'get_collection' => (new GetCollection())->withShortName('dummy'),
×
55
                'post' => (new Post())->withShortName('dummy'),
×
56
            ])),
×
57
            (new ApiResource())->withShortName('relatedDummy')->withOperations(new Operations(['get' => (new Get())->withTypes(['#relatedDummy'])->withShortName('relatedDummy')])),
×
58
        ]));
×
59
        $resourceMetadataFactoryProphecy->create('relatedDummy')->shouldBeCalled()->willReturn(new ResourceMetadataCollection('relatedDummy', [
×
60
            (new ApiResource())->withShortName('relatedDummy')->withOperations(new Operations(['get' => (new Get())->withShortName('relatedDummy')])),
×
61
        ]));
×
62

63
        $this->doTestNormalize($resourceMetadataFactoryProphecy->reveal());
×
64
    }
65

66
    private function doTestNormalize($resourceMetadataFactory = null): void
67
    {
68
        $title = 'Test Api';
×
69
        $desc = 'test ApiGerard';
×
70
        $version = '0.0.0';
×
71
        $documentation = new Documentation(new ResourceNameCollection(['dummy' => 'dummy']), $title, $desc, $version);
×
72

73
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
74
        $propertyNameCollectionFactoryProphecy->create('dummy', [])->shouldBeCalled()->willReturn(new PropertyNameCollection(['name', 'description', 'nameConverted', 'relatedDummy', 'iri']));
×
75

76
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
77
        $propertyMetadataFactoryProphecy->create('dummy', 'name', Argument::type('array'))->shouldBeCalled()->willReturn(
×
78
            (new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)])->withDescription('name')->withReadable(true)->withWritable(true)->withReadableLink(true)->withWritableLink(true)
×
79
        );
×
80
        $propertyMetadataFactoryProphecy->create('dummy', 'description', Argument::type('array'))->shouldBeCalled()->willReturn(
×
81
            (new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)])->withDescription('description')->withReadable(true)->withWritable(true)->withReadableLink(true)->withWritableLink(true)->withJsonldContext(['@type' => '@id'])
×
82
        );
×
83
        $propertyMetadataFactoryProphecy->create('dummy', 'nameConverted', Argument::type('array'))->shouldBeCalled()->willReturn(
×
84
            (new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)])->withDescription('name converted')->withReadable(true)->withWritable(true)->withReadableLink(true)->withWritableLink(true)
×
85
        );
×
86
        $propertyMetadataFactoryProphecy->create('dummy', 'relatedDummy', Argument::type('array'))->shouldBeCalled()->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_OBJECT, false, 'dummy', true, null, new Type(Type::BUILTIN_TYPE_OBJECT, false, 'relatedDummy'))])->withDescription('This is a name.')->withReadable(true)->withWritable(true)->withReadableLink(true)->withWritableLink(true));
×
87
        $propertyMetadataFactoryProphecy->create('dummy', 'iri', Argument::type('array'))->shouldBeCalled()->willReturn((new ApiProperty())->withIris(['https://schema.org/Dummy']));
×
88

89
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
90
        $resourceClassResolverProphecy->isResourceClass(Argument::type('string'))->willReturn(true);
×
91

92
        $urlGenerator = $this->prophesize(UrlGeneratorInterface::class);
×
93
        $urlGenerator->generate('api_entrypoint')->willReturn('/')->shouldBeCalledTimes(1);
×
94
        $urlGenerator->generate('api_doc', ['_format' => 'jsonld'])->willReturn('/doc')->shouldBeCalledTimes(1);
×
95

96
        $urlGenerator->generate('api_doc', ['_format' => 'jsonld'], 0)->willReturn('/doc')->shouldBeCalledTimes(1);
×
97

98
        $documentationNormalizer = new DocumentationNormalizer(
×
99
            $resourceMetadataFactory,
×
100
            $propertyNameCollectionFactoryProphecy->reveal(),
×
101
            $propertyMetadataFactoryProphecy->reveal(),
×
102
            $resourceClassResolverProphecy->reveal(),
×
103
            $urlGenerator->reveal(),
×
104
            new CustomConverter()
×
105
        );
×
106

107
        $expected = [
×
108
            '@context' => [
×
109
                '@vocab' => '/doc#',
×
110
                'hydra' => 'http://www.w3.org/ns/hydra/core#',
×
111
                'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
×
112
                'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
×
113
                'xmls' => 'http://www.w3.org/2001/XMLSchema#',
×
114
                'owl' => 'http://www.w3.org/2002/07/owl#',
×
115
                'schema' => 'https://schema.org/',
×
116
                'domain' => [
×
117
                    '@id' => 'rdfs:domain',
×
118
                    '@type' => '@id',
×
119
                ],
×
120
                'range' => [
×
121
                    '@id' => 'rdfs:range',
×
122
                    '@type' => '@id',
×
123
                ],
×
124
                'subClassOf' => [
×
125
                    '@id' => 'rdfs:subClassOf',
×
126
                    '@type' => '@id',
×
127
                ],
×
128
                'expects' => [
×
129
                    '@id' => 'hydra:expects',
×
130
                    '@type' => '@id',
×
131
                ],
×
132
                'returns' => [
×
133
                    '@id' => 'hydra:returns',
×
134
                    '@type' => '@id',
×
135
                ],
×
136
            ],
×
137
            '@id' => '/doc',
×
138
            '@type' => 'hydra:ApiDocumentation',
×
139
            'hydra:title' => 'Test Api',
×
140
            'hydra:description' => 'test ApiGerard',
×
141
            'hydra:supportedClass' => [
×
142
                [
×
143
                    '@id' => '#dummy',
×
144
                    '@type' => 'hydra:Class',
×
145
                    'rdfs:label' => 'dummy',
×
146
                    'hydra:title' => 'dummy',
×
147
                    'hydra:description' => 'dummy',
×
148
                    'hydra:supportedProperty' => [
×
149
                        [
×
150
                            '@type' => 'hydra:SupportedProperty',
×
151
                            'hydra:property' => [
×
152
                                '@id' => '#dummy/name',
×
153
                                '@type' => 'rdf:Property',
×
154
                                'rdfs:label' => 'name',
×
155
                                'domain' => '#dummy',
×
156
                                'range' => 'xmls:string',
×
157
                            ],
×
158
                            'hydra:title' => 'name',
×
159
                            'hydra:required' => false,
×
160
                            'hydra:readable' => true,
×
161
                            'hydra:writeable' => true,
×
162
                            'hydra:description' => 'name',
×
163
                        ],
×
164
                        [
×
165
                            '@type' => 'hydra:SupportedProperty',
×
166
                            'hydra:property' => [
×
167
                                '@id' => '#dummy/description',
×
168
                                '@type' => 'rdf:Property',
×
169
                                'rdfs:label' => 'description',
×
170
                                'domain' => '#dummy',
×
171
                                'range' => '@id',
×
172
                            ],
×
173
                            'hydra:title' => 'description',
×
174
                            'hydra:required' => false,
×
175
                            'hydra:readable' => true,
×
176
                            'hydra:writeable' => true,
×
177
                            'hydra:description' => 'description',
×
178
                        ],
×
179
                        [
×
180
                            '@type' => 'hydra:SupportedProperty',
×
181
                            'hydra:property' => [
×
182
                                '@id' => '#dummy/name_converted',
×
183
                                '@type' => 'rdf:Property',
×
184
                                'rdfs:label' => 'name_converted',
×
185
                                'domain' => '#dummy',
×
186
                                'range' => 'xmls:string',
×
187
                            ],
×
188
                            'hydra:title' => 'name_converted',
×
189
                            'hydra:required' => false,
×
190
                            'hydra:readable' => true,
×
191
                            'hydra:writeable' => true,
×
192
                            'hydra:description' => 'name converted',
×
193
                        ],
×
194
                        [
×
195
                            '@type' => 'hydra:SupportedProperty',
×
196
                            'hydra:property' => [
×
197
                                '@id' => '#dummy/relatedDummy',
×
198
                                '@type' => 'rdf:Property',
×
199
                                'rdfs:label' => 'relatedDummy',
×
200
                                'domain' => '#dummy',
×
201
                                'range' => '#relatedDummy',
×
202
                            ],
×
203
                            'hydra:title' => 'relatedDummy',
×
204
                            'hydra:required' => false,
×
205
                            'hydra:readable' => true,
×
206
                            'hydra:writeable' => true,
×
207
                            'hydra:description' => 'This is a name.',
×
208
                        ],
×
209
                        [
×
210
                            '@type' => 'hydra:SupportedProperty',
×
211
                            'hydra:property' => [
×
212
                                '@id' => 'https://schema.org/Dummy',
×
213
                                '@type' => 'rdf:Property',
×
214
                                'rdfs:label' => 'iri',
×
215
                                'domain' => '#dummy',
×
216
                            ],
×
217
                            'hydra:title' => 'iri',
×
218
                            'hydra:required' => null,
×
219
                            'hydra:readable' => null,
×
220
                            'hydra:writeable' => false,
×
221
                        ],
×
222
                    ],
×
223
                    'hydra:supportedOperation' => [
×
224
                        [
×
225
                            '@type' => ['hydra:Operation', 'schema:FindAction'],
×
226
                            'hydra:method' => 'GET',
×
227
                            'hydra:title' => 'foobar',
×
228
                            'rdfs:label' => 'foobar',
×
229
                            'returns' => '#dummy',
×
230
                            'hydra:foo' => 'bar',
×
231
                        ],
×
232
                        [
×
233
                            '@type' => ['hydra:Operation', 'schema:ReplaceAction'],
×
234
                            'expects' => '#dummy',
×
235
                            'hydra:method' => 'PUT',
×
236
                            'hydra:title' => 'Replaces the dummy resource.',
×
237
                            'rdfs:label' => 'Replaces the dummy resource.',
×
238
                            'returns' => '#dummy',
×
239
                        ],
×
240
                        [
×
241
                            '@type' => ['hydra:Operation', 'schema:FindAction'],
×
242
                            'hydra:method' => 'GET',
×
243
                            'hydra:title' => 'Retrieves a relatedDummy resource.',
×
244
                            'rdfs:label' => 'Retrieves a relatedDummy resource.',
×
245
                            'returns' => '#relatedDummy',
×
246
                        ],
×
247
                    ],
×
248
                ],
×
249
                [
×
250
                    '@id' => '#Entrypoint',
×
251
                    '@type' => 'hydra:Class',
×
252
                    'hydra:title' => 'The API entrypoint',
×
253
                    'hydra:supportedProperty' => [
×
254
                        [
×
255
                            '@type' => 'hydra:SupportedProperty',
×
256
                            'hydra:property' => [
×
257
                                '@id' => '#Entrypoint/dummy',
×
258
                                '@type' => 'hydra:Link',
×
259
                                'rdfs:label' => 'The collection of dummy resources',
×
260
                                'domain' => '#Entrypoint',
×
261
                                'rdfs:range' => [
×
262
                                    ['@id' => 'hydra:Collection'],
×
263
                                    [
×
264
                                        'owl:equivalentClass' => [
×
265
                                            'owl:onProperty' => ['@id' => 'hydra:member'],
×
266
                                            'owl:allValuesFrom' => ['@id' => '#dummy'],
×
267
                                        ],
×
268
                                    ],
×
269
                                ],
×
270
                                'hydra:supportedOperation' => [
×
271
                                    [
×
272
                                        '@type' => ['hydra:Operation', 'schema:FindAction'],
×
273
                                        'hydra:method' => 'GET',
×
274
                                        'hydra:title' => 'Retrieves the collection of dummy resources.',
×
275
                                        'rdfs:label' => 'Retrieves the collection of dummy resources.',
×
276
                                        'returns' => 'hydra:Collection',
×
277
                                    ],
×
278
                                    [
×
279
                                        '@type' => ['hydra:Operation', 'schema:CreateAction'],
×
280
                                        'expects' => '#dummy',
×
281
                                        'hydra:method' => 'POST',
×
282
                                        'hydra:title' => 'Creates a dummy resource.',
×
283
                                        'rdfs:label' => 'Creates a dummy resource.',
×
284
                                        'returns' => '#dummy',
×
285
                                    ],
×
286
                                ],
×
287
                            ],
×
288
                            'hydra:title' => 'The collection of dummy resources',
×
289
                            'hydra:readable' => true,
×
290
                            'hydra:writeable' => false,
×
291
                        ],
×
292
                    ],
×
293
                    'hydra:supportedOperation' => [
×
294
                        '@type' => 'hydra:Operation',
×
295
                        'hydra:method' => 'GET',
×
296
                        'rdfs:label' => 'The API entrypoint.',
×
297
                        'returns' => '#EntryPoint',
×
298
                    ],
×
299
                ],
×
300
                [
×
301
                    '@id' => '#ConstraintViolation',
×
302
                    '@type' => 'hydra:Class',
×
303
                    'hydra:title' => 'A constraint violation',
×
304
                    'hydra:supportedProperty' => [
×
305
                        [
×
306
                            '@type' => 'hydra:SupportedProperty',
×
307
                            'hydra:property' => [
×
308
                                '@id' => '#ConstraintViolation/propertyPath',
×
309
                                '@type' => 'rdf:Property',
×
310
                                'rdfs:label' => 'propertyPath',
×
311
                                'domain' => '#ConstraintViolation',
×
312
                                'range' => 'xmls:string',
×
313
                            ],
×
314
                            'hydra:title' => 'propertyPath',
×
315
                            'hydra:description' => 'The property path of the violation',
×
316
                            'hydra:readable' => true,
×
317
                            'hydra:writeable' => false,
×
318
                        ],
×
319
                        [
×
320
                            '@type' => 'hydra:SupportedProperty',
×
321
                            'hydra:property' => [
×
322
                                '@id' => '#ConstraintViolation/message',
×
323
                                '@type' => 'rdf:Property',
×
324
                                'rdfs:label' => 'message',
×
325
                                'domain' => '#ConstraintViolation',
×
326
                                'range' => 'xmls:string',
×
327
                            ],
×
328
                            'hydra:title' => 'message',
×
329
                            'hydra:description' => 'The message associated with the violation',
×
330
                            'hydra:readable' => true,
×
331
                            'hydra:writeable' => false,
×
332
                        ],
×
333
                    ],
×
334
                ],
×
335
                [
×
336
                    '@id' => '#ConstraintViolationList',
×
337
                    '@type' => 'hydra:Class',
×
338
                    'subClassOf' => 'hydra:Error',
×
339
                    'hydra:title' => 'A constraint violation list',
×
340
                    'hydra:supportedProperty' => [
×
341
                        [
×
342
                            '@type' => 'hydra:SupportedProperty',
×
343
                            'hydra:property' => [
×
344
                                '@id' => '#ConstraintViolationList/violations',
×
345
                                '@type' => 'rdf:Property',
×
346
                                'rdfs:label' => 'violations',
×
347
                                'domain' => '#ConstraintViolationList',
×
348
                                'range' => '#ConstraintViolation',
×
349
                            ],
×
350
                            'hydra:title' => 'violations',
×
351
                            'hydra:description' => 'The violations',
×
352
                            'hydra:readable' => true,
×
353
                            'hydra:writeable' => false,
×
354
                        ],
×
355
                    ],
×
356
                ],
×
357
            ],
×
358
            'hydra:entrypoint' => '/',
×
359
        ];
×
360

361
        $this->assertEquals($expected, $documentationNormalizer->normalize($documentation));
×
362
        $this->assertTrue($documentationNormalizer->supportsNormalization($documentation, 'jsonld'));
×
363
        $this->assertFalse($documentationNormalizer->supportsNormalization($documentation, 'hal'));
×
364
        $this->assertEmpty($documentationNormalizer->getSupportedTypes('json'));
×
365
        $this->assertSame([Documentation::class => true], $documentationNormalizer->getSupportedTypes($documentationNormalizer::FORMAT));
×
366
    }
367

368
    public function testNormalizeInputOutputClass(): void
369
    {
370
        $title = 'Test Api';
×
371
        $desc = 'test ApiGerard';
×
372
        $version = '0.0.0';
×
373
        $documentation = new Documentation(new ResourceNameCollection(['dummy' => 'dummy']), $title, $desc, $version);
×
374

375
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
376
        $propertyNameCollectionFactoryProphecy->create('inputClass', Argument::type('array'))->shouldBeCalled()->willReturn(new PropertyNameCollection(['a', 'b']));
×
377
        $propertyNameCollectionFactoryProphecy->create('outputClass', Argument::type('array'))->shouldBeCalled()->willReturn(new PropertyNameCollection(['c', 'd']));
×
378
        $propertyNameCollectionFactoryProphecy->create('dummy', Argument::type('array'))->shouldBeCalled()->willReturn(new PropertyNameCollection([]));
×
379

380
        $resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class);
×
381
        $resourceMetadataFactoryProphecy->create('dummy')->shouldBeCalled()->willReturn(new ResourceMetadataCollection('dummy', [
×
382
            (new ApiResource())->withShortName('dummy')->withDescription('dummy')->withTypes(['#dummy'])->withOperations(new Operations([
×
383
                'get' => (new Get())->withTypes(['#dummy'])->withShortName('dummy')->withInput(['class' => 'inputClass'])->withOutput(['class' => 'outputClass']),
×
384
                'put' => (new Put())->withShortName('dummy')->withInput(['class' => null])->withOutput(['class' => 'outputClass']),
×
385
                'get_collection' => (new GetCollection())->withShortName('dummy')->withInput(['class' => 'inputClass'])->withOutput(['class' => 'outputClass']),
×
386
                'post' => (new Post())->withShortName('dummy')->withOutput(['class' => null])->withInput(['class' => 'inputClass']),
×
387
            ])),
×
388
        ]));
×
389

390
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
391
        $propertyMetadataFactoryProphecy->create('inputClass', 'a', Argument::type('array'))->shouldBeCalled()->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)])->withDescription('a')->withReadable(true)->withWritable(true)->withReadableLink(true)->withWritableLink(true));
×
392
        $propertyMetadataFactoryProphecy->create('inputClass', 'b', Argument::type('array'))->shouldBeCalled()->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)])->withDescription('b')->withReadable(true)->withWritable(true)->withReadableLink(true)->withWritableLink(true));
×
393
        $propertyMetadataFactoryProphecy->create('outputClass', 'c', Argument::type('array'))->shouldBeCalled()->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)])->withDescription('c')->withReadable(true)->withWritable(true)->withReadableLink(true)->withWritableLink(true));
×
394
        $propertyMetadataFactoryProphecy->create('outputClass', 'd', Argument::type('array'))->shouldBeCalled()->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)])->withDescription('d')->withReadable(true)->withWritable(true)->withReadableLink(true)->withWritableLink(true));
×
395

396
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
397
        $resourceClassResolverProphecy->isResourceClass(Argument::type('string'))->willReturn(true);
×
398

399
        $urlGenerator = $this->prophesize(UrlGeneratorInterface::class);
×
400
        $urlGenerator->generate('api_entrypoint')->willReturn('/')->shouldBeCalledTimes(1);
×
401
        $urlGenerator->generate('api_doc', ['_format' => 'jsonld'])->willReturn('/doc')->shouldBeCalledTimes(1);
×
402
        $urlGenerator->generate('api_doc', ['_format' => 'jsonld'], 0)->willReturn('/doc')->shouldBeCalledTimes(1);
×
403

404
        $documentationNormalizer = new DocumentationNormalizer(
×
405
            $resourceMetadataFactoryProphecy->reveal(),
×
406
            $propertyNameCollectionFactoryProphecy->reveal(),
×
407
            $propertyMetadataFactoryProphecy->reveal(),
×
408
            $resourceClassResolverProphecy->reveal(),
×
409
            $urlGenerator->reveal()
×
410
        );
×
411

412
        $expected = [
×
413
            '@context' => [
×
414
                '@vocab' => '/doc#',
×
415
                'hydra' => 'http://www.w3.org/ns/hydra/core#',
×
416
                'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
×
417
                'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
×
418
                'xmls' => 'http://www.w3.org/2001/XMLSchema#',
×
419
                'owl' => 'http://www.w3.org/2002/07/owl#',
×
420
                'schema' => 'https://schema.org/',
×
421
                'domain' => [
×
422
                    '@id' => 'rdfs:domain',
×
423
                    '@type' => '@id',
×
424
                ],
×
425
                'range' => [
×
426
                    '@id' => 'rdfs:range',
×
427
                    '@type' => '@id',
×
428
                ],
×
429
                'subClassOf' => [
×
430
                    '@id' => 'rdfs:subClassOf',
×
431
                    '@type' => '@id',
×
432
                ],
×
433
                'expects' => [
×
434
                    '@id' => 'hydra:expects',
×
435
                    '@type' => '@id',
×
436
                ],
×
437
                'returns' => [
×
438
                    '@id' => 'hydra:returns',
×
439
                    '@type' => '@id',
×
440
                ],
×
441
            ],
×
442
            '@id' => '/doc',
×
443
            '@type' => 'hydra:ApiDocumentation',
×
444
            'hydra:title' => 'Test Api',
×
445
            'hydra:description' => 'test ApiGerard',
×
446
            'hydra:entrypoint' => '/',
×
447
            'hydra:supportedClass' => [
×
448
                [
×
449
                    '@id' => '#dummy',
×
450
                    '@type' => 'hydra:Class',
×
451
                    'rdfs:label' => 'dummy',
×
452
                    'hydra:title' => 'dummy',
×
453
                    'hydra:supportedProperty' => [
×
454
                        [
×
455
                            '@type' => 'hydra:SupportedProperty',
×
456
                            'hydra:property' => [
×
457
                                '@id' => '#dummy/a',
×
458
                                '@type' => 'rdf:Property',
×
459
                                'rdfs:label' => 'a',
×
460
                                'domain' => '#dummy',
×
461
                                'range' => 'xmls:string',
×
462
                            ],
×
463
                            'hydra:title' => 'a',
×
464
                            'hydra:required' => false,
×
465
                            'hydra:readable' => true,
×
466
                            'hydra:writeable' => true,
×
467
                            'hydra:description' => 'a',
×
468
                        ],
×
469
                        [
×
470
                            '@type' => 'hydra:SupportedProperty',
×
471
                            'hydra:property' => [
×
472
                                '@id' => '#dummy/b',
×
473
                                '@type' => 'rdf:Property',
×
474
                                'rdfs:label' => 'b',
×
475
                                'domain' => '#dummy',
×
476
                                'range' => 'xmls:string',
×
477
                            ],
×
478
                            'hydra:title' => 'b',
×
479
                            'hydra:required' => false,
×
480
                            'hydra:readable' => true,
×
481
                            'hydra:writeable' => true,
×
482
                            'hydra:description' => 'b',
×
483
                        ],
×
484
                        [
×
485
                            '@type' => 'hydra:SupportedProperty',
×
486
                            'hydra:property' => [
×
487
                                '@id' => '#dummy/c',
×
488
                                '@type' => 'rdf:Property',
×
489
                                'rdfs:label' => 'c',
×
490
                                'domain' => '#dummy',
×
491
                                'range' => 'xmls:string',
×
492
                            ],
×
493
                            'hydra:title' => 'c',
×
494
                            'hydra:required' => false,
×
495
                            'hydra:readable' => true,
×
496
                            'hydra:writeable' => true,
×
497
                            'hydra:description' => 'c',
×
498
                        ],
×
499
                        [
×
500
                            '@type' => 'hydra:SupportedProperty',
×
501
                            'hydra:property' => [
×
502
                                '@id' => '#dummy/d',
×
503
                                '@type' => 'rdf:Property',
×
504
                                'rdfs:label' => 'd',
×
505
                                'domain' => '#dummy',
×
506
                                'range' => 'xmls:string',
×
507
                            ],
×
508
                            'hydra:title' => 'd',
×
509
                            'hydra:required' => false,
×
510
                            'hydra:readable' => true,
×
511
                            'hydra:writeable' => true,
×
512
                            'hydra:description' => 'd',
×
513
                        ],
×
514
                    ],
×
515
                    'hydra:supportedOperation' => [
×
516
                        [
×
517
                            '@type' => [
×
518
                                'hydra:Operation',
×
519
                                'schema:FindAction',
×
520
                            ],
×
521
                            'hydra:method' => 'GET',
×
522
                            'hydra:title' => 'Retrieves a dummy resource.',
×
523
                            'rdfs:label' => 'Retrieves a dummy resource.',
×
524
                            'returns' => '#dummy',
×
525
                        ],
×
526
                        [
×
527
                            '@type' => [
×
528
                                'hydra:Operation',
×
529
                                'schema:ReplaceAction',
×
530
                            ],
×
531
                            'expects' => 'owl:Nothing',
×
532
                            'hydra:method' => 'PUT',
×
533
                            'hydra:title' => 'Replaces the dummy resource.',
×
534
                            'rdfs:label' => 'Replaces the dummy resource.',
×
535
                            'returns' => '#dummy',
×
536
                        ],
×
537
                    ],
×
538
                    'hydra:description' => 'dummy',
×
539
                ],
×
540
                [
×
541
                    '@id' => '#Entrypoint',
×
542
                    '@type' => 'hydra:Class',
×
543
                    'hydra:title' => 'The API entrypoint',
×
544
                    'hydra:supportedProperty' => [
×
545
                        [
×
546
                            '@type' => 'hydra:SupportedProperty',
×
547
                            'hydra:property' => [
×
548
                                '@id' => '#Entrypoint/dummy',
×
549
                                '@type' => 'hydra:Link',
×
550
                                'domain' => '#Entrypoint',
×
551
                                'rdfs:label' => 'The collection of dummy resources',
×
552
                                'rdfs:range' => [
×
553
                                    [
×
554
                                        '@id' => 'hydra:Collection',
×
555
                                    ],
×
556
                                    [
×
557
                                        'owl:equivalentClass' => [
×
558
                                            'owl:onProperty' => [
×
559
                                                '@id' => 'hydra:member',
×
560
                                            ],
×
561
                                            'owl:allValuesFrom' => [
×
562
                                                '@id' => '#dummy',
×
563
                                            ],
×
564
                                        ],
×
565
                                    ],
×
566
                                ],
×
567
                                'hydra:supportedOperation' => [
×
568
                                    [
×
569
                                        '@type' => [
×
570
                                            'hydra:Operation',
×
571
                                            'schema:FindAction',
×
572
                                        ],
×
573
                                        'hydra:method' => 'GET',
×
574
                                        'hydra:title' => 'Retrieves the collection of dummy resources.',
×
575
                                        'rdfs:label' => 'Retrieves the collection of dummy resources.',
×
576
                                        'returns' => 'hydra:Collection',
×
577
                                    ],
×
578
                                    [
×
579
                                        '@type' => [
×
580
                                            'hydra:Operation',
×
581
                                            'schema:CreateAction',
×
582
                                        ],
×
583
                                        'expects' => '#dummy',
×
584
                                        'hydra:method' => 'POST',
×
585
                                        'hydra:title' => 'Creates a dummy resource.',
×
586
                                        'rdfs:label' => 'Creates a dummy resource.',
×
587
                                        'returns' => 'owl:Nothing',
×
588
                                    ],
×
589
                                ],
×
590
                            ],
×
591
                            'hydra:title' => 'The collection of dummy resources',
×
592
                            'hydra:readable' => true,
×
593
                            'hydra:writeable' => false,
×
594
                        ],
×
595
                    ],
×
596
                    'hydra:supportedOperation' => [
×
597
                        '@type' => 'hydra:Operation',
×
598
                        'hydra:method' => 'GET',
×
599
                        'rdfs:label' => 'The API entrypoint.',
×
600
                        'returns' => '#EntryPoint',
×
601
                    ],
×
602
                ],
×
603
                2 => [
×
604
                    '@id' => '#ConstraintViolation',
×
605
                    '@type' => 'hydra:Class',
×
606
                    'hydra:title' => 'A constraint violation',
×
607
                    'hydra:supportedProperty' => [
×
608
                        [
×
609
                            '@type' => 'hydra:SupportedProperty',
×
610
                            'hydra:property' => [
×
611
                                '@id' => '#ConstraintViolation/propertyPath',
×
612
                                '@type' => 'rdf:Property',
×
613
                                'rdfs:label' => 'propertyPath',
×
614
                                'domain' => '#ConstraintViolation',
×
615
                                'range' => 'xmls:string',
×
616
                            ],
×
617
                            'hydra:title' => 'propertyPath',
×
618
                            'hydra:description' => 'The property path of the violation',
×
619
                            'hydra:readable' => true,
×
620
                            'hydra:writeable' => false,
×
621
                        ],
×
622
                        [
×
623
                            '@type' => 'hydra:SupportedProperty',
×
624
                            'hydra:property' => [
×
625
                                '@id' => '#ConstraintViolation/message',
×
626
                                '@type' => 'rdf:Property',
×
627
                                'rdfs:label' => 'message',
×
628
                                'domain' => '#ConstraintViolation',
×
629
                                'range' => 'xmls:string',
×
630
                            ],
×
631
                            'hydra:title' => 'message',
×
632
                            'hydra:description' => 'The message associated with the violation',
×
633
                            'hydra:readable' => true,
×
634
                            'hydra:writeable' => false,
×
635
                        ],
×
636
                    ],
×
637
                ],
×
638
                [
×
639
                    '@id' => '#ConstraintViolationList',
×
640
                    '@type' => 'hydra:Class',
×
641
                    'subClassOf' => 'hydra:Error',
×
642
                    'hydra:title' => 'A constraint violation list',
×
643
                    'hydra:supportedProperty' => [
×
644
                        [
×
645
                            '@type' => 'hydra:SupportedProperty',
×
646
                            'hydra:property' => [
×
647
                                '@id' => '#ConstraintViolationList/violations',
×
648
                                '@type' => 'rdf:Property',
×
649
                                'rdfs:label' => 'violations',
×
650
                                'domain' => '#ConstraintViolationList',
×
651
                                'range' => '#ConstraintViolation',
×
652
                            ],
×
653
                            'hydra:title' => 'violations',
×
654
                            'hydra:description' => 'The violations',
×
655
                            'hydra:readable' => true,
×
656
                            'hydra:writeable' => false,
×
657
                        ],
×
658
                    ],
×
659
                ],
×
660
            ],
×
661
        ];
×
662

663
        $this->assertEquals($expected, $documentationNormalizer->normalize($documentation));
×
664
    }
665

666
    public function testHasHydraContext(): void
667
    {
668
        $title = 'Test Api';
×
669
        $desc = 'test ApiGerard';
×
670
        $version = '0.0.0';
×
671
        $documentation = new Documentation(new ResourceNameCollection(['dummy' => 'dummy']), $title, $desc, $version);
×
672

673
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
674
        $propertyNameCollectionFactoryProphecy->create('dummy', Argument::type('array'))->shouldBeCalled()->willReturn(new PropertyNameCollection(['name']));
×
675

676
        $resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class);
×
677
        $resourceMetadataFactoryProphecy->create('dummy')->shouldBeCalled()->willReturn(new ResourceMetadataCollection('dummy', [
×
678
            (new ApiResource())->withShortName('dummy')->withDescription('dummy')->withTypes(['#dummy'])->withOperations(new Operations([
×
679
                'get' => (new Get())->withTypes(['#dummy'])->withShortName('dummy')->withInput(['class' => 'inputClass'])->withOutput(['class' => 'outputClass']),
×
680
            ])),
×
681
        ]));
×
682

683
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
684
        $propertyMetadataFactoryProphecy->create('dummy', 'name', Argument::type('array'))->shouldBeCalled()->willReturn(
×
685
            (new ApiProperty())
×
686
                ->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)])
×
687
                ->withDescription('b')
×
688
                ->withReadable(true)
×
689
                ->withWritable(true)
×
690
                ->withJsonldContext([
×
691
                    'hydra:property' => [
×
692
                        '@type' => 'https://schema.org/Enumeration',
×
693
                    ],
×
694
                ])
×
695
        );
×
696

697
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
698
        $resourceClassResolverProphecy->isResourceClass(Argument::type('string'))->willReturn(true);
×
699

700
        $urlGenerator = $this->prophesize(UrlGeneratorInterface::class);
×
701
        $urlGenerator->generate('api_entrypoint')->willReturn('/')->shouldBeCalledTimes(1);
×
702
        $urlGenerator->generate('api_doc', ['_format' => 'jsonld'])->willReturn('/doc')->shouldBeCalledTimes(1);
×
703
        $urlGenerator->generate('api_doc', ['_format' => 'jsonld'], 0)->willReturn('/doc')->shouldBeCalledTimes(1);
×
704

705
        $documentationNormalizer = new DocumentationNormalizer(
×
706
            $resourceMetadataFactoryProphecy->reveal(),
×
707
            $propertyNameCollectionFactoryProphecy->reveal(),
×
708
            $propertyMetadataFactoryProphecy->reveal(),
×
709
            $resourceClassResolverProphecy->reveal(),
×
710
            $urlGenerator->reveal()
×
711
        );
×
712

713
        $this->assertEquals([
×
714
            '@id' => '#dummy/name',
×
715
            '@type' => 'https://schema.org/Enumeration',
×
716
            'rdfs:label' => 'name',
×
717
            'domain' => '#dummy',
×
718
            'range' => 'xmls:string',
×
719
        ], $documentationNormalizer->normalize($documentation)['hydra:supportedClass'][0]['hydra:supportedProperty'][0]['hydra:property']);
×
720
    }
721

722
    public function testNormalizeWithoutPrefix(): void
723
    {
NEW
724
        $resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class);
×
NEW
725
        $resourceMetadataFactoryProphecy->create('dummy')->shouldBeCalled()->willReturn(new ResourceMetadataCollection('dummy', [
×
NEW
726
            (new ApiResource())->withShortName('dummy')->withDescription('dummy')->withTypes(['#dummy'])->withOperations(new Operations([
×
NEW
727
                'get' => (new Get())->withHydraContext(['foo' => 'bar', 'title' => 'foobar'])->withTypes(['#dummy'])->withShortName('dummy'),
×
NEW
728
                'put' => (new Put())->withShortName('dummy'),
×
NEW
729
                'get_collection' => (new GetCollection())->withShortName('dummy'),
×
NEW
730
                'post' => (new Post())->withShortName('dummy'),
×
NEW
731
            ])),
×
NEW
732
            (new ApiResource())->withShortName('relatedDummy')->withOperations(new Operations(['get' => (new Get())->withTypes(['#relatedDummy'])->withShortName('relatedDummy')])),
×
NEW
733
        ]));
×
NEW
734
        $resourceMetadataFactoryProphecy->create('relatedDummy')->shouldBeCalled()->willReturn(new ResourceMetadataCollection('relatedDummy', [
×
NEW
735
            (new ApiResource())->withShortName('relatedDummy')->withOperations(new Operations(['get' => (new Get())->withShortName('relatedDummy')])),
×
NEW
736
        ]));
×
737

NEW
738
        $title = 'Test Api';
×
NEW
739
        $desc = 'test ApiGerard';
×
NEW
740
        $version = '0.0.0';
×
NEW
741
        $documentation = new Documentation(new ResourceNameCollection(['dummy' => 'dummy']), $title, $desc, $version);
×
742

NEW
743
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
NEW
744
        $propertyNameCollectionFactoryProphecy->create('dummy', [])->shouldBeCalled()->willReturn(new PropertyNameCollection(['name', 'description', 'nameConverted', 'relatedDummy', 'iri']));
×
745

NEW
746
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
NEW
747
        $propertyMetadataFactoryProphecy->create('dummy', 'name', Argument::type('array'))->shouldBeCalled()->willReturn(
×
NEW
748
            (new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)])->withDescription('name')->withReadable(true)->withWritable(true)->withReadableLink(true)->withWritableLink(true)
×
NEW
749
        );
×
NEW
750
        $propertyMetadataFactoryProphecy->create('dummy', 'description', Argument::type('array'))->shouldBeCalled()->willReturn(
×
NEW
751
            (new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)])->withDescription('description')->withReadable(true)->withWritable(true)->withReadableLink(true)->withWritableLink(true)->withJsonldContext(['@type' => '@id'])
×
NEW
752
        );
×
NEW
753
        $propertyMetadataFactoryProphecy->create('dummy', 'nameConverted', Argument::type('array'))->shouldBeCalled()->willReturn(
×
NEW
754
            (new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)])->withDescription('name converted')->withReadable(true)->withWritable(true)->withReadableLink(true)->withWritableLink(true)
×
NEW
755
        );
×
NEW
756
        $propertyMetadataFactoryProphecy->create('dummy', 'relatedDummy', Argument::type('array'))->shouldBeCalled()->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_OBJECT, false, 'dummy', true, null, new Type(Type::BUILTIN_TYPE_OBJECT, false, 'relatedDummy'))])->withDescription('This is a name.')->withReadable(true)->withWritable(true)->withReadableLink(true)->withWritableLink(true));
×
NEW
757
        $propertyMetadataFactoryProphecy->create('dummy', 'iri', Argument::type('array'))->shouldBeCalled()->willReturn((new ApiProperty())->withIris(['https://schema.org/Dummy']));
×
758

NEW
759
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
NEW
760
        $resourceClassResolverProphecy->isResourceClass(Argument::type('string'))->willReturn(true);
×
761

NEW
762
        $urlGenerator = $this->prophesize(UrlGeneratorInterface::class);
×
NEW
763
        $urlGenerator->generate('api_entrypoint')->willReturn('/')->shouldBeCalledTimes(1);
×
NEW
764
        $urlGenerator->generate('api_doc', ['_format' => 'jsonld'])->willReturn('/doc')->shouldBeCalledTimes(1);
×
765

NEW
766
        $urlGenerator->generate('api_doc', ['_format' => 'jsonld'], 0)->willReturn('/doc')->shouldBeCalledTimes(1);
×
767

NEW
768
        $documentationNormalizer = new DocumentationNormalizer(
×
NEW
769
            $resourceMetadataFactoryProphecy->reveal(),
×
NEW
770
            $propertyNameCollectionFactoryProphecy->reveal(),
×
NEW
771
            $propertyMetadataFactoryProphecy->reveal(),
×
NEW
772
            $resourceClassResolverProphecy->reveal(),
×
NEW
773
            $urlGenerator->reveal(),
×
NEW
774
            new CustomConverter()
×
NEW
775
        );
×
776

NEW
777
        $expected = [
×
NEW
778
            '@context' => [
×
NEW
779
                '@vocab' => '/doc#',
×
NEW
780
                'hydra' => 'http://www.w3.org/ns/hydra/core#',
×
NEW
781
                'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
×
NEW
782
                'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
×
NEW
783
                'xmls' => 'http://www.w3.org/2001/XMLSchema#',
×
NEW
784
                'owl' => 'http://www.w3.org/2002/07/owl#',
×
NEW
785
                'schema' => 'https://schema.org/',
×
NEW
786
                'domain' => [
×
NEW
787
                    '@id' => 'rdfs:domain',
×
NEW
788
                    '@type' => '@id',
×
NEW
789
                ],
×
NEW
790
                'range' => [
×
NEW
791
                    '@id' => 'rdfs:range',
×
NEW
792
                    '@type' => '@id',
×
NEW
793
                ],
×
NEW
794
                'subClassOf' => [
×
NEW
795
                    '@id' => 'rdfs:subClassOf',
×
NEW
796
                    '@type' => '@id',
×
NEW
797
                ],
×
NEW
798
                'expects' => [
×
NEW
799
                    '@id' => 'expects',
×
NEW
800
                    '@type' => '@id',
×
NEW
801
                ],
×
NEW
802
                'returns' => [
×
NEW
803
                    '@id' => 'returns',
×
NEW
804
                    '@type' => '@id',
×
NEW
805
                ],
×
NEW
806
            ],
×
NEW
807
            '@id' => '/doc',
×
NEW
808
            '@type' => 'ApiDocumentation',
×
NEW
809
            'title' => 'Test Api',
×
NEW
810
            'description' => 'test ApiGerard',
×
NEW
811
            'supportedClass' => [
×
NEW
812
                [
×
NEW
813
                    '@id' => '#dummy',
×
NEW
814
                    '@type' => 'Class',
×
NEW
815
                    'rdfs:label' => 'dummy',
×
NEW
816
                    'title' => 'dummy',
×
NEW
817
                    'description' => 'dummy',
×
NEW
818
                    'supportedProperty' => [
×
NEW
819
                        [
×
NEW
820
                            '@type' => 'SupportedProperty',
×
NEW
821
                            'property' => [
×
NEW
822
                                '@id' => '#dummy/name',
×
NEW
823
                                '@type' => 'rdf:Property',
×
NEW
824
                                'rdfs:label' => 'name',
×
NEW
825
                                'domain' => '#dummy',
×
NEW
826
                                'range' => 'xmls:string',
×
NEW
827
                            ],
×
NEW
828
                            'title' => 'name',
×
NEW
829
                            'required' => false,
×
NEW
830
                            'readable' => true,
×
NEW
831
                            'writeable' => true,
×
NEW
832
                            'description' => 'name',
×
NEW
833
                        ],
×
NEW
834
                        [
×
NEW
835
                            '@type' => 'SupportedProperty',
×
NEW
836
                            'property' => [
×
NEW
837
                                '@id' => '#dummy/description',
×
NEW
838
                                '@type' => 'rdf:Property',
×
NEW
839
                                'rdfs:label' => 'description',
×
NEW
840
                                'domain' => '#dummy',
×
NEW
841
                                'range' => '@id',
×
NEW
842
                            ],
×
NEW
843
                            'title' => 'description',
×
NEW
844
                            'required' => false,
×
NEW
845
                            'readable' => true,
×
NEW
846
                            'writeable' => true,
×
NEW
847
                            'description' => 'description',
×
NEW
848
                        ],
×
NEW
849
                        [
×
NEW
850
                            '@type' => 'SupportedProperty',
×
NEW
851
                            'property' => [
×
NEW
852
                                '@id' => '#dummy/name_converted',
×
NEW
853
                                '@type' => 'rdf:Property',
×
NEW
854
                                'rdfs:label' => 'name_converted',
×
NEW
855
                                'domain' => '#dummy',
×
NEW
856
                                'range' => 'xmls:string',
×
NEW
857
                            ],
×
NEW
858
                            'title' => 'name_converted',
×
NEW
859
                            'required' => false,
×
NEW
860
                            'readable' => true,
×
NEW
861
                            'writeable' => true,
×
NEW
862
                            'description' => 'name converted',
×
NEW
863
                        ],
×
NEW
864
                        [
×
NEW
865
                            '@type' => 'SupportedProperty',
×
NEW
866
                            'property' => [
×
NEW
867
                                '@id' => '#dummy/relatedDummy',
×
NEW
868
                                '@type' => 'rdf:Property',
×
NEW
869
                                'rdfs:label' => 'relatedDummy',
×
NEW
870
                                'domain' => '#dummy',
×
NEW
871
                                'range' => '#relatedDummy',
×
NEW
872
                            ],
×
NEW
873
                            'title' => 'relatedDummy',
×
NEW
874
                            'required' => false,
×
NEW
875
                            'readable' => true,
×
NEW
876
                            'writeable' => true,
×
NEW
877
                            'description' => 'This is a name.',
×
NEW
878
                        ],
×
NEW
879
                        [
×
NEW
880
                            '@type' => 'SupportedProperty',
×
NEW
881
                            'property' => [
×
NEW
882
                                '@id' => 'https://schema.org/Dummy',
×
NEW
883
                                '@type' => 'rdf:Property',
×
NEW
884
                                'rdfs:label' => 'iri',
×
NEW
885
                                'domain' => '#dummy',
×
NEW
886
                            ],
×
NEW
887
                            'title' => 'iri',
×
NEW
888
                            'required' => null,
×
NEW
889
                            'readable' => null,
×
NEW
890
                            'writeable' => false,
×
NEW
891
                        ],
×
NEW
892
                    ],
×
NEW
893
                    'supportedOperation' => [
×
NEW
894
                        [
×
NEW
895
                            '@type' => ['Operation', 'schema:FindAction'],
×
NEW
896
                            'method' => 'GET',
×
NEW
897
                            'title' => 'foobar',
×
NEW
898
                            'rdfs:label' => 'foobar',
×
NEW
899
                            'returns' => '#dummy',
×
NEW
900
                            'foo' => 'bar',
×
NEW
901
                        ],
×
NEW
902
                        [
×
NEW
903
                            '@type' => ['Operation', 'schema:ReplaceAction'],
×
NEW
904
                            'expects' => '#dummy',
×
NEW
905
                            'method' => 'PUT',
×
NEW
906
                            'title' => 'Replaces the dummy resource.',
×
NEW
907
                            'rdfs:label' => 'Replaces the dummy resource.',
×
NEW
908
                            'returns' => '#dummy',
×
NEW
909
                        ],
×
NEW
910
                        [
×
NEW
911
                            '@type' => ['Operation', 'schema:FindAction'],
×
NEW
912
                            'method' => 'GET',
×
NEW
913
                            'title' => 'Retrieves a relatedDummy resource.',
×
NEW
914
                            'rdfs:label' => 'Retrieves a relatedDummy resource.',
×
NEW
915
                            'returns' => '#relatedDummy',
×
NEW
916
                        ],
×
NEW
917
                    ],
×
NEW
918
                ],
×
NEW
919
                [
×
NEW
920
                    '@id' => '#Entrypoint',
×
NEW
921
                    '@type' => 'Class',
×
NEW
922
                    'title' => 'The API entrypoint',
×
NEW
923
                    'supportedProperty' => [
×
NEW
924
                        [
×
NEW
925
                            '@type' => 'SupportedProperty',
×
NEW
926
                            'property' => [
×
NEW
927
                                '@id' => '#Entrypoint/dummy',
×
NEW
928
                                '@type' => 'Link',
×
NEW
929
                                'rdfs:label' => 'The collection of dummy resources',
×
NEW
930
                                'domain' => '#Entrypoint',
×
NEW
931
                                'rdfs:range' => [
×
NEW
932
                                    ['@id' => 'Collection'],
×
NEW
933
                                    [
×
NEW
934
                                        'owl:equivalentClass' => [
×
NEW
935
                                            'owl:onProperty' => ['@id' => 'member'],
×
NEW
936
                                            'owl:allValuesFrom' => ['@id' => '#dummy'],
×
NEW
937
                                        ],
×
NEW
938
                                    ],
×
NEW
939
                                ],
×
NEW
940
                                'supportedOperation' => [
×
NEW
941
                                    [
×
NEW
942
                                        '@type' => ['Operation', 'schema:FindAction'],
×
NEW
943
                                        'method' => 'GET',
×
NEW
944
                                        'title' => 'Retrieves the collection of dummy resources.',
×
NEW
945
                                        'rdfs:label' => 'Retrieves the collection of dummy resources.',
×
NEW
946
                                        'returns' => 'Collection',
×
NEW
947
                                    ],
×
NEW
948
                                    [
×
NEW
949
                                        '@type' => ['Operation', 'schema:CreateAction'],
×
NEW
950
                                        'expects' => '#dummy',
×
NEW
951
                                        'method' => 'POST',
×
NEW
952
                                        'title' => 'Creates a dummy resource.',
×
NEW
953
                                        'rdfs:label' => 'Creates a dummy resource.',
×
NEW
954
                                        'returns' => '#dummy',
×
NEW
955
                                    ],
×
NEW
956
                                ],
×
NEW
957
                            ],
×
NEW
958
                            'title' => 'The collection of dummy resources',
×
NEW
959
                            'readable' => true,
×
NEW
960
                            'writeable' => false,
×
NEW
961
                        ],
×
NEW
962
                    ],
×
NEW
963
                    'supportedOperation' => [
×
NEW
964
                        '@type' => 'Operation',
×
NEW
965
                        'method' => 'GET',
×
NEW
966
                        'rdfs:label' => 'The API entrypoint.',
×
NEW
967
                        'returns' => '#EntryPoint',
×
NEW
968
                    ],
×
NEW
969
                ],
×
NEW
970
                [
×
NEW
971
                    '@id' => '#ConstraintViolation',
×
NEW
972
                    '@type' => 'Class',
×
NEW
973
                    'title' => 'A constraint violation',
×
NEW
974
                    'supportedProperty' => [
×
NEW
975
                        [
×
NEW
976
                            '@type' => 'SupportedProperty',
×
NEW
977
                            'property' => [
×
NEW
978
                                '@id' => '#ConstraintViolation/propertyPath',
×
NEW
979
                                '@type' => 'rdf:Property',
×
NEW
980
                                'rdfs:label' => 'propertyPath',
×
NEW
981
                                'domain' => '#ConstraintViolation',
×
NEW
982
                                'range' => 'xmls:string',
×
NEW
983
                            ],
×
NEW
984
                            'title' => 'propertyPath',
×
NEW
985
                            'description' => 'The property path of the violation',
×
NEW
986
                            'readable' => true,
×
NEW
987
                            'writeable' => false,
×
NEW
988
                        ],
×
NEW
989
                        [
×
NEW
990
                            '@type' => 'SupportedProperty',
×
NEW
991
                            'property' => [
×
NEW
992
                                '@id' => '#ConstraintViolation/message',
×
NEW
993
                                '@type' => 'rdf:Property',
×
NEW
994
                                'rdfs:label' => 'message',
×
NEW
995
                                'domain' => '#ConstraintViolation',
×
NEW
996
                                'range' => 'xmls:string',
×
NEW
997
                            ],
×
NEW
998
                            'title' => 'message',
×
NEW
999
                            'description' => 'The message associated with the violation',
×
NEW
1000
                            'readable' => true,
×
NEW
1001
                            'writeable' => false,
×
NEW
1002
                        ],
×
NEW
1003
                    ],
×
NEW
1004
                ],
×
NEW
1005
                [
×
NEW
1006
                    '@id' => '#ConstraintViolationList',
×
NEW
1007
                    '@type' => 'Class',
×
NEW
1008
                    'subClassOf' => 'Error',
×
NEW
1009
                    'title' => 'A constraint violation list',
×
NEW
1010
                    'supportedProperty' => [
×
NEW
1011
                        [
×
NEW
1012
                            '@type' => 'SupportedProperty',
×
NEW
1013
                            'property' => [
×
NEW
1014
                                '@id' => '#ConstraintViolationList/violations',
×
NEW
1015
                                '@type' => 'rdf:Property',
×
NEW
1016
                                'rdfs:label' => 'violations',
×
NEW
1017
                                'domain' => '#ConstraintViolationList',
×
NEW
1018
                                'range' => '#ConstraintViolation',
×
NEW
1019
                            ],
×
NEW
1020
                            'title' => 'violations',
×
NEW
1021
                            'description' => 'The violations',
×
NEW
1022
                            'readable' => true,
×
NEW
1023
                            'writeable' => false,
×
NEW
1024
                        ],
×
NEW
1025
                    ],
×
NEW
1026
                ],
×
NEW
1027
            ],
×
NEW
1028
            'entrypoint' => '/',
×
NEW
1029
        ];
×
1030

NEW
1031
        $this->assertEquals($expected, $documentationNormalizer->normalize($documentation, null, [ContextBuilder::HYDRA_CONTEXT_HAS_PREFIX => false]));
×
1032
    }
1033
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc