@@ -335,12 +335,6 @@ private function doTestNormalize($resourceMetadataFactory = null): void
335335 'domain ' => '#Entrypoint ' ,
336336 'range ' => [
337337 ['@id ' => 'hydra:Collection ' ],
338- [
339- 'owl:equivalentClass ' => [
340- 'owl:onProperty ' => ['@id ' => 'hydra:member ' ],
341- 'owl:allValuesFrom ' => ['@id ' => '#dummy ' ],
342- ],
343- ],
344338 ],
345339 'owl:maxCardinality ' => 1 ,
346340 'hydra:supportedOperation ' => [
@@ -365,6 +359,10 @@ private function doTestNormalize($resourceMetadataFactory = null): void
365359 'hydra:description ' => 'The collection of dummy resources ' ,
366360 'hydra:readable ' => true ,
367361 'hydra:writeable ' => false ,
362+ 'hydra:manages ' => [
363+ 'hydra:property ' => 'hydra:member ' ,
364+ 'hydra:object ' => '#dummy ' ,
365+ ],
368366 ],
369367 ],
370368 'hydra:supportedOperation ' => [
@@ -900,12 +898,6 @@ public function testNormalizeWithoutPrefix(): void
900898 'domain ' => '#Entrypoint ' ,
901899 'range ' => [
902900 ['@id ' => 'hydra:Collection ' ],
903- [
904- 'owl:equivalentClass ' => [
905- 'owl:onProperty ' => ['@id ' => 'hydra:member ' ],
906- 'owl:allValuesFrom ' => ['@id ' => '#dummy ' ],
907- ],
908- ],
909901 ],
910902 'owl:maxCardinality ' => 1 ,
911903 'supportedOperation ' => [
@@ -930,6 +922,10 @@ public function testNormalizeWithoutPrefix(): void
930922 'description ' => 'The collection of dummy resources ' ,
931923 'readable ' => true ,
932924 'writeable ' => false ,
925+ 'manages ' => [
926+ 'property ' => 'hydra:member ' ,
927+ 'object ' => '#dummy ' ,
928+ ],
933929 ],
934930 ],
935931 'supportedOperation ' => [
@@ -1170,4 +1166,56 @@ public function testNormalizeNoEntrypointAndHideHydraOperation(): void
11701166
11711167 $ this ->assertEquals ($ expected , $ documentationNormalizer ->normalize ($ documentation , null , [ContextBuilder::HYDRA_CONTEXT_HAS_PREFIX => false ]));
11721168 }
1169+
1170+ public function testManagesBlock (): void
1171+ {
1172+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
1173+ $ resourceMetadataFactoryProphecy ->create ('dummy ' )->shouldBeCalled ()->willReturn (new ResourceMetadataCollection ('dummy ' , [
1174+ (new ApiResource ())->withShortName ('dummy ' )->withDescription ('dummy ' )->withTypes (['#dummy ' ])->withOperations (new Operations ([
1175+ 'get ' => (new Get ())->withTypes (['#dummy ' ])->withShortName ('dummy ' ),
1176+ 'get_collection ' => (new GetCollection ())->withShortName ('dummy ' ),
1177+ 'post ' => (new Post ())->withShortName ('dummy ' ),
1178+ ])),
1179+ ]));
1180+
1181+ $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
1182+ $ propertyNameCollectionFactoryProphecy ->create ('dummy ' , Argument::type ('array ' ))->willReturn (new PropertyNameCollection ([]));
1183+
1184+ $ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
1185+ $ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
1186+
1187+ $ urlGenerator = $ this ->prophesize (UrlGeneratorInterface::class);
1188+ $ urlGenerator ->generate ('api_entrypoint ' )->willReturn ('/ ' );
1189+ $ urlGenerator ->generate ('api_doc ' , ['_format ' => 'jsonld ' ])->willReturn ('/doc ' );
1190+ $ urlGenerator ->generate ('api_doc ' , ['_format ' => 'jsonld ' ], 0 )->willReturn ('/doc ' );
1191+
1192+ $ documentationNormalizer = new DocumentationNormalizer (
1193+ $ resourceMetadataFactoryProphecy ->reveal (),
1194+ $ propertyNameCollectionFactoryProphecy ->reveal (),
1195+ $ propertyMetadataFactoryProphecy ->reveal (),
1196+ $ resourceClassResolverProphecy ->reveal (),
1197+ $ urlGenerator ->reveal ()
1198+ );
1199+
1200+ $ documentation = new Documentation (new ResourceNameCollection (['dummy ' => 'dummy ' ]), 'Test Api ' , 'test ' , '1.0.0 ' );
1201+ $ normalized = $ documentationNormalizer ->normalize ($ documentation );
1202+
1203+ $ entrypointClass = array_filter ($ normalized ['hydra:supportedClass ' ], static fn ($ class ) => '#Entrypoint ' === $ class ['@id ' ]);
1204+ $ this ->assertNotEmpty ($ entrypointClass , 'Entrypoint class should exist ' );
1205+
1206+ $ entrypointClass = reset ($ entrypointClass );
1207+ $ dummyProperty = array_filter ($ entrypointClass ['hydra:supportedProperty ' ], static fn ($ prop ) => str_contains ($ prop ['hydra:property ' ]['@id ' ] ?? '' , 'Entrypoint/dummy ' ));
1208+ $ this ->assertNotEmpty ($ dummyProperty , 'Entrypoint property for dummy should exist ' );
1209+
1210+ $ dummyProperty = reset ($ dummyProperty );
1211+
1212+ $ this ->assertArrayHasKey ('hydra:manages ' , $ dummyProperty , 'The entrypoint property should have a manages block ' );
1213+
1214+ $ manages = $ dummyProperty ['hydra:manages ' ];
1215+ $ this ->assertIsArray ($ manages , 'The manages block should be an array ' );
1216+ $ this ->assertArrayHasKey ('hydra:property ' , $ manages , 'The manages block should have a property ' );
1217+ $ this ->assertArrayHasKey ('hydra:object ' , $ manages , 'The manages block should have an object ' );
1218+ $ this ->assertSame ('#dummy ' , $ manages ['hydra:object ' ], 'The object should be #dummy ' );
1219+ $ this ->assertSame ('hydra:member ' , $ manages ['hydra:property ' ], 'The property should be hydra:member ' );
1220+ }
11731221}
0 commit comments