58
58
use ApiPlatform \OpenApi \Tests \Fixtures \Dummy ;
59
59
use ApiPlatform \OpenApi \Tests \Fixtures \DummyErrorResource ;
60
60
use ApiPlatform \OpenApi \Tests \Fixtures \DummyFilter ;
61
+ use ApiPlatform \OpenApi \Tests \Fixtures \Issue6872 \Diamond ;
61
62
use ApiPlatform \OpenApi \Tests \Fixtures \OutputDto ;
62
63
use ApiPlatform \State \Pagination \PaginationOptions ;
63
64
use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \WithParameter ;
@@ -82,6 +83,7 @@ public function testInvoke(): void
82
83
$ 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 ([
83
84
'class ' => OutputDto::class,
84
85
])->withPaginationClientItemsPerPage (true )->withShortName ('Dummy ' )->withDescription ('This is a dummy ' );
86
+
85
87
$ dummyResourceWebhook = (new ApiResource ())->withOperations (new Operations ([
86
88
'dummy webhook ' => (new Get ())->withUriTemplate ('/dummy/{id} ' )->withShortName ('short ' )->withOpenapi (new Webhook ('first webhook ' )),
87
89
'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
269
271
]))->withOperation ($ baseOperation ),
270
272
]));
271
273
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
+
272
283
$ 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 ]));
274
285
275
286
$ resourceCollectionMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
276
287
$ resourceCollectionMetadataFactoryProphecy ->create (Dummy::class)->shouldBeCalled ()->willReturn (new ResourceMetadataCollection (Dummy::class, [$ dummyResource , $ dummyResourceWebhook ]));
277
288
$ resourceCollectionMetadataFactoryProphecy ->create (DummyErrorResource::class)->shouldBeCalled ()->willReturn (new ResourceMetadataCollection (DummyErrorResource::class, [new ApiResource (operations: [new ErrorOperation (name: 'err ' , description: 'nice one! ' )])]));
278
289
$ resourceCollectionMetadataFactoryProphecy ->create (WithParameter::class)->shouldBeCalled ()->willReturn (new ResourceMetadataCollection (WithParameter::class, [$ parameterResource ]));
290
+ $ resourceCollectionMetadataFactoryProphecy ->create (Diamond::class)->shouldBeCalled ()->willReturn (new ResourceMetadataCollection (Diamond::class, [$ diamondResource ]));
279
291
280
292
$ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
281
293
$ propertyNameCollectionFactoryProphecy ->create (Dummy::class, Argument::any ())->shouldBeCalled ()->willReturn (new PropertyNameCollection (['id ' , 'name ' , 'description ' , 'dummyDate ' , 'enum ' ]));
@@ -1162,5 +1174,20 @@ public function testInvoke(): void
1162
1174
],
1163
1175
deprecated: false
1164
1176
), $ 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 );
1165
1192
}
1166
1193
}
0 commit comments