5959use ApiPlatform \OpenApi \Tests \Fixtures \Dummy ;
6060use ApiPlatform \OpenApi \Tests \Fixtures \DummyErrorResource ;
6161use ApiPlatform \OpenApi \Tests \Fixtures \DummyFilter ;
62+ use ApiPlatform \OpenApi \Tests \Fixtures \Issue6872 \Diamond ;
6263use ApiPlatform \OpenApi \Tests \Fixtures \OutputDto ;
6364use ApiPlatform \State \Pagination \PaginationOptions ;
6465use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \WithParameter ;
@@ -85,6 +86,7 @@ public function testInvoke(): void
8586 $ 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 ([
8687 'class ' => OutputDto::class,
8788 ])->withPaginationClientItemsPerPage (true )->withShortName ('Dummy ' )->withDescription ('This is a dummy ' );
89+
8890 $ dummyResourceWebhook = (new ApiResource ())->withOperations (new Operations ([
8991 'dummy webhook ' => (new Get ())->withUriTemplate ('/dummy/{id} ' )->withShortName ('short ' )->withOpenapi (new Webhook ('first webhook ' )),
9092 '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,23 @@ public function testInvoke(): void
272274 ]))->withOperation ($ baseOperation ),
273275 ]));
274276
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+ ->withOperation ($ baseOperation ),
284+ ]));
285+
275286 $ resourceNameCollectionFactoryProphecy = $ this ->prophesize (ResourceNameCollectionFactoryInterface::class);
276- $ resourceNameCollectionFactoryProphecy ->create ()->shouldBeCalled ()->willReturn (new ResourceNameCollection ([Dummy::class, WithParameter::class]));
287+ $ resourceNameCollectionFactoryProphecy ->create ()->shouldBeCalled ()->willReturn (new ResourceNameCollection ([Dummy::class, WithParameter::class, Diamond::class ]));
277288
278289 $ resourceCollectionMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
279290 $ resourceCollectionMetadataFactoryProphecy ->create (Dummy::class)->shouldBeCalled ()->willReturn (new ResourceMetadataCollection (Dummy::class, [$ dummyResource , $ dummyResourceWebhook ]));
280291 $ resourceCollectionMetadataFactoryProphecy ->create (DummyErrorResource::class)->shouldBeCalled ()->willReturn (new ResourceMetadataCollection (DummyErrorResource::class, [new ApiResource (operations: [new ErrorOperation (name: 'err ' , description: 'nice one! ' )])]));
281292 $ resourceCollectionMetadataFactoryProphecy ->create (WithParameter::class)->shouldBeCalled ()->willReturn (new ResourceMetadataCollection (WithParameter::class, [$ parameterResource ]));
293+ $ resourceCollectionMetadataFactoryProphecy ->create (Diamond::class)->shouldBeCalled ()->willReturn (new ResourceMetadataCollection (Diamond::class, [$ diamondResource ]));
282294
283295 $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
284296 $ propertyNameCollectionFactoryProphecy ->create (Dummy::class, Argument::any ())->shouldBeCalled ()->willReturn (new PropertyNameCollection (['id ' , 'name ' , 'description ' , 'dummyDate ' , 'enum ' ]));
@@ -1171,5 +1183,20 @@ public function testInvoke(): void
11711183 ],
11721184 deprecated: false
11731185 ), $ paths ->getPath ('/erroredDummies ' )->getGet ());
1186+
1187+ $ diamondsGetPath = $ paths ->getPath ('/diamonds ' );
1188+ $ diamondGetOperation = $ diamondsGetPath ->getGet ();
1189+ $ diamondGetResponses = $ diamondGetOperation ->getResponses ();
1190+
1191+ $ this ->assertNotNull ($ diamondGetOperation );
1192+ $ this ->assertArrayHasKey ('403 ' , $ diamondGetResponses );
1193+ $ this ->assertSame ('Forbidden ' , $ diamondGetResponses ['403 ' ]->getDescription ());
1194+
1195+ $ diamondsPutPath = $ paths ->getPath ('/diamond/{id} ' );
1196+ $ diamondPutOperation = $ diamondsPutPath ->getPut ();
1197+ $ diamondPutResponses = $ diamondPutOperation ->getResponses ();
1198+
1199+ $ this ->assertNotNull ($ diamondPutOperation );
1200+ $ this ->assertArrayNotHasKey ('403 ' , $ diamondPutResponses );
11741201 }
11751202}
0 commit comments