@@ -1976,4 +1976,103 @@ public function testNormalizeWithPropertySwaggerContext()
19761976
19771977 $ this ->assertEquals ($ expected , $ normalizer ->normalize ($ documentation , DocumentationNormalizer::FORMAT , ['base_url ' => '/app_dev.php/ ' ]));
19781978 }
1979+
1980+ public function testNormalizeWithPaginationClientEnabled ()
1981+ {
1982+ $ documentation = new Documentation (new ResourceNameCollection ([Dummy::class]), 'Test API ' , 'This is a test API. ' , '1.2.3 ' , ['jsonld ' => ['application/ld+json ' ]]);
1983+
1984+ $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
1985+ $ propertyNameCollectionFactoryProphecy ->create (Dummy::class, [])->shouldBeCalled ()->willReturn (new PropertyNameCollection (['id ' , 'name ' ]));
1986+
1987+ $ dummyMetadata = new ResourceMetadata ('Dummy ' , 'This is a dummy. ' , 'http://schema.example.com/Dummy ' , [], ['get ' => ['method ' => 'GET ' , 'pagination_client_enabled ' => true ]]);
1988+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
1989+ $ resourceMetadataFactoryProphecy ->create (Dummy::class)->shouldBeCalled ()->willReturn ($ dummyMetadata );
1990+
1991+ $ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
1992+ $ propertyMetadataFactoryProphecy ->create (Dummy::class, 'id ' )->shouldBeCalled ()->willReturn (new PropertyMetadata (new Type (Type::BUILTIN_TYPE_INT ), 'This is an id. ' , true , false ));
1993+ $ 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 ' ]]));
1994+ $ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
1995+ $ resourceClassResolverProphecy ->isResourceClass (Dummy::class)->willReturn (true );
1996+
1997+ $ operationMethodResolverProphecy = $ this ->prophesize (OperationMethodResolverInterface::class);
1998+ $ operationMethodResolverProphecy ->getCollectionOperationMethod (Dummy::class, 'get ' )->shouldBeCalled ()->willReturn ('GET ' );
1999+
2000+ $ operationPathResolver = new CustomOperationPathResolver (new OperationPathResolver (new UnderscorePathSegmentNameGenerator ()));
2001+
2002+ $ normalizer = new DocumentationNormalizer (
2003+ $ resourceMetadataFactoryProphecy ->reveal (),
2004+ $ propertyNameCollectionFactoryProphecy ->reveal (),
2005+ $ propertyMetadataFactoryProphecy ->reveal (),
2006+ $ resourceClassResolverProphecy ->reveal (),
2007+ $ operationMethodResolverProphecy ->reveal (),
2008+ $ operationPathResolver
2009+ );
2010+
2011+ $ expected = [
2012+ 'swagger ' => '2.0 ' ,
2013+ 'basePath ' => '/app_dev.php/ ' ,
2014+ 'info ' => [
2015+ 'title ' => 'Test API ' ,
2016+ 'description ' => 'This is a test API. ' ,
2017+ 'version ' => '1.2.3 ' ,
2018+ ],
2019+ 'paths ' => new \ArrayObject ([
2020+ '/dummies ' => [
2021+ 'get ' => new \ArrayObject ([
2022+ 'tags ' => ['Dummy ' ],
2023+ 'operationId ' => 'getDummyCollection ' ,
2024+ 'produces ' => ['application/ld+json ' ],
2025+ 'summary ' => 'Retrieves the collection of Dummy resources. ' ,
2026+ 'parameters ' => [
2027+ [
2028+ 'name ' => 'page ' ,
2029+ 'in ' => 'query ' ,
2030+ 'required ' => false ,
2031+ 'type ' => 'integer ' ,
2032+ 'description ' => 'The collection page number ' ,
2033+ ],
2034+ [
2035+ 'name ' => 'pagination ' ,
2036+ 'in ' => 'query ' ,
2037+ 'required ' => false ,
2038+ 'type ' => 'boolean ' ,
2039+ 'description ' => 'Enable or disable pagination ' ,
2040+ ],
2041+ ],
2042+ 'responses ' => [
2043+ 200 => [
2044+ 'description ' => 'Dummy collection response ' ,
2045+ 'schema ' => [
2046+ 'type ' => 'array ' ,
2047+ 'items ' => ['$ref ' => '#/definitions/Dummy ' ],
2048+ ],
2049+ ],
2050+ ],
2051+ ]),
2052+ ],
2053+ ]),
2054+ 'definitions ' => new \ArrayObject ([
2055+ 'Dummy ' => new \ArrayObject ([
2056+ 'type ' => 'object ' ,
2057+ 'description ' => 'This is a dummy. ' ,
2058+ 'externalDocs ' => ['url ' => 'http://schema.example.com/Dummy ' ],
2059+ 'properties ' => [
2060+ 'id ' => new \ArrayObject ([
2061+ 'type ' => 'integer ' ,
2062+ 'description ' => 'This is an id. ' ,
2063+ 'readOnly ' => true ,
2064+ ]),
2065+ 'name ' => new \ArrayObject ([
2066+ 'type ' => 'string ' ,
2067+ 'description ' => 'This is a name. ' ,
2068+ 'enum ' => ['one ' , 'two ' ],
2069+ 'example ' => 'one ' ,
2070+ ]),
2071+ ],
2072+ ]),
2073+ ]),
2074+ ];
2075+
2076+ $ this ->assertEquals ($ expected , $ normalizer ->normalize ($ documentation , DocumentationNormalizer::FORMAT , ['base_url ' => '/app_dev.php/ ' ]));
2077+ }
19792078}
0 commit comments