From 7114ebbd37073d60c44d2ef04cadf5978e4054b0 Mon Sep 17 00:00:00 2001 From: meyerbaptiste Date: Wed, 21 Jun 2017 14:32:50 +0200 Subject: [PATCH] Fix path for custom operation with Swagger UI --- src/Api/OperationTypeDeprecationHelper.php | 2 +- .../Symfony/Bundle/Action/SwaggerUiAction.php | 2 +- .../Bundle/Resources/config/swagger.xml | 2 +- src/Bridge/Symfony/Routing/ApiLoader.php | 29 ++---- .../Symfony/Routing/RouteNameGenerator.php | 61 ++++++++++++ .../Routing/RouterOperationPathResolver.php | 31 +++++-- .../CustomOperationPathResolver.php | 12 ++- .../DashOperationPathResolver.php | 6 +- .../OperationPathResolverInterface.php | 3 +- .../UnderscoreOperationPathResolver.php | 6 +- .../Serializer/DocumentationNormalizer.php | 24 +++-- .../Bundle/Action/SwaggerUiActionTest.php | 5 +- .../Routing/RouteNameGeneratorTest.php | 47 ++++++++++ .../RouterOperationPathResolverTest.php | 93 +++++++++++++++++++ .../CustomOperationPathResolverTest.php | 53 +++++++++++ .../DashOperationPathResolverTest.php | 23 ++++- .../UnderscoreOperationPathResolverTest.php | 23 ++++- .../DocumentationNormalizerTest.php | 87 +++++++---------- 18 files changed, 404 insertions(+), 105 deletions(-) create mode 100644 src/Bridge/Symfony/Routing/RouteNameGenerator.php create mode 100644 tests/Bridge/Symfony/Routing/RouteNameGeneratorTest.php create mode 100644 tests/Bridge/Symfony/Routing/RouterOperationPathResolverTest.php create mode 100644 tests/PathResolver/CustomOperationPathResolverTest.php diff --git a/src/Api/OperationTypeDeprecationHelper.php b/src/Api/OperationTypeDeprecationHelper.php index 0fad8642d7..47d6325270 100644 --- a/src/Api/OperationTypeDeprecationHelper.php +++ b/src/Api/OperationTypeDeprecationHelper.php @@ -22,7 +22,7 @@ * Because we introduced a third type in API Platform 2.1, we're using a string with OperationType constants: * - OperationType::ITEM * - OperationType::COLLECTION - * - OperationType::SUBCOLLECTION + * - OperationType::SUBRESOURCE * * @internal */ diff --git a/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php b/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php index f7c842c549..a4f9ca17fc 100644 --- a/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php +++ b/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php @@ -92,7 +92,7 @@ private function getContext(Request $request, Documentation $documentation): arr $swaggerData = [ 'url' => $this->urlGenerator->generate('api_doc', ['format' => 'json']), - 'spec' => $this->normalizer->normalize($documentation, 'json'), + 'spec' => $this->normalizer->normalize($documentation, 'json', ['base_url' => $request->getBaseUrl()]), ]; $swaggerData['oauth'] = [ diff --git a/src/Bridge/Symfony/Bundle/Resources/config/swagger.xml b/src/Bridge/Symfony/Bundle/Resources/config/swagger.xml index 26c1a25ef8..a8e188f207 100644 --- a/src/Bridge/Symfony/Bundle/Resources/config/swagger.xml +++ b/src/Bridge/Symfony/Bundle/Resources/config/swagger.xml @@ -13,7 +13,7 @@ - + null %api_platform.oauth.enabled% diff --git a/src/Bridge/Symfony/Routing/ApiLoader.php b/src/Bridge/Symfony/Routing/ApiLoader.php index 5ecd4373ee..b41c68abe3 100644 --- a/src/Bridge/Symfony/Routing/ApiLoader.php +++ b/src/Bridge/Symfony/Routing/ApiLoader.php @@ -38,6 +38,9 @@ */ final class ApiLoader extends Loader { + /** + * @deprecated since version 2.1, to be removed in 3.0. Use {@see RouteNameGenerator::ROUTE_NAME_PREFIX} instead. + */ const ROUTE_NAME_PREFIX = 'api_'; const DEFAULT_ACTION_PATTERN = 'api_platform.action.'; const SUBRESOURCE_SUFFIX = '_get_subresource'; @@ -166,13 +169,13 @@ private function computeSubresourceOperations(RouteCollection $routeCollection, $resourceRouteName = $this->routeNameResolver($rootShortname); $operation['identifiers'] = [['id', $rootResourceClass]]; - $operation['route_name'] = sprintf('%s%s_%s%s', self::ROUTE_NAME_PREFIX, $resourceRouteName, $propertyName, self::SUBRESOURCE_SUFFIX); - $operation['path'] = $this->operationPathResolver->resolveOperationPath($rootShortname, $operation, OperationType::SUBRESOURCE); + $operation['route_name'] = sprintf('%s%s_%s%s', RouteNameGenerator::ROUTE_NAME_PREFIX, $resourceRouteName, $propertyName, self::SUBRESOURCE_SUFFIX); + $operation['path'] = $this->operationPathResolver->resolveOperationPath($rootShortname, $operation, OperationType::SUBRESOURCE, $operation['route_name']); } else { $operation['identifiers'] = $parentOperation['identifiers']; $operation['identifiers'][] = [$parentOperation['property'], $resourceClass]; $operation['route_name'] = str_replace(self::SUBRESOURCE_SUFFIX, "_$propertyName".self::SUBRESOURCE_SUFFIX, $parentOperation['route_name']); - $operation['path'] = $this->operationPathResolver->resolveOperationPath($parentOperation['path'], $operation, OperationType::SUBRESOURCE); + $operation['path'] = $this->operationPathResolver->resolveOperationPath($parentOperation['path'], $operation, OperationType::SUBRESOURCE, $operation['route_name']); } $route = new Route( @@ -245,28 +248,16 @@ private function addRoute(RouteCollection $routeCollection, string $resourceClas throw new RuntimeException('Either a "route_name" or a "method" operation attribute must exist.'); } - $controller = $operation['controller'] ?? null; - $actionName = sprintf('%s_%s', strtolower($operation['method']), $operationType); - - if (null === $controller) { - $controller = self::DEFAULT_ACTION_PATTERN.$actionName; + if (null === $controller = $operation['controller'] ?? null) { + $controller = sprintf('%s%s_%s', self::DEFAULT_ACTION_PATTERN, strtolower($operation['method']), $operationType); if (!$this->container->has($controller)) { throw new RuntimeException(sprintf('There is no builtin action for the %s %s operation. You need to define the controller yourself.', $operationType, $operation['method'])); } } - if ($operationName !== strtolower($operation['method'])) { - $actionName = sprintf('%s_%s', $operationName, $operationType); - } - - $path = $this->operationPathResolver->resolveOperationPath($resourceShortName, $operation, $operationType); - - $resourceRouteName = $this->routeNameResolver($resourceShortName); - $routeName = sprintf('%s%s_%s', self::ROUTE_NAME_PREFIX, $resourceRouteName, $actionName); - $route = new Route( - $path, + $this->operationPathResolver->resolveOperationPath($resourceShortName, $operation, $operationType, $operationName), [ '_controller' => $controller, '_format' => null, @@ -280,6 +271,6 @@ private function addRoute(RouteCollection $routeCollection, string $resourceClas [$operation['method']] ); - $routeCollection->add($routeName, $route); + $routeCollection->add(RouteNameGenerator::generate($operationName, $resourceShortName, $operationType), $route); } } diff --git a/src/Bridge/Symfony/Routing/RouteNameGenerator.php b/src/Bridge/Symfony/Routing/RouteNameGenerator.php new file mode 100644 index 0000000000..220ea35933 --- /dev/null +++ b/src/Bridge/Symfony/Routing/RouteNameGenerator.php @@ -0,0 +1,61 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Core\Bridge\Symfony\Routing; + +use ApiPlatform\Core\Api\OperationType; +use ApiPlatform\Core\Api\OperationTypeDeprecationHelper; +use ApiPlatform\Core\Exception\InvalidArgumentException; +use Doctrine\Common\Util\Inflector; + +/** + * Generates the Symfony route name associated with an operation name and a resource short name. + * + * @internal + * + * @author Baptiste Meyer + */ +class RouteNameGenerator +{ + const ROUTE_NAME_PREFIX = 'api_'; + + private function __construct() + { + } + + /** + * Generates a Symfony route name. + * + * @param string $operationName + * @param string $resourceShortName + * @param string|bool $operationType + * + * @throws InvalidArgumentException + * + * @return string + */ + public static function generate(string $operationName, string $resourceShortName, $operationType): string + { + if (OperationType::SUBRESOURCE === $operationType = OperationTypeDeprecationHelper::getOperationType($operationType)) { + throw new InvalidArgumentException(sprintf('%s::SUBRESOURCE is not supported as operation type by %s().', OperationType::class, __METHOD__)); + } + + return sprintf( + '%s%s_%s_%s', + static::ROUTE_NAME_PREFIX, + Inflector::pluralize(Inflector::tableize($resourceShortName)), + $operationName, + $operationType + ); + } +} diff --git a/src/Bridge/Symfony/Routing/RouterOperationPathResolver.php b/src/Bridge/Symfony/Routing/RouterOperationPathResolver.php index 908eb658a0..a87fec7c88 100644 --- a/src/Bridge/Symfony/Routing/RouterOperationPathResolver.php +++ b/src/Bridge/Symfony/Routing/RouterOperationPathResolver.php @@ -13,6 +13,8 @@ namespace ApiPlatform\Core\Bridge\Symfony\Routing; +use ApiPlatform\Core\Api\OperationType; +use ApiPlatform\Core\Api\OperationTypeDeprecationHelper; use ApiPlatform\Core\Exception\InvalidArgumentException; use ApiPlatform\Core\PathResolver\OperationPathResolverInterface; use Symfony\Component\Routing\RouterInterface; @@ -38,15 +40,32 @@ public function __construct(RouterInterface $router, OperationPathResolverInterf * * @throws InvalidArgumentException */ - public function resolveOperationPath(string $resourceShortName, array $operation, $operationType): string + public function resolveOperationPath(string $resourceShortName, array $operation, $operationType/*, string $operationName = null*/): string { - if (!isset($operation['route_name'])) { - return $this->deferred->resolveOperationPath($resourceShortName, $operation, $operationType); + if (func_num_args() >= 4) { + $operationName = func_get_arg(3); + } else { + @trigger_error(sprintf('Method %s() will have a 4th `string $operationName` argument in version 3.0. Not defining it is deprecated since 2.1.', __METHOD__), E_USER_DEPRECATED); + + $operationName = null; + } + + if (OperationType::SUBRESOURCE === $operationType = OperationTypeDeprecationHelper::getOperationType($operationType)) { + return $this->deferred->resolveOperationPath($resourceShortName, $operation, $operationType, $operationName); + } + + if (isset($operation['route_name'])) { + $routeName = $operation['route_name']; + } elseif (null !== $operationName) { + $routeName = RouteNameGenerator::generate($operationName, $resourceShortName, $operationType); + } else { + return $this->deferred->resolveOperationPath($resourceShortName, $operation, $operationType, $operationName); } - $route = $this->router->getRouteCollection()->get($operation['route_name']); - if (null === $route) { - throw new InvalidArgumentException(sprintf('The route "%s" of the resource "%s" was not found.', $operation['route_name'], $resourceShortName)); + if (!$route = $this->router->getRouteCollection()->get($routeName)) { + throw new InvalidArgumentException( + sprintf('The route "%s" of the resource "%s" was not found.', $routeName, $resourceShortName) + ); } return $route->getPath(); diff --git a/src/PathResolver/CustomOperationPathResolver.php b/src/PathResolver/CustomOperationPathResolver.php index 19fb26c817..07a7eadce2 100644 --- a/src/PathResolver/CustomOperationPathResolver.php +++ b/src/PathResolver/CustomOperationPathResolver.php @@ -32,12 +32,20 @@ public function __construct(OperationPathResolverInterface $deferred) /** * {@inheritdoc} */ - public function resolveOperationPath(string $resourceShortName, array $operation, $operationType): string + public function resolveOperationPath(string $resourceShortName, array $operation, $operationType/*, string $operationName = null*/): string { + if (func_num_args() >= 4) { + $operationName = func_get_arg(3); + } else { + @trigger_error(sprintf('Method %s() will have a 4th `string $operationName` argument in version 3.0. Not defining it is deprecated since 2.1.', __METHOD__), E_USER_DEPRECATED); + + $operationName = null; + } + if (isset($operation['path'])) { return $operation['path']; } - return $this->deferred->resolveOperationPath($resourceShortName, $operation, OperationTypeDeprecationHelper::getOperationType($operationType)); + return $this->deferred->resolveOperationPath($resourceShortName, $operation, OperationTypeDeprecationHelper::getOperationType($operationType), $operationName); } } diff --git a/src/PathResolver/DashOperationPathResolver.php b/src/PathResolver/DashOperationPathResolver.php index 48bd3e026e..28df5dd157 100644 --- a/src/PathResolver/DashOperationPathResolver.php +++ b/src/PathResolver/DashOperationPathResolver.php @@ -27,8 +27,12 @@ final class DashOperationPathResolver implements OperationPathResolverInterface /** * {@inheritdoc} */ - public function resolveOperationPath(string $resourceShortName, array $operation, $operationType): string + public function resolveOperationPath(string $resourceShortName, array $operation, $operationType/*, string $operationName = null*/): string { + if (func_num_args() < 4) { + @trigger_error(sprintf('Method %s() will have a 4th `string $operationName` argument in version 3.0. Not defining it is deprecated since 2.1.', __METHOD__), E_USER_DEPRECATED); + } + $operationType = OperationTypeDeprecationHelper::getOperationType($operationType); if ($operationType === OperationType::SUBRESOURCE && 1 < count($operation['identifiers'])) { diff --git a/src/PathResolver/OperationPathResolverInterface.php b/src/PathResolver/OperationPathResolverInterface.php index 4ea1ff8c4b..b6970a2369 100644 --- a/src/PathResolver/OperationPathResolverInterface.php +++ b/src/PathResolver/OperationPathResolverInterface.php @@ -27,8 +27,9 @@ interface OperationPathResolverInterface * @param array $operation The operation metadata * @param string|bool $operationType One of the constants defined in ApiPlatform\Core\Api\OperationType * If the property is a boolean, true represents OperationType::COLLECTION, false is for OperationType::ITEM + * @param string $operationName The operation name * * @return string */ - public function resolveOperationPath(string $resourceShortName, array $operation, $operationType): string; + public function resolveOperationPath(string $resourceShortName, array $operation, $operationType/*, string $operationName = null*/): string; } diff --git a/src/PathResolver/UnderscoreOperationPathResolver.php b/src/PathResolver/UnderscoreOperationPathResolver.php index befbca7185..cf4364d338 100644 --- a/src/PathResolver/UnderscoreOperationPathResolver.php +++ b/src/PathResolver/UnderscoreOperationPathResolver.php @@ -27,8 +27,12 @@ final class UnderscoreOperationPathResolver implements OperationPathResolverInte /** * {@inheritdoc} */ - public function resolveOperationPath(string $resourceShortName, array $operation, $operationType): string + public function resolveOperationPath(string $resourceShortName, array $operation, $operationType/*, string $operationName = null*/): string { + if (func_num_args() < 4) { + @trigger_error(sprintf('Method %s() will have a 4th `string $operationName` argument in version 3.0. Not defining it is deprecated since 2.1.', __METHOD__), E_USER_DEPRECATED); + } + $operationType = OperationTypeDeprecationHelper::getOperationType($operationType); if ($operationType === OperationType::SUBRESOURCE && 1 < count($operation['identifiers'])) { diff --git a/src/Swagger/Serializer/DocumentationNormalizer.php b/src/Swagger/Serializer/DocumentationNormalizer.php index 54e2267807..94a87e5d2a 100644 --- a/src/Swagger/Serializer/DocumentationNormalizer.php +++ b/src/Swagger/Serializer/DocumentationNormalizer.php @@ -51,7 +51,6 @@ final class DocumentationNormalizer implements NormalizerInterface private $resourceClassResolver; private $operationMethodResolver; private $operationPathResolver; - private $urlGenerator; private $nameConverter; private $oauthEnabled; private $oauthType; @@ -63,8 +62,12 @@ final class DocumentationNormalizer implements NormalizerInterface /** * @param ContainerInterface|FilterCollection|null $filterLocator The new filter locator or the deprecated filter collection */ - public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFactory, PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, ResourceClassResolverInterface $resourceClassResolver, OperationMethodResolverInterface $operationMethodResolver, OperationPathResolverInterface $operationPathResolver, UrlGeneratorInterface $urlGenerator, $filterLocator = null, NameConverterInterface $nameConverter = null, $oauthEnabled = false, $oauthType = '', $oauthFlow = '', $oauthTokenUrl = '', $oauthAuthorizationUrl = '', $oauthScopes = []) + public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFactory, PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, ResourceClassResolverInterface $resourceClassResolver, OperationMethodResolverInterface $operationMethodResolver, OperationPathResolverInterface $operationPathResolver, UrlGeneratorInterface $urlGenerator = null, $filterLocator = null, NameConverterInterface $nameConverter = null, $oauthEnabled = false, $oauthType = '', $oauthFlow = '', $oauthTokenUrl = '', $oauthAuthorizationUrl = '', $oauthScopes = []) { + if ($urlGenerator) { + @trigger_error(sprintf('Passing an instance of %s to %s() is deprecated since version 2.1 and will be removed in 3.0.', UrlGeneratorInterface::class, __METHOD__), E_USER_DEPRECATED); + } + $this->setFilterLocator($filterLocator, true); $this->resourceMetadataFactory = $resourceMetadataFactory; @@ -73,7 +76,6 @@ public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFa $this->resourceClassResolver = $resourceClassResolver; $this->operationMethodResolver = $operationMethodResolver; $this->operationPathResolver = $operationPathResolver; - $this->urlGenerator = $urlGenerator; $this->nameConverter = $nameConverter; $this->oauthEnabled = $oauthEnabled; $this->oauthType = $oauthType; @@ -103,7 +105,7 @@ public function normalize($object, $format = null, array $context = []) $definitions->ksort(); $paths->ksort(); - return $this->computeDoc($object, $definitions, $paths); + return $this->computeDoc($object, $definitions, $paths, $context); } /** @@ -124,7 +126,7 @@ private function addPaths(\ArrayObject $paths, \ArrayObject $definitions, string } foreach ($operations as $operationName => $operation) { - $path = $this->getPath($resourceShortName, $operation, $operationType); + $path = $this->getPath($resourceShortName, $operationName, $operation, $operationType); $method = $operationType === OperationType::ITEM ? $this->operationMethodResolver->getItemOperationMethod($resourceClass, $operationName) : $this->operationMethodResolver->getCollectionOperationMethod($resourceClass, $operationName); $paths[$path][strtolower($method)] = $this->getPathOperation($operationName, $operation, $method, $operationType, $resourceClass, $resourceMetadata, $mimeTypes, $definitions); @@ -140,14 +142,15 @@ private function addPaths(\ArrayObject $paths, \ArrayObject $definitions, string * @see https://github.com/OAI/OpenAPI-Specification/issues/93 * * @param string $resourceShortName + * @param string $operationName * @param array $operation * @param string $operationType * * @return string */ - private function getPath(string $resourceShortName, array $operation, string $operationType): string + private function getPath(string $resourceShortName, string $operationName, array $operation, string $operationType): string { - $path = $this->operationPathResolver->resolveOperationPath($resourceShortName, $operation, $operationType); + $path = $this->operationPathResolver->resolveOperationPath($resourceShortName, $operation, $operationType, $operationName); if ('.{_format}' === substr($path, -10)) { $path = substr($path, 0, -10); } @@ -211,7 +214,7 @@ private function updateGetOperation(\ArrayObject $pathOperation, array $mimeType $pathOperation['produces'] ?? $pathOperation['produces'] = $mimeTypes; - if ($operationType === OperationType::COLLECTION || $operationType === OperationType::SUBRESOURCE) { + if ($operationType === OperationType::COLLECTION) { $pathOperation['summary'] ?? $pathOperation['summary'] = sprintf('Retrieves the collection of %s resources.', $resourceShortName); $pathOperation['responses'] ?? $pathOperation['responses'] = [ '200' => [ @@ -526,14 +529,15 @@ private function getType(string $type, bool $isCollection, string $className = n * @param Documentation $documentation * @param \ArrayObject $definitions * @param \ArrayObject $paths + * @param array $context * * @return array */ - private function computeDoc(Documentation $documentation, \ArrayObject $definitions, \ArrayObject $paths): array + private function computeDoc(Documentation $documentation, \ArrayObject $definitions, \ArrayObject $paths, array $context): array { $doc = [ 'swagger' => self::SWAGGER_VERSION, - 'basePath' => $this->urlGenerator->generate('api_entrypoint'), + 'basePath' => $context['base_url'] ?? '/', 'info' => [ 'title' => $documentation->getTitle(), 'version' => $documentation->getVersion(), diff --git a/tests/Bridge/Symfony/Bundle/Action/SwaggerUiActionTest.php b/tests/Bridge/Symfony/Bundle/Action/SwaggerUiActionTest.php index 536dbe319d..b405302ada 100644 --- a/tests/Bridge/Symfony/Bundle/Action/SwaggerUiActionTest.php +++ b/tests/Bridge/Symfony/Bundle/Action/SwaggerUiActionTest.php @@ -49,7 +49,7 @@ public function testInvoke(Request $request, ProphecyInterface $twigProphecy) $resourceMetadataFactoryProphecy->create('Foo')->willReturn(new ResourceMetadata('F'))->shouldBeCalled(); $normalizerProphecy = $this->prophesize(NormalizerInterface::class); - $normalizerProphecy->normalize(Argument::type(Documentation::class), 'json')->willReturn(self::SPEC)->shouldBeCalled(); + $normalizerProphecy->normalize(Argument::type(Documentation::class), 'json', Argument::type('array'))->willReturn(self::SPEC)->shouldBeCalled(); $urlGeneratorProphecy = $this->prophesize(UrlGenerator::class); $urlGeneratorProphecy->generate('api_doc', ['format' => 'json'])->willReturn('/url')->shouldBeCalled(); @@ -138,8 +138,9 @@ public function testDoNotRunCurrentRequest(Request $request) $resourceNameCollectionFactoryProphecy->create()->willReturn(new ResourceNameCollection(['Foo', 'Bar']))->shouldBeCalled(); $resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class); + $normalizerProphecy = $this->prophesize(NormalizerInterface::class); - $normalizerProphecy->normalize(Argument::type(Documentation::class), 'json')->willReturn(self::SPEC)->shouldBeCalled(); + $normalizerProphecy->normalize(Argument::type(Documentation::class), 'json', Argument::type('array'))->willReturn(self::SPEC)->shouldBeCalled(); $twigProphecy = $this->prophesize(\Twig_Environment::class); $twigProphecy->render('@ApiPlatform/SwaggerUi/index.html.twig', [ diff --git a/tests/Bridge/Symfony/Routing/RouteNameGeneratorTest.php b/tests/Bridge/Symfony/Routing/RouteNameGeneratorTest.php new file mode 100644 index 0000000000..2270c5a92e --- /dev/null +++ b/tests/Bridge/Symfony/Routing/RouteNameGeneratorTest.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Core\Tests\Bridge\Symfony\Routing; + +use ApiPlatform\Core\Api\OperationType; +use ApiPlatform\Core\Bridge\Symfony\Routing\RouteNameGenerator; + +/** + * @author Baptiste Meyer + */ +class RouteNameGeneratorTest extends \PHPUnit_Framework_TestCase +{ + public function testGenerate() + { + $this->assertEquals('api_foos_get_collection', RouteNameGenerator::generate('get', 'Foo', OperationType::COLLECTION)); + $this->assertEquals('api_bars_custom_operation_item', RouteNameGenerator::generate('custom_operation', 'Bar', OperationType::ITEM)); + } + + /** + * @group legacy + * @expectedDeprecation Using a boolean for the Operation Type is deprecrated since API Platform 2.1 and will not be possible anymore in API Platform 3 + */ + public function testLegacyGenerate() + { + $this->assertEquals('api_foos_get_collection', RouteNameGenerator::generate('get', 'Foo', true)); + } + + /** + * @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException + * @expectedExceptionMessage ApiPlatform\Core\Api\OperationType::SUBRESOURCE is not supported as operation type by ApiPlatform\Core\Bridge\Symfony\Routing\RouteNameGenerator::generate(). + */ + public function testGenerateWithSubresource() + { + RouteNameGenerator::generate('api_foos_bars_get_subresource', 'Bar', OperationType::SUBRESOURCE); + } +} diff --git a/tests/Bridge/Symfony/Routing/RouterOperationPathResolverTest.php b/tests/Bridge/Symfony/Routing/RouterOperationPathResolverTest.php new file mode 100644 index 0000000000..099ec022e1 --- /dev/null +++ b/tests/Bridge/Symfony/Routing/RouterOperationPathResolverTest.php @@ -0,0 +1,93 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Core\Tests\Bridge\Symfony\Routing; + +use ApiPlatform\Core\Api\OperationType; +use ApiPlatform\Core\Bridge\Symfony\Routing\RouteNameGenerator; +use ApiPlatform\Core\Bridge\Symfony\Routing\RouterOperationPathResolver; +use ApiPlatform\Core\PathResolver\OperationPathResolverInterface; +use Prophecy\Argument; +use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\Routing\RouterInterface; + +/** + * @author Baptiste Meyer + */ +class RouterOperationPathResolverTest extends \PHPUnit_Framework_TestCase +{ + public function testResolveOperationPath() + { + $routeCollection = new RouteCollection(); + $routeCollection->add('foos', new Route('/foos')); + + $routerProphecy = $this->prophesize(RouterInterface::class); + $routerProphecy->getRouteCollection()->willReturn($routeCollection)->shouldBeCalled(); + + $operationPathResolver = new RouterOperationPathResolver($routerProphecy->reveal(), $this->prophesize(OperationPathResolverInterface::class)->reveal()); + + $this->assertEquals('/foos', $operationPathResolver->resolveOperationPath('Foo', ['route_name' => 'foos'], OperationType::COLLECTION, 'get')); + } + + public function testResolveOperationPathWithSubresource() + { + $operationPathResolverProphecy = $this->prophesize(OperationPathResolverInterface::class); + $operationPathResolverProphecy->resolveOperationPath('Bar', Argument::type('array'), OperationType::SUBRESOURCE, 'api_foos_bars_get_subresource')->willReturn('/foos/{id}/bars.{_format}')->shouldBeCalled(); + + $operationPathResolver = new RouterOperationPathResolver($this->prophesize(RouterInterface::class)->reveal(), $operationPathResolverProphecy->reveal()); + + $this->assertEquals('/foos/{id}/bars.{_format}', $operationPathResolver->resolveOperationPath('Bar', [], OperationType::SUBRESOURCE, 'api_foos_bars_get_subresource')); + } + + public function testResolveOperationPathWithRouteNameGeneration() + { + $routeCollection = new RouteCollection(); + $routeCollection->add(RouteNameGenerator::generate('get', 'Foo', OperationType::COLLECTION), new Route('/foos')); + + $routerProphecy = $this->prophesize(RouterInterface::class); + $routerProphecy->getRouteCollection()->willReturn($routeCollection)->shouldBeCalled(); + + $operationPathResolver = new RouterOperationPathResolver($routerProphecy->reveal(), $this->prophesize(OperationPathResolverInterface::class)->reveal()); + + $this->assertEquals('/foos', $operationPathResolver->resolveOperationPath('Foo', [], OperationType::COLLECTION, 'get')); + } + + /** + * @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException + * @expectedExceptionMessage The route "api_foos_get_collection" of the resource "Foo" was not found. + */ + public function testResolveOperationPathWithRouteNotFound() + { + $routerProphecy = $this->prophesize(RouterInterface::class); + $routerProphecy->getRouteCollection()->willReturn(new RouteCollection())->shouldBeCalled(); + + $operationPathResolver = new RouterOperationPathResolver($routerProphecy->reveal(), $this->prophesize(OperationPathResolverInterface::class)->reveal()); + $operationPathResolver->resolveOperationPath('Foo', [], OperationType::COLLECTION, 'get'); + } + + /** + * @group legacy + * @expectedDeprecation Method ApiPlatform\Core\Bridge\Symfony\Routing\RouterOperationPathResolver::resolveOperationPath() will have a 4th `string $operationName` argument in version 3.0. Not defining it is deprecated since 2.1. + * @expectedDeprecation Using a boolean for the Operation Type is deprecrated since API Platform 2.1 and will not be possible anymore in API Platform 3 + */ + public function testLegacyResolveOperationPath() + { + $operationPathResolverProphecy = $this->prophesize(OperationPathResolverInterface::class); + $operationPathResolverProphecy->resolveOperationPath('Foo', [], OperationType::ITEM, null)->willReturn('/foos/{id}.{_format}')->shouldBeCalled(); + + $operationPathResolver = new RouterOperationPathResolver($this->prophesize(RouterInterface::class)->reveal(), $operationPathResolverProphecy->reveal()); + + $this->assertEquals('/foos/{id}.{_format}', $operationPathResolver->resolveOperationPath('Foo', [], false)); + } +} diff --git a/tests/PathResolver/CustomOperationPathResolverTest.php b/tests/PathResolver/CustomOperationPathResolverTest.php new file mode 100644 index 0000000000..12ee5e08f1 --- /dev/null +++ b/tests/PathResolver/CustomOperationPathResolverTest.php @@ -0,0 +1,53 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Core\Tests\PathResolver; + +use ApiPlatform\Core\Api\OperationType; +use ApiPlatform\Core\PathResolver\CustomOperationPathResolver; +use ApiPlatform\Core\PathResolver\OperationPathResolverInterface; + +/** + * @author Baptiste Meyer + */ +class CustomOperationPathResolverTest extends \PHPUnit_Framework_TestCase +{ + public function testResolveOperationPath() + { + $operationPathResolver = new CustomOperationPathResolver($this->prophesize(OperationPathResolverInterface::class)->reveal()); + + $this->assertEquals('/foos.{_format}', $operationPathResolver->resolveOperationPath('Foo', ['path' => '/foos.{_format}'], OperationType::COLLECTION, 'get')); + } + + public function testResolveOperationPathWithDeferred() + { + $operationPathResolverProphecy = $this->prophesize(OperationPathResolverInterface::class); + $operationPathResolverProphecy->resolveOperationPath('Foo', [], OperationType::ITEM, 'get')->willReturn('/foos/{id}.{_format}')->shouldBeCalled(); + + $operationPathResolver = new CustomOperationPathResolver($operationPathResolverProphecy->reveal()); + + $this->assertEquals('/foos/{id}.{_format}', $operationPathResolver->resolveOperationPath('Foo', [], OperationType::ITEM, 'get')); + } + + /** + * @group legacy + * @expectedDeprecation Method ApiPlatform\Core\PathResolver\CustomOperationPathResolver::resolveOperationPath() will have a 4th `string $operationName` argument in version 3.0. Not defining it is deprecated since 2.1. + * @expectedDeprecation Using a boolean for the Operation Type is deprecrated since API Platform 2.1 and will not be possible anymore in API Platform 3 + */ + public function testLegacyResolveOperationPath() + { + $operationPathResolver = new CustomOperationPathResolver($this->prophesize(OperationPathResolverInterface::class)->reveal()); + + $this->assertEquals('/foos.{_format}', $operationPathResolver->resolveOperationPath('Foo', ['path' => '/foos.{_format}'], true)); + } +} diff --git a/tests/PathResolver/DashOperationPathResolverTest.php b/tests/PathResolver/DashOperationPathResolverTest.php index 31083824f1..7fd7effb07 100644 --- a/tests/PathResolver/DashOperationPathResolverTest.php +++ b/tests/PathResolver/DashOperationPathResolverTest.php @@ -16,32 +16,47 @@ use ApiPlatform\Core\Api\OperationType; use ApiPlatform\Core\PathResolver\DashOperationPathResolver; +/** + * @author Guilhem N. + */ class DashOperationPathResolverTest extends \PHPUnit_Framework_TestCase { public function testResolveCollectionOperationPath() { $dashOperationPathResolver = new DashOperationPathResolver(); - $this->assertSame('/short-names.{_format}', $dashOperationPathResolver->resolveOperationPath('ShortName', [], OperationType::COLLECTION)); + $this->assertSame('/short-names.{_format}', $dashOperationPathResolver->resolveOperationPath('ShortName', [], OperationType::COLLECTION, 'get')); } public function testResolveItemOperationPath() { $dashOperationPathResolver = new DashOperationPathResolver(); - $this->assertSame('/short-names/{id}.{_format}', $dashOperationPathResolver->resolveOperationPath('ShortName', [], OperationType::ITEM)); + $this->assertSame('/short-names/{id}.{_format}', $dashOperationPathResolver->resolveOperationPath('ShortName', [], OperationType::ITEM, 'get')); } public function testResolveSubresourceOperationPath() { $dashOperationPathResolver = new DashOperationPathResolver(); - $path = $dashOperationPathResolver->resolveOperationPath('ShortName', ['property' => 'relatedFoo', 'identifiers' => [['id', 'class']], 'collection' => true], OperationType::SUBRESOURCE); + $path = $dashOperationPathResolver->resolveOperationPath('ShortName', ['property' => 'relatedFoo', 'identifiers' => [['id', 'class']], 'collection' => true], OperationType::SUBRESOURCE, 'get'); $this->assertSame('/short-names/{id}/related-foos.{_format}', $path); - $next = $dashOperationPathResolver->resolveOperationPath($path, ['property' => 'bar', 'identifiers' => [['id', 'class'], ['relatedId', 'class']], 'collection' => false], OperationType::SUBRESOURCE); + $next = $dashOperationPathResolver->resolveOperationPath($path, ['property' => 'bar', 'identifiers' => [['id', 'class'], ['relatedId', 'class']], 'collection' => false], OperationType::SUBRESOURCE, 'get'); $this->assertSame('/short-names/{id}/related-foos/{relatedId}/bar.{_format}', $next); } + + /** + * @group legacy + * @expectedDeprecation Method ApiPlatform\Core\PathResolver\DashOperationPathResolver::resolveOperationPath() will have a 4th `string $operationName` argument in version 3.0. Not defining it is deprecated since 2.1. + * @expectedDeprecation Using a boolean for the Operation Type is deprecrated since API Platform 2.1 and will not be possible anymore in API Platform 3 + */ + public function testLegacyResolveOperationPath() + { + $dashOperationPathResolver = new DashOperationPathResolver(); + + $this->assertSame('/short-names.{_format}', $dashOperationPathResolver->resolveOperationPath('ShortName', [], true)); + } } diff --git a/tests/PathResolver/UnderscoreOperationPathResolverTest.php b/tests/PathResolver/UnderscoreOperationPathResolverTest.php index 93ff32c2e6..12475b70af 100644 --- a/tests/PathResolver/UnderscoreOperationPathResolverTest.php +++ b/tests/PathResolver/UnderscoreOperationPathResolverTest.php @@ -16,32 +16,47 @@ use ApiPlatform\Core\Api\OperationType; use ApiPlatform\Core\PathResolver\UnderscoreOperationPathResolver; +/** + * @author Guilhem N. + */ class UnderscoreOperationPathResolverTest extends \PHPUnit_Framework_TestCase { public function testResolveCollectionOperationPath() { $underscoreOperationPathResolver = new UnderscoreOperationPathResolver(); - $this->assertSame('/short_names.{_format}', $underscoreOperationPathResolver->resolveOperationPath('ShortName', [], OperationType::COLLECTION)); + $this->assertSame('/short_names.{_format}', $underscoreOperationPathResolver->resolveOperationPath('ShortName', [], OperationType::COLLECTION, 'get')); } public function testResolveItemOperationPath() { $underscoreOperationPathResolver = new UnderscoreOperationPathResolver(); - $this->assertSame('/short_names/{id}.{_format}', $underscoreOperationPathResolver->resolveOperationPath('ShortName', [], OperationType::ITEM)); + $this->assertSame('/short_names/{id}.{_format}', $underscoreOperationPathResolver->resolveOperationPath('ShortName', [], OperationType::ITEM, 'get')); } public function testResolveSubresourceOperationPath() { $dashOperationPathResolver = new UnderscoreOperationPathResolver(); - $path = $dashOperationPathResolver->resolveOperationPath('ShortName', ['property' => 'relatedFoo', 'identifiers' => [['id', 'class']], 'collection' => true], OperationType::SUBRESOURCE); + $path = $dashOperationPathResolver->resolveOperationPath('ShortName', ['property' => 'relatedFoo', 'identifiers' => [['id', 'class']], 'collection' => true], OperationType::SUBRESOURCE, 'get'); $this->assertSame('/short_names/{id}/related_foos.{_format}', $path); - $next = $dashOperationPathResolver->resolveOperationPath($path, ['property' => 'bar', 'identifiers' => [['id', 'class'], ['relatedId', 'class']], 'collection' => false], OperationType::SUBRESOURCE); + $next = $dashOperationPathResolver->resolveOperationPath($path, ['property' => 'bar', 'identifiers' => [['id', 'class'], ['relatedId', 'class']], 'collection' => false], OperationType::SUBRESOURCE, 'get'); $this->assertSame('/short_names/{id}/related_foos/{relatedId}/bar.{_format}', $next); } + + /** + * @group legacy + * @expectedDeprecation Method ApiPlatform\Core\PathResolver\UnderscoreOperationPathResolver::resolveOperationPath() will have a 4th `string $operationName` argument in version 3.0. Not defining it is deprecated since 2.1. + * @expectedDeprecation Using a boolean for the Operation Type is deprecrated since API Platform 2.1 and will not be possible anymore in API Platform 3 + */ + public function testLegacyResolveOperationPath() + { + $underscoreOperationPathResolver = new UnderscoreOperationPathResolver(); + + $this->assertSame('/short_names.{_format}', $underscoreOperationPathResolver->resolveOperationPath('ShortName', [], true)); + } } diff --git a/tests/Swagger/Serializer/DocumentationNormalizerTest.php b/tests/Swagger/Serializer/DocumentationNormalizerTest.php index c1a81f647b..5394eff8ba 100644 --- a/tests/Swagger/Serializer/DocumentationNormalizerTest.php +++ b/tests/Swagger/Serializer/DocumentationNormalizerTest.php @@ -42,6 +42,25 @@ */ class DocumentationNormalizerTest extends \PHPUnit_Framework_TestCase { + /** + * @group legacy + * @expectedDeprecation Passing an instance of ApiPlatform\Core\Api\UrlGeneratorInterface to ApiPlatform\Core\Swagger\Serializer\DocumentationNormalizer::__construct() is deprecated since version 2.1 and will be removed in 3.0. + */ + public function testLegacyConstruct() + { + $normalizer = new DocumentationNormalizer( + $this->prophesize(ResourceMetadataFactoryInterface::class)->reveal(), + $this->prophesize(PropertyNameCollectionFactoryInterface::class)->reveal(), + $this->prophesize(PropertyMetadataFactoryInterface::class)->reveal(), + $this->prophesize(ResourceClassResolverInterface::class)->reveal(), + $this->prophesize(OperationMethodResolverInterface::class)->reveal(), + $this->prophesize(OperationPathResolverInterface::class)->reveal(), + $this->prophesize(UrlGeneratorInterface::class)->reveal() + ); + + $this->assertInstanceOf(DocumentationNormalizer::class, $normalizer); + } + public function testNormalize() { $documentation = new Documentation(new ResourceNameCollection([Dummy::class]), 'Test API', 'This is a test API.', '1.2.3', ['jsonld' => ['application/ld+json']]); @@ -67,9 +86,6 @@ public function testNormalize() $operationMethodResolverProphecy->getCollectionOperationMethod(Dummy::class, 'custom')->shouldBeCalled()->willReturn('GET'); $operationMethodResolverProphecy->getCollectionOperationMethod(Dummy::class, 'custom2')->shouldBeCalled()->willReturn('POST'); - $urlGeneratorProphecy = $this->prophesize(UrlGeneratorInterface::class); - $urlGeneratorProphecy->generate('api_entrypoint')->willReturn('/app_dev.php/')->shouldBeCalled(); - $operationPathResolver = new CustomOperationPathResolver(new UnderscoreOperationPathResolver()); $normalizer = new DocumentationNormalizer( @@ -78,8 +94,7 @@ public function testNormalize() $propertyMetadataFactoryProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $operationMethodResolverProphecy->reveal(), - $operationPathResolver, - $urlGeneratorProphecy->reveal() + $operationPathResolver ); $expected = [ @@ -244,7 +259,7 @@ public function testNormalize() ]), ]; - $this->assertEquals($expected, $normalizer->normalize($documentation)); + $this->assertEquals($expected, $normalizer->normalize($documentation, DocumentationNormalizer::FORMAT, ['base_url' => '/app_dev.php/'])); } public function testNormalizeWithNameConverter() @@ -269,9 +284,6 @@ public function testNormalizeWithNameConverter() $operationMethodResolverProphecy = $this->prophesize(OperationMethodResolverInterface::class); $operationMethodResolverProphecy->getItemOperationMethod(Dummy::class, 'get')->shouldBeCalled()->willReturn('GET'); - $urlGeneratorProphecy = $this->prophesize(UrlGeneratorInterface::class); - $urlGeneratorProphecy->generate('api_entrypoint')->willReturn('/app_dev.php/')->shouldBeCalled(); - $nameConverterProphecy = $this->prophesize(NameConverterInterface::class); $nameConverterProphecy->normalize('name')->willReturn('name')->shouldBeCalled(); $nameConverterProphecy->normalize('nameConverted')->willReturn('name_converted')->shouldBeCalled(); @@ -285,7 +297,7 @@ public function testNormalizeWithNameConverter() $resourceClassResolverProphecy->reveal(), $operationMethodResolverProphecy->reveal(), $operationPathResolver, - $urlGeneratorProphecy->reveal(), + null, null, $nameConverterProphecy->reveal(), true, @@ -298,7 +310,7 @@ public function testNormalizeWithNameConverter() $expected = [ 'swagger' => '2.0', - 'basePath' => '/app_dev.php/', + 'basePath' => '/', 'info' => [ 'title' => 'Dummy API', 'description' => 'This is a dummy API', @@ -406,9 +418,6 @@ public function testNormalizeWithOnlyNormalizationGroups() $operationMethodResolverProphecy->getCollectionOperationMethod(Dummy::class, 'get')->shouldBeCalled()->willReturn('GET'); $operationMethodResolverProphecy->getCollectionOperationMethod(Dummy::class, 'post')->shouldBeCalled()->willReturn('POST'); - $urlGeneratorProphecy = $this->prophesize(UrlGeneratorInterface::class); - $urlGeneratorProphecy->generate('api_entrypoint')->willReturn('/app_dev.php/')->shouldBeCalled(); - $operationPathResolver = new CustomOperationPathResolver(new UnderscoreOperationPathResolver()); $normalizer = new DocumentationNormalizer( @@ -417,13 +426,12 @@ public function testNormalizeWithOnlyNormalizationGroups() $propertyMetadataFactoryProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $operationMethodResolverProphecy->reveal(), - $operationPathResolver, - $urlGeneratorProphecy->reveal() + $operationPathResolver ); $expected = [ 'swagger' => '2.0', - 'basePath' => '/app_dev.php/', + 'basePath' => '/', 'info' => [ 'title' => 'Test API', 'description' => 'This is a test API.', @@ -592,9 +600,6 @@ public function testNormalizeWithOnlyDenormalizationGroups() $operationMethodResolverProphecy->getCollectionOperationMethod(Dummy::class, 'get')->shouldBeCalled()->willReturn('GET'); $operationMethodResolverProphecy->getCollectionOperationMethod(Dummy::class, 'post')->shouldBeCalled()->willReturn('POST'); - $urlGeneratorProphecy = $this->prophesize(UrlGeneratorInterface::class); - $urlGeneratorProphecy->generate('api_entrypoint')->willReturn('/app_dev.php/')->shouldBeCalled(); - $operationPathResolver = new CustomOperationPathResolver(new UnderscoreOperationPathResolver()); $normalizer = new DocumentationNormalizer( @@ -603,13 +608,12 @@ public function testNormalizeWithOnlyDenormalizationGroups() $propertyMetadataFactoryProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $operationMethodResolverProphecy->reveal(), - $operationPathResolver, - $urlGeneratorProphecy->reveal() + $operationPathResolver ); $expected = [ 'swagger' => '2.0', - 'basePath' => '/app_dev.php/', + 'basePath' => '/', 'info' => [ 'title' => 'Test API', 'description' => 'This is a test API.', @@ -781,9 +785,6 @@ public function testNormalizeWithNormalizationAndDenormalizationGroups() $operationMethodResolverProphecy->getCollectionOperationMethod(Dummy::class, 'get')->shouldBeCalled()->willReturn('GET'); $operationMethodResolverProphecy->getCollectionOperationMethod(Dummy::class, 'post')->shouldBeCalled()->willReturn('POST'); - $urlGeneratorProphecy = $this->prophesize(UrlGeneratorInterface::class); - $urlGeneratorProphecy->generate('api_entrypoint')->willReturn('/app_dev.php/')->shouldBeCalled(); - $operationPathResolver = new CustomOperationPathResolver(new UnderscoreOperationPathResolver()); $normalizer = new DocumentationNormalizer( @@ -792,13 +793,12 @@ public function testNormalizeWithNormalizationAndDenormalizationGroups() $propertyMetadataFactoryProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $operationMethodResolverProphecy->reveal(), - $operationPathResolver, - $urlGeneratorProphecy->reveal() + $operationPathResolver ); $expected = [ 'swagger' => '2.0', - 'basePath' => '/app_dev.php/', + 'basePath' => '/', 'info' => [ 'title' => 'Test API', 'description' => 'This is a test API.', @@ -1004,7 +1004,6 @@ public function testSupports() $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class); $operationMethodResolverProphecy = $this->prophesize(OperationMethodResolverInterface::class); $operationPathResolver = new CustomOperationPathResolver(new UnderscoreOperationPathResolver()); - $urlGeneratorProphecy = $this->prophesize(UrlGeneratorInterface::class); $normalizer = new DocumentationNormalizer( $resourceMetadataFactoryProphecy->reveal(), @@ -1012,8 +1011,7 @@ public function testSupports() $propertyMetadataFactoryProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $operationMethodResolverProphecy->reveal(), - $operationPathResolver, - $urlGeneratorProphecy->reveal() + $operationPathResolver ); $documentation = new Documentation(new ResourceNameCollection([Dummy::class]), 'Test API', 'This is a test API.', '1.2.3', ['jsonld' => ['application/ld+json']]); @@ -1050,9 +1048,6 @@ public function testNoOperations() $operationMethodResolverProphecy = $this->prophesize(OperationMethodResolverInterface::class); $operationMethodResolverProphecy->getCollectionOperationMethod(Dummy::class, 'get')->shouldNotBeCalled(); - $urlGeneratorProphecy = $this->prophesize(UrlGeneratorInterface::class); - $urlGeneratorProphecy->generate('api_entrypoint')->willReturn('/')->shouldBeCalled(); - $operationPathResolver = new CustomOperationPathResolver(new UnderscoreOperationPathResolver()); $normalizer = new DocumentationNormalizer( @@ -1061,8 +1056,7 @@ public function testNoOperations() $propertyMetadataFactoryProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $operationMethodResolverProphecy->reveal(), - $operationPathResolver, - $urlGeneratorProphecy->reveal() + $operationPathResolver ); $expected = [ @@ -1103,9 +1097,6 @@ public function testWithCustomMethod() $operationMethodResolverProphecy = $this->prophesize(OperationMethodResolverInterface::class); $operationMethodResolverProphecy->getCollectionOperationMethod(Dummy::class, 'get')->shouldBeCalled()->willReturn('FOO'); - $urlGeneratorProphecy = $this->prophesize(UrlGeneratorInterface::class); - $urlGeneratorProphecy->generate('api_entrypoint')->willReturn('/')->shouldBeCalled(); - $operationPathResolver = new CustomOperationPathResolver(new UnderscoreOperationPathResolver()); $normalizer = new DocumentationNormalizer( @@ -1114,8 +1105,7 @@ public function testWithCustomMethod() $propertyMetadataFactoryProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $operationMethodResolverProphecy->reveal(), - $operationPathResolver, - $urlGeneratorProphecy->reveal() + $operationPathResolver ); $expected = [ @@ -1199,9 +1189,6 @@ public function testNormalizeWithNestedNormalizationGroups() $operationMethodResolverProphecy->getCollectionOperationMethod(Dummy::class, 'get')->shouldBeCalled()->willReturn('GET'); $operationMethodResolverProphecy->getCollectionOperationMethod(Dummy::class, 'post')->shouldBeCalled()->willReturn('POST'); - $urlGeneratorProphecy = $this->prophesize(UrlGeneratorInterface::class); - $urlGeneratorProphecy->generate('api_entrypoint')->willReturn('/app_dev.php/')->shouldBeCalled(); - $operationPathResolver = new CustomOperationPathResolver(new UnderscoreOperationPathResolver()); $normalizer = new DocumentationNormalizer( @@ -1210,13 +1197,12 @@ public function testNormalizeWithNestedNormalizationGroups() $propertyMetadataFactoryProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $operationMethodResolverProphecy->reveal(), - $operationPathResolver, - $urlGeneratorProphecy->reveal() + $operationPathResolver ); $expected = [ 'swagger' => '2.0', - 'basePath' => '/app_dev.php/', + 'basePath' => '/', 'info' => [ 'title' => 'Test API', 'description' => 'This is a test API.', @@ -1385,9 +1371,6 @@ private function normalizeWithFilters($filterLocator) $operationMethodResolverProphecy = $this->prophesize(OperationMethodResolverInterface::class); $operationMethodResolverProphecy->getCollectionOperationMethod(Dummy::class, 'get')->shouldBeCalled()->willReturn('GET'); - $urlGeneratorProphecy = $this->prophesize(UrlGeneratorInterface::class); - $urlGeneratorProphecy->generate('api_entrypoint')->willReturn('/')->shouldBeCalled(); - $operationPathResolver = new CustomOperationPathResolver(new UnderscoreOperationPathResolver()); $normalizer = new DocumentationNormalizer( @@ -1397,7 +1380,7 @@ private function normalizeWithFilters($filterLocator) $resourceClassResolverProphecy->reveal(), $operationMethodResolverProphecy->reveal(), $operationPathResolver, - $urlGeneratorProphecy->reveal(), + null, $filterLocator );