5858use ApiPlatform \OpenApi \Tests \Fixtures \Dummy ;
5959use ApiPlatform \OpenApi \Tests \Fixtures \DummyErrorResource ;
6060use ApiPlatform \OpenApi \Tests \Fixtures \DummyFilter ;
61+ use ApiPlatform \OpenApi \Tests \Fixtures \Issue6872 \Diamond ;
6162use ApiPlatform \OpenApi \Tests \Fixtures \OutputDto ;
6263use ApiPlatform \State \Pagination \PaginationOptions ;
6364use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \WithParameter ;
@@ -82,6 +83,7 @@ public function testInvoke(): void
8283 $ 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 ([
8384 'class ' => OutputDto::class,
8485 ])->withPaginationClientItemsPerPage (true )->withShortName ('Dummy ' )->withDescription ('This is a dummy ' );
86+
8587 $ dummyResourceWebhook = (new ApiResource ())->withOperations (new Operations ([
8688 'dummy webhook ' => (new Get ())->withUriTemplate ('/dummy/{id} ' )->withShortName ('short ' )->withOpenapi (new Webhook ('first webhook ' )),
8789 'an other dummy webhook ' => (new Post ())->withUriTemplate ('/dummies ' )->withShortName ('short something ' )->withOpenapi (new Webhook ('happy webhook ' , new Model \PathItem (post: new Operation (
@@ -269,13 +271,23 @@ public function testInvoke(): void
269271 ]))->withOperation ($ baseOperation ),
270272 ]));
271273
274+ $ diamondResource = (new ApiResource ())
275+ ->withOperations (new Operations ([
276+ 'getDiamondCollection ' => (new GetCollection (uriTemplate: '/diamonds ' ))
277+ ->withSecurity ("is_granted('ROLE_USER') " )
278+ ->withOperation ($ baseOperation ),
279+ 'putDiamond ' => (new Put (uriTemplate: '/diamond/{id} ' ))
280+ ->withOperation ($ baseOperation ),
281+ ]));
282+
272283 $ resourceNameCollectionFactoryProphecy = $ this ->prophesize (ResourceNameCollectionFactoryInterface::class);
273- $ resourceNameCollectionFactoryProphecy ->create ()->shouldBeCalled ()->willReturn (new ResourceNameCollection ([Dummy::class, WithParameter::class]));
284+ $ resourceNameCollectionFactoryProphecy ->create ()->shouldBeCalled ()->willReturn (new ResourceNameCollection ([Dummy::class, WithParameter::class, Diamond::class ]));
274285
275286 $ resourceCollectionMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
276287 $ resourceCollectionMetadataFactoryProphecy ->create (Dummy::class)->shouldBeCalled ()->willReturn (new ResourceMetadataCollection (Dummy::class, [$ dummyResource , $ dummyResourceWebhook ]));
277288 $ resourceCollectionMetadataFactoryProphecy ->create (DummyErrorResource::class)->shouldBeCalled ()->willReturn (new ResourceMetadataCollection (DummyErrorResource::class, [new ApiResource (operations: [new ErrorOperation (name: 'err ' , description: 'nice one! ' )])]));
278289 $ resourceCollectionMetadataFactoryProphecy ->create (WithParameter::class)->shouldBeCalled ()->willReturn (new ResourceMetadataCollection (WithParameter::class, [$ parameterResource ]));
290+ $ resourceCollectionMetadataFactoryProphecy ->create (Diamond::class)->shouldBeCalled ()->willReturn (new ResourceMetadataCollection (Diamond::class, [$ diamondResource ]));
279291
280292 $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
281293 $ propertyNameCollectionFactoryProphecy ->create (Dummy::class, Argument::any ())->shouldBeCalled ()->willReturn (new PropertyNameCollection (['id ' , 'name ' , 'description ' , 'dummyDate ' , 'enum ' ]));
@@ -1162,5 +1174,20 @@ public function testInvoke(): void
11621174 ],
11631175 deprecated: false
11641176 ), $ paths ->getPath ('/erroredDummies ' )->getGet ());
1177+
1178+ $ diamondsGetPath = $ paths ->getPath ('/diamonds ' );
1179+ $ diamondGetOperation = $ diamondsGetPath ->getGet ();
1180+ $ diamondGetResponses = $ diamondGetOperation ->getResponses ();
1181+
1182+ $ this ->assertNotNull ($ diamondGetOperation );
1183+ $ this ->assertArrayHasKey ('403 ' , $ diamondGetResponses );
1184+ $ this ->assertSame ('Forbidden ' , $ diamondGetResponses ['403 ' ]->getDescription ());
1185+
1186+ $ diamondsPutPath = $ paths ->getPath ('/diamond/{id} ' );
1187+ $ diamondPutOperation = $ diamondsPutPath ->getPut ();
1188+ $ diamondPutResponses = $ diamondPutOperation ->getResponses ();
1189+
1190+ $ this ->assertNotNull ($ diamondPutOperation );
1191+ $ this ->assertArrayNotHasKey ('403 ' , $ diamondPutResponses );
11651192 }
11661193}
0 commit comments