59
59
use ApiPlatform \OpenApi \Tests \Fixtures \Dummy ;
60
60
use ApiPlatform \OpenApi \Tests \Fixtures \DummyErrorResource ;
61
61
use ApiPlatform \OpenApi \Tests \Fixtures \DummyFilter ;
62
+ use ApiPlatform \OpenApi \Tests \Fixtures \Issue6872 \Diamond ;
62
63
use ApiPlatform \OpenApi \Tests \Fixtures \OutputDto ;
63
64
use ApiPlatform \State \Pagination \PaginationOptions ;
64
65
use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \WithParameter ;
@@ -85,6 +86,7 @@ public function testInvoke(): void
85
86
$ baseOperation = (new HttpOperation ())->withTypes (['http://schema.example.com/Dummy ' ])->withInputFormats (self ::OPERATION_FORMATS ['input_formats ' ])->withOutputFormats (self ::OPERATION_FORMATS ['output_formats ' ])->withClass (Dummy::class)->withOutput ([
86
87
'class ' => OutputDto::class,
87
88
])->withPaginationClientItemsPerPage (true )->withShortName ('Dummy ' )->withDescription ('This is a dummy ' );
89
+
88
90
$ dummyResourceWebhook = (new ApiResource ())->withOperations (new Operations ([
89
91
'dummy webhook ' => (new Get ())->withUriTemplate ('/dummy/{id} ' )->withShortName ('short ' )->withOpenapi (new Webhook ('first webhook ' )),
90
92
'an other dummy webhook ' => (new Post ())->withUriTemplate ('/dummies ' )->withShortName ('short something ' )->withOpenapi (new Webhook ('happy webhook ' , new Model \PathItem (post: new Operation (
@@ -272,13 +274,24 @@ public function testInvoke(): void
272
274
]))->withOperation ($ baseOperation ),
273
275
]));
274
276
277
+ $ diamondResource = (new ApiResource ())
278
+ ->withOperations (new Operations ([
279
+ 'getDiamondCollection ' => (new GetCollection (uriTemplate: '/diamonds ' ))
280
+ ->withSecurity ("is_granted('ROLE_USER') " )
281
+ ->withOperation ($ baseOperation ),
282
+ 'putDiamond ' => (new Put (uriTemplate: '/diamond/{id} ' ))
283
+ ->withSecurity ('' )
284
+ ->withOperation ($ baseOperation ),
285
+ ]));
286
+
275
287
$ resourceNameCollectionFactoryProphecy = $ this ->prophesize (ResourceNameCollectionFactoryInterface::class);
276
- $ resourceNameCollectionFactoryProphecy ->create ()->shouldBeCalled ()->willReturn (new ResourceNameCollection ([Dummy::class, WithParameter::class]));
288
+ $ resourceNameCollectionFactoryProphecy ->create ()->shouldBeCalled ()->willReturn (new ResourceNameCollection ([Dummy::class, WithParameter::class, Diamond::class ]));
277
289
278
290
$ resourceCollectionMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
279
291
$ resourceCollectionMetadataFactoryProphecy ->create (Dummy::class)->shouldBeCalled ()->willReturn (new ResourceMetadataCollection (Dummy::class, [$ dummyResource , $ dummyResourceWebhook ]));
280
292
$ resourceCollectionMetadataFactoryProphecy ->create (DummyErrorResource::class)->shouldBeCalled ()->willReturn (new ResourceMetadataCollection (DummyErrorResource::class, [new ApiResource (operations: [new ErrorOperation (name: 'err ' , description: 'nice one! ' )])]));
281
293
$ resourceCollectionMetadataFactoryProphecy ->create (WithParameter::class)->shouldBeCalled ()->willReturn (new ResourceMetadataCollection (WithParameter::class, [$ parameterResource ]));
294
+ $ resourceCollectionMetadataFactoryProphecy ->create (Diamond::class)->shouldBeCalled ()->willReturn (new ResourceMetadataCollection (Diamond::class, [$ diamondResource ]));
282
295
283
296
$ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
284
297
$ propertyNameCollectionFactoryProphecy ->create (Dummy::class, Argument::any ())->shouldBeCalled ()->willReturn (new PropertyNameCollection (['id ' , 'name ' , 'description ' , 'dummyDate ' , 'enum ' ]));
@@ -1171,5 +1184,20 @@ public function testInvoke(): void
1171
1184
],
1172
1185
deprecated: false
1173
1186
), $ paths ->getPath ('/erroredDummies ' )->getGet ());
1187
+
1188
+ $ diamondsGetPath = $ paths ->getPath ('/diamonds ' );
1189
+ $ diamondGetOperation = $ diamondsGetPath ->getGet ();
1190
+ $ diamondGetResponses = $ diamondGetOperation ->getResponses ();
1191
+
1192
+ $ this ->assertNotNull ($ diamondGetOperation );
1193
+ $ this ->assertArrayHasKey ('403 ' , $ diamondGetResponses );
1194
+ $ this ->assertSame ('Forbidden ' , $ diamondGetResponses ['403 ' ]->getDescription ());
1195
+
1196
+ $ diamondsPutPath = $ paths ->getPath ('/diamond/{id} ' );
1197
+ $ diamondPutOperation = $ diamondsPutPath ->getPut ();
1198
+ $ diamondPutResponses = $ diamondPutOperation ->getResponses ();
1199
+
1200
+ $ this ->assertNotNull ($ diamondPutOperation );
1201
+ $ this ->assertArrayNotHasKey ('403 ' , $ diamondPutResponses );
1174
1202
}
1175
1203
}
0 commit comments