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

api-platform / core / 15775135891

20 Jun 2025 08:42AM UTC coverage: 22.065% (+0.2%) from 21.876%
15775135891

push

github

soyuka
Merge 4.1

13 of 103 new or added lines in 10 files covered. (12.62%)

868 existing lines in 35 files now uncovered.

11487 of 52060 relevant lines covered (22.06%)

21.72 hits per line

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

0.0
/src/Metadata/Tests/Extractor/XmlExtractorTest.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\Metadata\Tests\Extractor;
15

16
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
17
use ApiPlatform\Metadata\Extractor\XmlResourceExtractor;
18
use ApiPlatform\Metadata\Get;
19
use ApiPlatform\Metadata\GetCollection;
20
use ApiPlatform\Metadata\QueryParameter;
21
use ApiPlatform\Metadata\Tests\Fixtures\ApiResource\Comment;
22
use ApiPlatform\Metadata\Tests\Fixtures\ApiResource\User;
23
use PHPUnit\Framework\TestCase;
24
use Symfony\Component\Serializer\Exception\ExceptionInterface;
25

26
/**
27
 * @author Vincent Chalamon <vincentchalamon@gmail.com>
28
 */
29
class XmlExtractorTest extends TestCase
30
{
31
    public function testValidXML(): void
32
    {
33
        $extractor = new XmlResourceExtractor([__DIR__.'/xml/valid.xml']);
×
34
        $this->assertEquals([
×
35
            Comment::class => [
×
36
                [
×
37
                    'uriTemplate' => null,
×
38
                    'shortName' => null,
×
39
                    'description' => null,
×
40
                    'routePrefix' => null,
×
41
                    'stateless' => null,
×
42
                    'sunset' => null,
×
43
                    'acceptPatch' => null,
×
44
                    'host' => null,
×
45
                    'condition' => null,
×
46
                    'controller' => null,
×
47
                    'urlGenerationStrategy' => null,
×
48
                    'deprecationReason' => null,
×
49
                    'fetchPartial' => null,
×
50
                    'forceEager' => null,
×
51
                    'paginationClientEnabled' => null,
×
52
                    'paginationClientItemsPerPage' => null,
×
53
                    'paginationClientPartial' => null,
×
54
                    'paginationEnabled' => null,
×
55
                    'paginationFetchJoinCollection' => null,
×
56
                    'paginationUseOutputWalkers' => null,
×
57
                    'paginationItemsPerPage' => null,
×
58
                    'paginationMaximumItemsPerPage' => null,
×
59
                    'paginationPartial' => null,
×
60
                    'paginationType' => null,
×
61
                    'security' => null,
×
62
                    'securityMessage' => null,
×
63
                    'securityPostDenormalize' => null,
×
64
                    'securityPostDenormalizeMessage' => null,
×
65
                    'securityPostValidation' => null,
×
66
                    'securityPostValidationMessage' => null,
×
67
                    'queryParameterValidationEnabled' => null,
×
68
                    'strictQueryParameterValidation' => null,
×
69
                    'hideHydraOperation' => null,
×
70
                    'input' => null,
×
71
                    'output' => null,
×
72
                    'types' => null,
×
73
                    'formats' => null,
×
74
                    'uriVariables' => null,
×
75
                    'inputFormats' => null,
×
76
                    'outputFormats' => null,
×
77
                    'defaults' => null,
×
78
                    'requirements' => null,
×
79
                    'options' => null,
×
80
                    'status' => null,
×
81
                    'schemes' => null,
×
82
                    'cacheHeaders' => null,
×
83
                    'normalizationContext' => null,
×
84
                    'denormalizationContext' => null,
×
85
                    'collectDenormalizationErrors' => null,
×
86
                    'hydraContext' => null,
×
87
                    'openapi' => null,
×
88
                    'validationContext' => null,
×
89
                    'filters' => null,
×
90
                    'mercure' => null,
×
91
                    'messenger' => null,
×
92
                    'order' => null,
×
93
                    'paginationViaCursor' => null,
×
94
                    'exceptionToStatus' => null,
×
95
                    'extraProperties' => null,
×
96
                    'operations' => null,
×
97
                    'graphQlOperations' => null,
×
98
                    'processor' => null,
×
99
                    'provider' => null,
×
100
                    'read' => null,
×
101
                    'write' => null,
×
102
                    'stateOptions' => null,
×
103
                    'links' => null,
×
104
                    'headers' => null,
×
105
                    'parameters' => null,
×
106
                ],
×
107
                [
×
108
                    'uriTemplate' => '/users/{author}/comments{._format}',
×
109
                    'shortName' => null,
×
110
                    'description' => 'User comments',
×
111
                    'routePrefix' => null,
×
112
                    'stateless' => null,
×
113
                    'sunset' => null,
×
114
                    'acceptPatch' => null,
×
115
                    'host' => null,
×
116
                    'condition' => null,
×
117
                    'controller' => null,
×
118
                    'urlGenerationStrategy' => null,
×
119
                    'deprecationReason' => null,
×
120
                    'fetchPartial' => null,
×
121
                    'forceEager' => null,
×
122
                    'paginationClientEnabled' => null,
×
123
                    'paginationClientItemsPerPage' => null,
×
124
                    'paginationClientPartial' => null,
×
125
                    'paginationEnabled' => null,
×
126
                    'paginationFetchJoinCollection' => null,
×
127
                    'paginationUseOutputWalkers' => null,
×
128
                    'paginationItemsPerPage' => null,
×
129
                    'paginationMaximumItemsPerPage' => null,
×
130
                    'paginationPartial' => null,
×
131
                    'paginationType' => null,
×
132
                    'security' => null,
×
133
                    'securityMessage' => null,
×
134
                    'securityPostDenormalize' => null,
×
135
                    'securityPostDenormalizeMessage' => null,
×
136
                    'securityPostValidation' => null,
×
137
                    'securityPostValidationMessage' => null,
×
138
                    'queryParameterValidationEnabled' => null,
×
139
                    'strictQueryParameterValidation' => null,
×
140
                    'hideHydraOperation' => null,
×
141
                    'input' => null,
×
142
                    'output' => null,
×
143
                    'types' => ['someirischema', 'anotheririschema'],
×
144
                    'formats' => ['jsonld', 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
×
145
                    'uriVariables' => [
×
146
                        'author' => 'author',
×
147
                    ],
×
148
                    'inputFormats' => ['json' => 'application/merge-patch+json'],
×
149
                    'outputFormats' => ['json' => 'application/merge-patch+json'],
×
150
                    'defaults' => null,
×
151
                    'requirements' => null,
×
152
                    'options' => null,
×
153
                    'status' => null,
×
154
                    'schemes' => null,
×
155
                    'cacheHeaders' => [
×
156
                        'max_age' => 60,
×
157
                        'shared_max_age' => 120,
×
158
                        'vary' => ['Authorization', 'Accept-Language'],
×
159
                    ],
×
160
                    'normalizationContext' => [
×
161
                        'groups' => ['comment:read', 'comment:custom-read'],
×
162
                        'enabled' => true,
×
163
                    ],
×
164
                    'denormalizationContext' => [
×
165
                        'groups' => 'comment:write',
×
166
                    ],
×
167
                    'collectDenormalizationErrors' => null,
×
168
                    'hydraContext' => [
×
169
                        'foo' => ['bar' => 'baz'],
×
170
                    ],
×
171
                    'openapi' => null,
×
172
                    'validationContext' => null,
×
173
                    'filters' => ['comment.custom_filter'],
×
174
                    'mercure' => ['private' => true],
×
175
                    'messenger' => 'input',
×
176
                    'order' => ['foo', 'bar'],
×
177
                    'paginationViaCursor' => [
×
178
                        'id' => 'DESC',
×
179
                    ],
×
180
                    'exceptionToStatus' => [
×
181
                        ExceptionInterface::class => 400,
×
182
                    ],
×
183
                    'extraProperties' => null,
×
184
                    'operations' => [
×
185
                        [
×
186
                            'name' => 'custom_operation_name',
×
187
                            'class' => GetCollection::class,
×
188
                            'uriTemplate' => '/users/{author}/comments{._format}',
×
189
                            'shortName' => null,
×
190
                            'description' => 'User comments',
×
191
                            'routePrefix' => null,
×
192
                            'stateless' => null,
×
193
                            'sunset' => null,
×
194
                            'acceptPatch' => null,
×
195
                            'host' => null,
×
196
                            'condition' => null,
×
197
                            'controller' => null,
×
198
                            'urlGenerationStrategy' => null,
×
199
                            'deprecationReason' => null,
×
200
                            'fetchPartial' => null,
×
201
                            'forceEager' => null,
×
202
                            'paginationClientEnabled' => null,
×
203
                            'paginationClientItemsPerPage' => null,
×
204
                            'paginationClientPartial' => null,
×
205
                            'paginationEnabled' => null,
×
206
                            'paginationFetchJoinCollection' => null,
×
207
                            'paginationUseOutputWalkers' => null,
×
208
                            'paginationItemsPerPage' => null,
×
209
                            'paginationMaximumItemsPerPage' => null,
×
210
                            'paginationPartial' => null,
×
211
                            'paginationType' => null,
×
212
                            'security' => null,
×
213
                            'securityMessage' => null,
×
214
                            'securityPostDenormalize' => null,
×
215
                            'securityPostDenormalizeMessage' => null,
×
216
                            'securityPostValidation' => null,
×
217
                            'securityPostValidationMessage' => null,
×
218
                            'queryParameterValidationEnabled' => null,
×
219
                            'input' => null,
×
220
                            'output' => null,
×
221
                            'types' => ['someirischema', 'anotheririschema'],
×
222
                            'formats' => ['jsonld', 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
×
223
                            'uriVariables' => [
×
224
                                'author' => 'author',
×
225
                            ],
×
226
                            'inputFormats' => ['json' => 'application/merge-patch+json'],
×
227
                            'outputFormats' => ['json' => 'application/merge-patch+json'],
×
228
                            'defaults' => null,
×
229
                            'requirements' => null,
×
230
                            'options' => null,
×
231
                            'status' => null,
×
232
                            'schemes' => null,
×
233
                            'cacheHeaders' => [
×
234
                                'max_age' => 60,
×
235
                                'shared_max_age' => 120,
×
236
                                'vary' => ['Authorization', 'Accept-Language'],
×
237
                            ],
×
238
                            'normalizationContext' => [
×
239
                                'groups' => ['comment:read', 'comment:custom-read'],
×
240
                                'enabled' => true,
×
241
                            ],
×
242
                            'denormalizationContext' => [
×
243
                                'groups' => 'comment:write',
×
244
                            ],
×
245
                            'collectDenormalizationErrors' => null,
×
246
                            'hydraContext' => [
×
247
                                'foo' => ['bar' => 'baz'],
×
248
                            ],
×
249
                            'openapi' => null,
×
250
                            'validationContext' => null,
×
251
                            'filters' => ['comment.custom_filter'],
×
252
                            'mercure' => ['private' => true],
×
253
                            'messenger' => 'input',
×
254
                            'order' => ['foo', 'bar'],
×
255
                            'paginationViaCursor' => [
×
256
                                'id' => 'DESC',
×
257
                            ],
×
258
                            'exceptionToStatus' => [
×
259
                                ExceptionInterface::class => 400,
×
260
                            ],
×
261
                            'extraProperties' => null,
×
262
                            'read' => null,
×
263
                            'deserialize' => null,
×
264
                            'validate' => null,
×
265
                            'write' => null,
×
266
                            'serialize' => null,
×
267
                            'queryParameterValidate' => null,
×
268
                            'strictQueryParameterValidation' => null,
×
269
                            'hideHydraOperation' => null,
×
270
                            'collection' => null,
×
271
                            'method' => null,
×
272
                            'priority' => null,
×
273
                            'processor' => null,
×
274
                            'provider' => null,
×
275
                            'itemUriTemplate' => null,
×
276
                            'stateOptions' => null,
×
277
                            'links' => null,
×
278
                            'headers' => ['hello' => 'world'],
×
279
                            'parameters' => null,
×
280
                            'routeName' => 'custom_route_name',
×
281
                        ],
×
282
                        [
×
283
                            'name' => null,
×
284
                            'class' => Get::class,
×
285
                            'uriTemplate' => '/users/{userId}/comments/{id}{._format}',
×
286
                            'shortName' => null,
×
287
                            'description' => 'User comments',
×
288
                            'routePrefix' => null,
×
289
                            'stateless' => null,
×
290
                            'sunset' => null,
×
291
                            'acceptPatch' => null,
×
292
                            'host' => null,
×
293
                            'condition' => null,
×
294
                            'controller' => null,
×
295
                            'urlGenerationStrategy' => null,
×
296
                            'deprecationReason' => null,
×
297
                            'fetchPartial' => null,
×
298
                            'forceEager' => null,
×
299
                            'paginationClientEnabled' => null,
×
300
                            'paginationClientItemsPerPage' => null,
×
301
                            'paginationClientPartial' => null,
×
302
                            'paginationEnabled' => null,
×
303
                            'paginationFetchJoinCollection' => null,
×
304
                            'paginationUseOutputWalkers' => null,
×
305
                            'paginationItemsPerPage' => null,
×
306
                            'paginationMaximumItemsPerPage' => null,
×
307
                            'paginationPartial' => null,
×
308
                            'paginationType' => null,
×
309
                            'security' => null,
×
310
                            'securityMessage' => null,
×
311
                            'securityPostDenormalize' => null,
×
312
                            'securityPostDenormalizeMessage' => null,
×
313
                            'securityPostValidation' => null,
×
314
                            'securityPostValidationMessage' => null,
×
315
                            'queryParameterValidationEnabled' => null,
×
316
                            'input' => null,
×
317
                            'output' => null,
×
318
                            'types' => ['someirischema', 'anotheririschema'],
×
319
                            'formats' => ['jsonld', 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
×
320
                            'uriVariables' => [
×
321
                                'userId' => [
×
322
                                    'from_property' => 'author',
×
323
                                    'from_class' => User::class,
×
324
                                ],
×
325
                                'id' => 'id',
×
326
                            ],
×
327
                            'inputFormats' => ['json' => 'application/merge-patch+json'],
×
328
                            'outputFormats' => ['json' => 'application/merge-patch+json'],
×
329
                            'defaults' => null,
×
330
                            'requirements' => null,
×
331
                            'options' => null,
×
332
                            'status' => null,
×
333
                            'schemes' => null,
×
334
                            'cacheHeaders' => [
×
335
                                'max_age' => 60,
×
336
                                'shared_max_age' => 120,
×
337
                                'vary' => ['Authorization', 'Accept-Language'],
×
338
                            ],
×
339
                            'normalizationContext' => [
×
340
                                'groups' => ['comment:read', 'comment:custom-read'],
×
341
                                'enabled' => true,
×
342
                            ],
×
343
                            'denormalizationContext' => [
×
344
                                'groups' => 'comment:write',
×
345
                            ],
×
346
                            'collectDenormalizationErrors' => null,
×
347
                            'hydraContext' => [
×
348
                                'foo' => ['bar' => 'baz'],
×
349
                            ],
×
350
                            'openapi' => null,
×
351
                            'validationContext' => null,
×
352
                            'filters' => ['comment.custom_filter'],
×
353
                            'mercure' => ['private' => true],
×
354
                            'messenger' => 'input',
×
355
                            'order' => ['foo', 'bar'],
×
356
                            'paginationViaCursor' => [
×
357
                                'id' => 'DESC',
×
358
                            ],
×
359
                            'exceptionToStatus' => [
×
360
                                ExceptionInterface::class => 400,
×
361
                            ],
×
362
                            'extraProperties' => [
×
363
                                'foo' => 'bar',
×
364
                                'boolean' => true,
×
365
                            ],
×
366
                            'read' => null,
×
367
                            'deserialize' => null,
×
368
                            'validate' => null,
×
369
                            'write' => null,
×
370
                            'serialize' => null,
×
371
                            'queryParameterValidate' => null,
×
372
                            'strictQueryParameterValidation' => null,
×
373
                            'hideHydraOperation' => null,
×
374
                            'collection' => null,
×
375
                            'method' => null,
×
376
                            'priority' => null,
×
377
                            'processor' => null,
×
378
                            'provider' => null,
×
379
                            'stateOptions' => null,
×
380
                            'links' => null,
×
381
                            'headers' => ['hello' => 'world'],
×
382
                            'parameters' => [
×
383
                                'author' => new QueryParameter(
×
384
                                    key: 'author',
×
385
                                    required: true,
×
386
                                    schema: [
×
387
                                        'type' => 'string',
×
388
                                    ],
×
389
                                    extraProperties: ['foo' => 'bar']
×
390
                                ),
×
391
                            ],
×
392
                            'routeName' => null,
×
393
                        ],
×
394
                    ],
×
395
                    'graphQlOperations' => null,
×
396
                    'processor' => null,
×
397
                    'provider' => null,
×
398
                    'read' => null,
×
399
                    'write' => null,
×
400
                    'stateOptions' => null,
×
401
                    'links' => null,
×
402
                    'headers' => ['hello' => 'world'],
×
403
                    'parameters' => null,
×
404
                ],
×
405
            ],
×
406
        ], $extractor->getResources());
×
407
    }
408

409
    #[\PHPUnit\Framework\Attributes\DataProvider('getInvalidPaths')]
410
    public function testInvalidXML(string $path, string $error): void
411
    {
UNCOV
412
        $this->expectException(InvalidArgumentException::class);
×
UNCOV
413
        $this->expectExceptionMessageMatches($error);
×
414

UNCOV
415
        (new XmlResourceExtractor([$path]))->getResources();
×
416
    }
417

418
    public static function getInvalidPaths(): array
419
    {
UNCOV
420
        return [
×
UNCOV
421
            [
×
UNCOV
422
                __DIR__.'/xml/invalid/required_class.xml',
×
UNCOV
423
                "/^Error while parsing .+\/xml\/invalid\/required_class.xml: \[ERROR 1868\] Element '\{https:\/\/api-platform\.com\/schema\/metadata\/resources-3\.0\}resource': The attribute 'class' is required but missing\./",
×
424
            ],
×
425
        ];
×
426
    }
427
}
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