@@ -669,4 +669,60 @@ public function testNormalizeInputOutputClass(): void
669
669
670
670
$ this ->assertEquals ($ expected , $ documentationNormalizer ->normalize ($ documentation ));
671
671
}
672
+
673
+ public function testHasHydraContext (): void
674
+ {
675
+ $ title = 'Test Api ' ;
676
+ $ desc = 'test ApiGerard ' ;
677
+ $ version = '0.0.0 ' ;
678
+ $ documentation = new Documentation (new ResourceNameCollection (['dummy ' => 'dummy ' ]), $ title , $ desc , $ version );
679
+
680
+ $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
681
+ $ propertyNameCollectionFactoryProphecy ->create ('dummy ' , Argument::type ('array ' ))->shouldBeCalled ()->willReturn (new PropertyNameCollection (['name ' ]));
682
+
683
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
684
+ $ resourceMetadataFactoryProphecy ->create ('dummy ' )->shouldBeCalled ()->willReturn (new ResourceMetadataCollection ('dummy ' , [
685
+ (new ApiResource ())->withShortName ('dummy ' )->withDescription ('dummy ' )->withTypes (['#dummy ' ])->withOperations (new Operations ([
686
+ 'get ' => (new Get ())->withTypes (['#dummy ' ])->withShortName ('dummy ' )->withInput (['class ' => 'inputClass ' ])->withOutput (['class ' => 'outputClass ' ]),
687
+ ])),
688
+ ]));
689
+
690
+ $ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
691
+ $ propertyMetadataFactoryProphecy ->create ('dummy ' , 'name ' , Argument::type ('array ' ))->shouldBeCalled ()->willReturn (
692
+ (new ApiProperty ())
693
+ ->withBuiltinTypes ([new Type (Type::BUILTIN_TYPE_STRING )])
694
+ ->withDescription ('b ' )
695
+ ->withReadable (true )
696
+ ->withWritable (true )
697
+ ->withJsonldContext ([
698
+ 'hydra:property ' => [
699
+ '@type ' => 'https://schema.org/Enumeration ' ,
700
+ ],
701
+ ])
702
+ );
703
+
704
+ $ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
705
+ $ resourceClassResolverProphecy ->isResourceClass (Argument::type ('string ' ))->willReturn (true );
706
+
707
+ $ urlGenerator = $ this ->prophesize (UrlGeneratorInterface::class);
708
+ $ urlGenerator ->generate ('api_entrypoint ' )->willReturn ('/ ' )->shouldBeCalledTimes (1 );
709
+ $ urlGenerator ->generate ('api_doc ' , ['_format ' => 'jsonld ' ])->willReturn ('/doc ' )->shouldBeCalledTimes (1 );
710
+ $ urlGenerator ->generate ('api_doc ' , ['_format ' => 'jsonld ' ], 0 )->willReturn ('/doc ' )->shouldBeCalledTimes (1 );
711
+
712
+ $ documentationNormalizer = new DocumentationNormalizer (
713
+ $ resourceMetadataFactoryProphecy ->reveal (),
714
+ $ propertyNameCollectionFactoryProphecy ->reveal (),
715
+ $ propertyMetadataFactoryProphecy ->reveal (),
716
+ $ resourceClassResolverProphecy ->reveal (),
717
+ $ urlGenerator ->reveal ()
718
+ );
719
+
720
+ $ this ->assertEquals ([
721
+ '@id ' => '#dummy/name ' ,
722
+ '@type ' => 'https://schema.org/Enumeration ' ,
723
+ 'rdfs:label ' => 'name ' ,
724
+ 'domain ' => '#dummy ' ,
725
+ 'range ' => 'xmls:string ' ,
726
+ ], $ documentationNormalizer ->normalize ($ documentation )['hydra:supportedClass ' ][0 ]['hydra:supportedProperty ' ][0 ]['hydra:property ' ]);
727
+ }
672
728
}
0 commit comments