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

api-platform / core / 5650127293

pending completion
5650127293

push

github

web-flow
fix: don't implement deprecated CacheableSupportsMethodInterface with Symfony 6.3+ (#5696)

* fix: don't implement deprecated CacheableSupportsMethodInterface

* fix: a check, and add tests

* fix ApiGatewayNormalizerTest

* more fixes

* fix more tests

* fix lowest

* only trigger the deprecation for Symfony 6.3

167 of 167 new or added lines in 23 files covered. (100.0%)

10865 of 18368 relevant lines covered (59.15%)

19.9 hits per line

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

0.0
/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.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\OpenApi\Tests\Serializer;
15

16
use ApiPlatform\OpenApi\Model\Info;
17
use ApiPlatform\OpenApi\Model\Paths;
18
use ApiPlatform\OpenApi\OpenApi;
19
use ApiPlatform\OpenApi\Serializer\ApiGatewayNormalizer;
20
use ApiPlatform\OpenApi\Serializer\OpenApiNormalizer;
21
use PHPUnit\Framework\TestCase;
22
use Prophecy\Argument;
23
use Prophecy\PhpUnit\ProphecyTrait;
24
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
25
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
26
use Symfony\Component\Serializer\Serializer;
27

28
final class ApiGatewayNormalizerTest extends TestCase
29
{
30
    use ProphecyTrait;
31

32
    /**
33
     * @group legacy
34
     */
35
    public function testSupportsNormalization(): void
36
    {
37
        $normalizerProphecy = $this->prophesize(NormalizerInterface::class);
×
38
        $normalizerProphecy->supportsNormalization(OpenApiNormalizer::FORMAT, OpenApi::class)->willReturn(true);
×
39
        if (!method_exists(Serializer::class, 'getSupportedTypes')) {
×
40
            $normalizerProphecy->willImplement(CacheableSupportsMethodInterface::class);
×
41
            $normalizerProphecy->hasCacheableSupportsMethod()->willReturn(true);
×
42
        }
43

44
        $normalizer = new ApiGatewayNormalizer($normalizerProphecy->reveal());
×
45

46
        $this->assertTrue($normalizer->supportsNormalization(OpenApiNormalizer::FORMAT, OpenApi::class));
×
47

48
        if (!method_exists(Serializer::class, 'getSupportedTypes')) {
×
49
            $this->assertTrue($normalizer->hasCacheableSupportsMethod());
×
50
        }
51
    }
52

53
    public function testNormalize(): void
54
    {
55
        $swaggerDocument = [
×
56
            'paths' => new \ArrayObject([
×
57
                '/dummies' => [
×
58
                    'post' => new \ArrayObject([
×
59
                        'parameters' => [
×
60
                            [
×
61
                                'name' => 'dummy',
×
62
                                'in' => 'body',
×
63
                                'schema' => [
×
64
                                    '$ref' => '#/definitions/Dummy',
×
65
                                ],
×
66
                            ],
×
67
                        ],
×
68
                        'responses' => [
×
69
                            201 => [
×
70
                                'schema' => [
×
71
                                    '$ref' => '#/definitions/Dummy-list_details',
×
72
                                ],
×
73
                            ],
×
74
                        ],
×
75
                    ]),
×
76
                    'get' => new \ArrayObject([
×
77
                        'parameters' => [
×
78
                            [
×
79
                                'name' => 'relatedDummy',
×
80
                                'in' => 'query',
×
81
                                'required' => false,
×
82
                                'type' => 'string',
×
83
                            ],
×
84
                            [
×
85
                                'name' => 'relatedDummy[]',
×
86
                                'in' => 'query',
×
87
                                'required' => false,
×
88
                                'type' => 'string',
×
89
                            ],
×
90
                        ],
×
91
                        'responses' => [
×
92
                            200 => [
×
93
                                'schema' => [
×
94
                                    'type' => 'array',
×
95
                                    'items' => [
×
96
                                        '$ref' => '#/definitions/Dummy-list',
×
97
                                    ],
×
98
                                ],
×
99
                            ],
×
100
                        ],
×
101
                    ]),
×
102
                ],
×
103
                '/dummies/{id}' => [
×
104
                    'get' => new \ArrayObject([
×
105
                        'parameters' => [
×
106
                            [
×
107
                                'name' => 'id',
×
108
                                'in' => 'path',
×
109
                                'required' => true,
×
110
                                'type' => 'string',
×
111
                            ],
×
112
                        ],
×
113
                        'responses' => [
×
114
                            200 => [
×
115
                                'schema' => [
×
116
                                    '$ref' => '#/definitions/Dummy-list_details',
×
117
                                ],
×
118
                            ],
×
119
                        ],
×
120
                    ]),
×
121
                ],
×
122
                '/dummies/{id}/what' => [
×
123
                    'post' => new \ArrayObject([
×
124
                        'parameters' => [
×
125
                            [
×
126
                                'name' => 'dummy',
×
127
                                'in' => 'body',
×
128
                                'schema' => [
×
129
                                    '$ref' => '#/definitions/Dummy:InputDto',
×
130
                                ],
×
131
                            ],
×
132
                        ],
×
133
                        'responses' => [
×
134
                            200 => [
×
135
                                'schema' => [
×
136
                                    '$ref' => '#/definitions/Dummy:OutputDto',
×
137
                                ],
×
138
                            ],
×
139
                        ],
×
140
                    ]),
×
141
                ],
×
142
            ]),
×
143
            'components' => ['schemas' => [
×
144
                'Dummy' => new \ArrayObject([
×
145
                    'properties' => [
×
146
                        'id' => [
×
147
                            'readOnly' => true,
×
148
                            'type' => 'integer',
×
149
                        ],
×
150
                        'description' => [
×
151
                            'type' => 'string',
×
152
                        ],
×
153
                    ],
×
154
                ]),
×
155
                'Dummy-list' => new \ArrayObject([
×
156
                    'properties' => [
×
157
                        'id' => [
×
158
                            'readOnly' => true,
×
159
                            'type' => 'integer',
×
160
                        ],
×
161
                        'description' => [
×
162
                            'type' => 'string',
×
163
                        ],
×
164
                    ],
×
165
                ]),
×
166
                'Dummy-list_details' => new \ArrayObject([
×
167
                    'properties' => [
×
168
                        'id' => [
×
169
                            'readOnly' => true,
×
170
                            'type' => 'integer',
×
171
                        ],
×
172
                        'description' => [
×
173
                            'type' => 'string',
×
174
                        ],
×
175
                        'relatedDummy' => new \ArrayObject([
×
176
                            '$ref' => '#/definitions/RelatedDummy-list_details',
×
177
                        ]),
×
178
                    ],
×
179
                ]),
×
180
                'Dummy:OutputDto' => new \ArrayObject([
×
181
                    'type' => 'object',
×
182
                    'properties' => [
×
183
                        'baz' => new \ArrayObject([
×
184
                            'readOnly' => true,
×
185
                            'type' => 'string',
×
186
                        ]),
×
187
                        'bat' => new \ArrayObject([
×
188
                            'type' => 'integer',
×
189
                        ]),
×
190
                    ],
×
191
                ]),
×
192
                'Dummy:InputDto' => new \ArrayObject([
×
193
                    'type' => 'object',
×
194
                    'properties' => [
×
195
                        'foo' => new \ArrayObject([
×
196
                            'type' => 'string',
×
197
                        ]),
×
198
                        'bar' => new \ArrayObject([
×
199
                            'type' => 'integer',
×
200
                        ]),
×
201
                    ],
×
202
                ]),
×
203
                'RelatedDummy-list_details' => new \ArrayObject([
×
204
                    'type' => 'object',
×
205
                    'properties' => [
×
206
                        'name' => new \ArrayObject([
×
207
                            'type' => 'string',
×
208
                        ]),
×
209
                    ],
×
210
                ]),
×
211
            ]],
×
212
        ];
×
213

214
        $modifiedSwaggerDocument = [
×
215
            'paths' => new \ArrayObject([
×
216
                '/dummies' => [
×
217
                    'post' => new \ArrayObject([
×
218
                        'parameters' => [
×
219
                            [
×
220
                                'name' => 'dummy',
×
221
                                'in' => 'body',
×
222
                                'schema' => [
×
223
                                    '$ref' => '#/definitions/Dummy',
×
224
                                ],
×
225
                            ],
×
226
                        ],
×
227
                        'responses' => [
×
228
                            201 => [
×
229
                                'schema' => [
×
230
                                    '$ref' => '#/definitions/Dummylistdetails',
×
231
                                ],
×
232
                            ],
×
233
                        ],
×
234
                    ]),
×
235
                    'get' => new \ArrayObject([
×
236
                        'parameters' => [
×
237
                            [
×
238
                                'name' => 'relatedDummy',
×
239
                                'in' => 'query',
×
240
                                'required' => false,
×
241
                                'type' => 'string',
×
242
                            ],
×
243
                        ],
×
244
                        'responses' => [
×
245
                            200 => [
×
246
                                'schema' => [
×
247
                                    'type' => 'array',
×
248
                                    'items' => [
×
249
                                        '$ref' => '#/definitions/Dummylist',
×
250
                                    ],
×
251
                                ],
×
252
                            ],
×
253
                        ],
×
254
                    ]),
×
255
                ],
×
256
                '/dummies/{id}' => [
×
257
                    'get' => new \ArrayObject([
×
258
                        'parameters' => [
×
259
                            [
×
260
                                'name' => 'id',
×
261
                                'in' => 'path',
×
262
                                'required' => true,
×
263
                                'type' => 'string',
×
264
                            ],
×
265
                        ],
×
266
                        'responses' => [
×
267
                            200 => [
×
268
                                'schema' => [
×
269
                                    '$ref' => '#/definitions/Dummylistdetails',
×
270
                                ],
×
271
                            ],
×
272
                        ],
×
273
                    ]),
×
274
                ],
×
275
                '/dummies/{id}/what' => [
×
276
                    'post' => new \ArrayObject([
×
277
                        'parameters' => [
×
278
                            [
×
279
                                'name' => 'dummy',
×
280
                                'in' => 'body',
×
281
                                'schema' => [
×
282
                                    '$ref' => '#/definitions/DummyInputDto',
×
283
                                ],
×
284
                            ],
×
285
                        ],
×
286
                        'responses' => [
×
287
                            200 => [
×
288
                                'schema' => [
×
289
                                    '$ref' => '#/definitions/DummyOutputDto',
×
290
                                ],
×
291
                            ],
×
292
                        ],
×
293
                    ]),
×
294
                ],
×
295
            ]),
×
296
            'components' => ['schemas' => [
×
297
                'Dummy' => new \ArrayObject([
×
298
                    'properties' => [
×
299
                        'id' => [
×
300
                            'type' => 'integer',
×
301
                        ],
×
302
                        'description' => [
×
303
                            'type' => 'string',
×
304
                        ],
×
305
                    ],
×
306
                ]),
×
307
                'Dummylist' => new \ArrayObject([
×
308
                    'properties' => [
×
309
                        'id' => [
×
310
                            'type' => 'integer',
×
311
                        ],
×
312
                        'description' => [
×
313
                            'type' => 'string',
×
314
                        ],
×
315
                    ],
×
316
                ]),
×
317
                'Dummylistdetails' => new \ArrayObject([
×
318
                    'properties' => [
×
319
                        'id' => [
×
320
                            'type' => 'integer',
×
321
                        ],
×
322
                        'description' => [
×
323
                            'type' => 'string',
×
324
                        ],
×
325
                        'relatedDummy' => new \ArrayObject([
×
326
                            '$ref' => '#/definitions/RelatedDummylistdetails',
×
327
                        ]),
×
328
                    ],
×
329
                ]),
×
330
                'DummyOutputDto' => new \ArrayObject([
×
331
                    'type' => 'object',
×
332
                    'properties' => [
×
333
                        'baz' => new \ArrayObject([
×
334
                            'type' => 'string',
×
335
                        ]),
×
336
                        'bat' => new \ArrayObject([
×
337
                            'type' => 'integer',
×
338
                        ]),
×
339
                    ],
×
340
                ]),
×
341
                'DummyInputDto' => new \ArrayObject([
×
342
                    'type' => 'object',
×
343
                    'properties' => [
×
344
                        'foo' => new \ArrayObject([
×
345
                            'type' => 'string',
×
346
                        ]),
×
347
                        'bar' => new \ArrayObject([
×
348
                            'type' => 'integer',
×
349
                        ]),
×
350
                    ],
×
351
                ]),
×
352
                'RelatedDummylistdetails' => new \ArrayObject([
×
353
                    'type' => 'object',
×
354
                    'properties' => [
×
355
                        'name' => new \ArrayObject([
×
356
                            'type' => 'string',
×
357
                        ]),
×
358
                    ],
×
359
                ]),
×
360
            ]],
×
361
            'basePath' => '/',
×
362
        ];
×
363

364
        $documentation = $this->getOpenApi();
×
365
        $normalizerProphecy = $this->prophesize(NormalizerInterface::class);
×
366
        $normalizerProphecy->normalize($documentation, OpenApiNormalizer::FORMAT, [
×
367
            ApiGatewayNormalizer::API_GATEWAY => true,
×
368
        ])->willReturn($swaggerDocument);
×
369

370
        $normalizer = new ApiGatewayNormalizer($normalizerProphecy->reveal());
×
371

372
        $this->assertEquals($modifiedSwaggerDocument, $normalizer->normalize($documentation, OpenApiNormalizer::FORMAT, [
×
373
            ApiGatewayNormalizer::API_GATEWAY => true,
×
374
        ]));
×
375
    }
376

377
    public function testNormalizeNotInApiGatewayContext(): void
378
    {
379
        $documentation = $this->getOpenApi();
×
380

381
        $swaggerDocument = [
×
382
            'paths' => new \ArrayObject([
×
383
                '/dummies' => [
×
384
                    'post' => new \ArrayObject([
×
385
                        'parameters' => [
×
386
                            [
×
387
                                'name' => 'dummy',
×
388
                                'in' => 'body',
×
389
                                'schema' => [
×
390
                                    '$ref' => '#/definitions/Dummy',
×
391
                                ],
×
392
                            ],
×
393
                        ],
×
394
                        'responses' => [
×
395
                            201 => [
×
396
                                'schema' => [
×
397
                                    '$ref' => '#/definitions/Dummy-list_details',
×
398
                                ],
×
399
                            ],
×
400
                        ],
×
401
                    ]),
×
402
                    'get' => new \ArrayObject([
×
403
                        'parameters' => [
×
404
                            [
×
405
                                'name' => 'relatedDummy',
×
406
                                'in' => 'query',
×
407
                                'required' => false,
×
408
                                'type' => 'string',
×
409
                            ],
×
410
                            [
×
411
                                'name' => 'relatedDummy[]',
×
412
                                'in' => 'query',
×
413
                                'required' => false,
×
414
                                'type' => 'string',
×
415
                            ],
×
416
                        ],
×
417
                        'responses' => [
×
418
                            200 => [
×
419
                                'schema' => [
×
420
                                    'type' => 'array',
×
421
                                    'items' => [
×
422
                                        '$ref' => '#/definitions/Dummy-list',
×
423
                                    ],
×
424
                                ],
×
425
                            ],
×
426
                        ],
×
427
                    ]),
×
428
                ],
×
429
                '/dummies/{id}' => [
×
430
                    'get' => new \ArrayObject([
×
431
                        'parameters' => [
×
432
                            [
×
433
                                'name' => 'id',
×
434
                                'in' => 'path',
×
435
                                'required' => true,
×
436
                                'type' => 'string',
×
437
                            ],
×
438
                        ],
×
439
                        'responses' => [
×
440
                            200 => [
×
441
                                'schema' => [
×
442
                                    '$ref' => '#/definitions/Dummy-list_details',
×
443
                                ],
×
444
                            ],
×
445
                        ],
×
446
                    ]),
×
447
                ],
×
448
                '/dummies/{id}/what' => [
×
449
                    'post' => new \ArrayObject([
×
450
                        'parameters' => [
×
451
                            [
×
452
                                'name' => 'dummy',
×
453
                                'in' => 'body',
×
454
                                'schema' => [
×
455
                                    '$ref' => '#/definitions/Dummy:InputDto',
×
456
                                ],
×
457
                            ],
×
458
                        ],
×
459
                        'responses' => [
×
460
                            200 => [
×
461
                                'schema' => [
×
462
                                    '$ref' => '#/definitions/Dummy:OutputDto',
×
463
                                ],
×
464
                            ],
×
465
                        ],
×
466
                    ]),
×
467
                ],
×
468
            ]),
×
469
            'components' => ['schemas' => new \ArrayObject([
×
470
                'Dummy' => new \ArrayObject([
×
471
                    'properties' => [
×
472
                        'id' => [
×
473
                            'readOnly' => true,
×
474
                            'type' => 'integer',
×
475
                        ],
×
476
                        'description' => [
×
477
                            'type' => 'string',
×
478
                        ],
×
479
                    ],
×
480
                ]),
×
481
                'Dummy-list' => new \ArrayObject([
×
482
                    'properties' => [
×
483
                        'id' => [
×
484
                            'readOnly' => true,
×
485
                            'type' => 'integer',
×
486
                        ],
×
487
                        'description' => [
×
488
                            'type' => 'string',
×
489
                        ],
×
490
                    ],
×
491
                ]),
×
492
                'Dummy-list_details' => new \ArrayObject([
×
493
                    'properties' => [
×
494
                        'id' => [
×
495
                            'readOnly' => true,
×
496
                            'type' => 'integer',
×
497
                        ],
×
498
                        'description' => [
×
499
                            'type' => 'string',
×
500
                        ],
×
501
                        'relatedDummy' => new \ArrayObject([
×
502
                            '$ref' => '#/definitions/RelatedDummy-list_details',
×
503
                        ]),
×
504
                    ],
×
505
                ]),
×
506
                'Dummy:OutputDto' => new \ArrayObject([
×
507
                    'type' => 'object',
×
508
                    'properties' => [
×
509
                        'baz' => new \ArrayObject([
×
510
                            'readOnly' => true,
×
511
                            'type' => 'string',
×
512
                        ]),
×
513
                        'bat' => new \ArrayObject([
×
514
                            'type' => 'integer',
×
515
                        ]),
×
516
                    ],
×
517
                ]),
×
518
                'Dummy:InputDto' => new \ArrayObject([
×
519
                    'type' => 'object',
×
520
                    'properties' => [
×
521
                        'foo' => new \ArrayObject([
×
522
                            'type' => 'string',
×
523
                        ]),
×
524
                        'bar' => new \ArrayObject([
×
525
                            'type' => 'integer',
×
526
                        ]),
×
527
                    ],
×
528
                ]),
×
529
                'RelatedDummy-list_details' => new \ArrayObject([
×
530
                    'type' => 'object',
×
531
                    'properties' => [
×
532
                        'name' => new \ArrayObject([
×
533
                            'type' => 'string',
×
534
                        ]),
×
535
                    ],
×
536
                ]),
×
537
            ])],
×
538
        ];
×
539

540
        $normalizerProphecy = $this->prophesize(NormalizerInterface::class);
×
541
        $normalizerProphecy->normalize($documentation, OpenApiNormalizer::FORMAT, Argument::type('array'))->willReturn($swaggerDocument);
×
542

543
        $normalizer = new ApiGatewayNormalizer($normalizerProphecy->reveal());
×
544

545
        $this->assertEquals($swaggerDocument, $normalizer->normalize($documentation, OpenApiNormalizer::FORMAT));
×
546
    }
547

548
    private function getOpenApi(): OpenApi
549
    {
550
        return new OpenApi(new Info('test', '0'), [], new Paths());
×
551
    }
552
}
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

© 2026 Coveralls, Inc