@@ -2000,4 +2000,103 @@ public function testNormalizeWithPropertySwaggerContext()
2000
2000
2001
2001
$ this ->assertEquals ($ expected , $ normalizer ->normalize ($ documentation , DocumentationNormalizer::FORMAT , ['base_url ' => '/app_dev.php/ ' ]));
2002
2002
}
2003
+
2004
+ public function testNormalizeWithPaginationClientEnabled ()
2005
+ {
2006
+ $ documentation = new Documentation (new ResourceNameCollection ([Dummy::class]), 'Test API ' , 'This is a test API. ' , '1.2.3 ' , ['jsonld ' => ['application/ld+json ' ]]);
2007
+
2008
+ $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
2009
+ $ propertyNameCollectionFactoryProphecy ->create (Dummy::class, [])->shouldBeCalled ()->willReturn (new PropertyNameCollection (['id ' , 'name ' ]));
2010
+
2011
+ $ dummyMetadata = new ResourceMetadata ('Dummy ' , 'This is a dummy. ' , 'http://schema.example.com/Dummy ' , [], ['get ' => ['method ' => 'GET ' , 'pagination_client_enabled ' => true ]]);
2012
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
2013
+ $ resourceMetadataFactoryProphecy ->create (Dummy::class)->shouldBeCalled ()->willReturn ($ dummyMetadata );
2014
+
2015
+ $ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
2016
+ $ propertyMetadataFactoryProphecy ->create (Dummy::class, 'id ' )->shouldBeCalled ()->willReturn (new PropertyMetadata (new Type (Type::BUILTIN_TYPE_INT ), 'This is an id. ' , true , false ));
2017
+ $ propertyMetadataFactoryProphecy ->create (Dummy::class, 'name ' )->shouldBeCalled ()->willReturn (new PropertyMetadata (new Type (Type::BUILTIN_TYPE_STRING ), 'This is a name. ' , true , true , true , true , false , false , null , null , ['swagger_context ' => ['type ' => 'string ' , 'enum ' => ['one ' , 'two ' ], 'example ' => 'one ' ]]));
2018
+ $ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
2019
+ $ resourceClassResolverProphecy ->isResourceClass (Dummy::class)->willReturn (true );
2020
+
2021
+ $ operationMethodResolverProphecy = $ this ->prophesize (OperationMethodResolverInterface::class);
2022
+ $ operationMethodResolverProphecy ->getCollectionOperationMethod (Dummy::class, 'get ' )->shouldBeCalled ()->willReturn ('GET ' );
2023
+
2024
+ $ operationPathResolver = new CustomOperationPathResolver (new OperationPathResolver (new UnderscorePathSegmentNameGenerator ()));
2025
+
2026
+ $ normalizer = new DocumentationNormalizer (
2027
+ $ resourceMetadataFactoryProphecy ->reveal (),
2028
+ $ propertyNameCollectionFactoryProphecy ->reveal (),
2029
+ $ propertyMetadataFactoryProphecy ->reveal (),
2030
+ $ resourceClassResolverProphecy ->reveal (),
2031
+ $ operationMethodResolverProphecy ->reveal (),
2032
+ $ operationPathResolver
2033
+ );
2034
+
2035
+ $ expected = [
2036
+ 'swagger ' => '2.0 ' ,
2037
+ 'basePath ' => '/app_dev.php/ ' ,
2038
+ 'info ' => [
2039
+ 'title ' => 'Test API ' ,
2040
+ 'description ' => 'This is a test API. ' ,
2041
+ 'version ' => '1.2.3 ' ,
2042
+ ],
2043
+ 'paths ' => new \ArrayObject ([
2044
+ '/dummies ' => [
2045
+ 'get ' => new \ArrayObject ([
2046
+ 'tags ' => ['Dummy ' ],
2047
+ 'operationId ' => 'getDummyCollection ' ,
2048
+ 'produces ' => ['application/ld+json ' ],
2049
+ 'summary ' => 'Retrieves the collection of Dummy resources. ' ,
2050
+ 'parameters ' => [
2051
+ [
2052
+ 'name ' => 'page ' ,
2053
+ 'in ' => 'query ' ,
2054
+ 'required ' => false ,
2055
+ 'type ' => 'integer ' ,
2056
+ 'description ' => 'The collection page number ' ,
2057
+ ],
2058
+ [
2059
+ 'name ' => 'pagination ' ,
2060
+ 'in ' => 'query ' ,
2061
+ 'required ' => false ,
2062
+ 'type ' => 'boolean ' ,
2063
+ 'description ' => 'Enable or disable pagination ' ,
2064
+ ],
2065
+ ],
2066
+ 'responses ' => [
2067
+ 200 => [
2068
+ 'description ' => 'Dummy collection response ' ,
2069
+ 'schema ' => [
2070
+ 'type ' => 'array ' ,
2071
+ 'items ' => ['$ref ' => '#/definitions/Dummy ' ],
2072
+ ],
2073
+ ],
2074
+ ],
2075
+ ]),
2076
+ ],
2077
+ ]),
2078
+ 'definitions ' => new \ArrayObject ([
2079
+ 'Dummy ' => new \ArrayObject ([
2080
+ 'type ' => 'object ' ,
2081
+ 'description ' => 'This is a dummy. ' ,
2082
+ 'externalDocs ' => ['url ' => 'http://schema.example.com/Dummy ' ],
2083
+ 'properties ' => [
2084
+ 'id ' => new \ArrayObject ([
2085
+ 'type ' => 'integer ' ,
2086
+ 'description ' => 'This is an id. ' ,
2087
+ 'readOnly ' => true ,
2088
+ ]),
2089
+ 'name ' => new \ArrayObject ([
2090
+ 'type ' => 'string ' ,
2091
+ 'description ' => 'This is a name. ' ,
2092
+ 'enum ' => ['one ' , 'two ' ],
2093
+ 'example ' => 'one ' ,
2094
+ ]),
2095
+ ],
2096
+ ]),
2097
+ ]),
2098
+ ];
2099
+
2100
+ $ this ->assertEquals ($ expected , $ normalizer ->normalize ($ documentation , DocumentationNormalizer::FORMAT , ['base_url ' => '/app_dev.php/ ' ]));
2101
+ }
2003
2102
}
0 commit comments