diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5094f0cb79c..5b447cc3470 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ env: EXT_MONGODB_VERSION: '1.5.5' EXT_PCOV_VERSION: '1.0.6' LEGACY: '0' - SYMFONY_REQUIRE: ^3.4 || ^4.0 + SYMFONY_REQUIRE: ^3.4 || ^4.0 || ^5.0 jobs: phpunit: @@ -173,7 +173,7 @@ jobs: run: | mkdir -p /tmp/api-platform/core/var ln -s /tmp/api-platform/core/var tests/Fixtures/app/var - tests/Fixtures/app/console cache:clear -- + tests/Fixtures/app/console cache:clear --ansi - name: Enable code coverage if: matrix.coverage run: echo '::set-env name=COVERAGE::1' @@ -1018,7 +1018,7 @@ jobs: run: | mkdir -p /tmp/api-platform/core/var ln -s /tmp/api-platform/core/var tests/Fixtures/app/var - tests/Fixtures/app/console cache:clear -- + tests/Fixtures/app/console cache:clear --ansi - name: Enable code coverage if: matrix.coverage run: echo '::set-env name=COVERAGE::1' @@ -1107,10 +1107,162 @@ jobs: run: | mkdir -p build/logs/phpunit vendor/bin/phpunit --log-junit build/logs/phpunit/junit.xml --colors=always - continue-on-error: true - name: Upload test artifacts if: always() uses: actions/upload-artifact@v1 with: name: phpunit-logs-php${{ matrix.php }}-no-deprecations path: build/logs/phpunit + + phpunit-symfony-next: + name: PHPUnit (PHP ${{ matrix.php }}) (Symfony ${{ matrix.symfony }}) + runs-on: ubuntu-latest + container: + image: php:${{ matrix.php }}-alpine + options: >- + --tmpfs /tmp:exec + strategy: + matrix: + php: + - '7.3' + symfony: + - '4.4' + fail-fast: false + timeout-minutes: 20 + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Install system packages + run: | + apk add \ + jq \ + moreutils \ + unzip \ + - name: Install mongodb PHP extension + run: | + apk add $PHPIZE_DEPS + pecl install mongodb-$EXT_MONGODB_VERSION + docker-php-ext-enable mongodb + - name: Disable PHP memory limit + run: echo 'memory_limit=-1' >> /usr/local/etc/php/php.ini + - name: Install Composer + run: wget -qO - https://raw.githubusercontent.com/composer/getcomposer.org/$COMPOSER_INSTALLER_COMMIT/web/installer | php -- --install-dir=/usr/local/bin --filename=composer --quiet + - name: Install Symfony Flex + run: | + composer global require --prefer-dist --no-progress --no-suggest --ansi \ + symfony/flex + - name: Allow unstable project dependencies + run: | + jq '. + {"minimum-stability": "dev"}' composer.json | sponge composer.json + - name: Update project dependencies + run: | + mkdir -p /tmp/api-platform/core/vendor + ln -s /tmp/api-platform/core/vendor vendor + composer update --no-progress --no-suggest --ansi + - name: Flag held back Symfony packages + env: + symfony_version: ${{ matrix.symfony }} + run: | + version_pattern=$symfony_version.x-dev + if [ "${symfony_version%.4}" != "$symfony_version" ]; then + current_major=${symfony_version%.4} + next_major=$((current_major + 1)) + version_pattern=$version_pattern'|'$next_major.0.x-dev'|'dev-master + fi + version_pattern=$(echo "$version_pattern" | sed -r 's/\./\\./g') + symfony_packages=$(composer show symfony/* | tr -s ' ' '\t' | cut -f1-2 | grep -vE 'polyfill|contracts|mercure') + ! echo "$symfony_packages" | grep -vE "$version_pattern" + continue-on-error: true + - name: Clear test app cache + run: | + mkdir -p /tmp/api-platform/core/var + ln -s /tmp/api-platform/core/var tests/Fixtures/app/var + tests/Fixtures/app/console cache:clear --ansi + - name: Run PHPUnit tests + run: | + mkdir -p build/logs/phpunit + vendor/bin/phpunit --log-junit build/logs/phpunit/junit.xml --colors=always + - name: Upload test artifacts + if: always() + uses: actions/upload-artifact@v1 + with: + name: phpunit-logs-php${{ matrix.php }}-symfony${{ matrix.symfony }} + path: build/logs/phpunit + + behat-symfony-next: + name: Behat (PHP ${{ matrix.php }}) (Symfony ${{ matrix.symfony }}) + runs-on: ubuntu-latest + container: + image: php:${{ matrix.php }}-alpine + options: >- + --tmpfs /tmp:exec + strategy: + matrix: + php: + - '7.3' + symfony: + - '4.4' + fail-fast: false + timeout-minutes: 20 + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Install system packages + run: | + apk add \ + jq \ + moreutils \ + unzip \ + - name: Install mongodb PHP extension + run: | + apk add $PHPIZE_DEPS + pecl install mongodb-$EXT_MONGODB_VERSION + docker-php-ext-enable mongodb + - name: Disable PHP memory limit + run: echo 'memory_limit=-1' >> /usr/local/etc/php/php.ini + - name: Install Composer + run: wget -qO - https://raw.githubusercontent.com/composer/getcomposer.org/$COMPOSER_INSTALLER_COMMIT/web/installer | php -- --install-dir=/usr/local/bin --filename=composer --quiet + - name: Install Symfony Flex + run: | + composer global require --prefer-dist --no-progress --no-suggest --ansi \ + symfony/flex + - name: Allow unstable project dependencies + run: | + jq '. + {"minimum-stability": "dev"}' composer.json | sponge composer.json + - name: Update project dependencies + run: | + mkdir -p /tmp/api-platform/core/vendor + ln -s /tmp/api-platform/core/vendor vendor + composer update --no-progress --no-suggest --ansi + - name: Flag held back Symfony packages + env: + symfony_version: ${{ matrix.symfony }} + run: | + version_pattern=$symfony_version.x-dev + if [ "${symfony_version%.4}" != "$symfony_version" ]; then + current_major=${symfony_version%.4} + next_major=$((current_major + 1)) + version_pattern=$version_pattern'|'$next_major.0.x-dev'|'dev-master + fi + version_pattern=$(echo "$version_pattern" | sed -r 's/\./\\./g') + symfony_packages=$(composer show symfony/* | tr -s ' ' '\t' | cut -f1-2 | grep -vE 'polyfill|contracts|mercure') + ! echo "$symfony_packages" | grep -vE "$version_pattern" + continue-on-error: true + - name: Enable legacy integrations + if: startsWith(matrix.php, '7.3') + run: echo '::set-env name=LEGACY::1' + - name: Clear test app cache + run: | + mkdir -p /tmp/api-platform/core/var + ln -s /tmp/api-platform/core/var tests/Fixtures/app/var + tests/Fixtures/app/console cache:clear --ansi + - name: Run Behat tests + run: | + mkdir -p build/logs/behat + vendor/bin/behat --format=progress --out=std --format=junit --out=build/logs/behat/junit --profile="$(if [ "$LEGACY" = '1' ]; then echo 'default-legacy'; else echo 'default'; fi)" --no-interaction --colors + - name: Upload test artifacts + if: always() + uses: actions/upload-artifact@v1 + with: + name: behat-logs-php${{ matrix.php }}-symfony${{ matrix.symfony }} + path: build/logs/behat diff --git a/composer.json b/composer.json index ab3be83299b..fd2eb4c9fe8 100644 --- a/composer.json +++ b/composer.json @@ -15,14 +15,15 @@ "require": { "php": ">=7.1", "doctrine/inflector": "^1.0", + "fig/link-util": "^1.0", "psr/cache": "^1.0", "psr/container": "^1.0", - "symfony/http-foundation": "^3.4 || ^4.0", - "symfony/http-kernel": "^3.4 || ^4.0", - "symfony/property-access": "^3.4 || ^4.0", - "symfony/property-info": "^3.4 || ^4.0", - "symfony/serializer": "^4.3", - "symfony/web-link": "^4.1", + "symfony/http-foundation": "^4.3.6 || ^5.0", + "symfony/http-kernel": "^4.3 || ^5.0", + "symfony/property-access": "^3.4 || ^4.0 || ^5.0", + "symfony/property-info": "^3.4 || ^4.0 || ^5.0", + "symfony/serializer": "^4.3 || ^5.0", + "symfony/web-link": "^4.1 || ^5.0", "willdurand/negotiation": "^2.0.3" }, "require-dev": { @@ -35,7 +36,7 @@ "doctrine/annotations": "^1.7", "doctrine/common": "^2.11", "doctrine/data-fixtures": "^1.2.2", - "doctrine/doctrine-bundle": "^1.8", + "doctrine/doctrine-bundle": "^1.8 || ^2.0", "doctrine/doctrine-cache-bundle": "^1.3.5", "doctrine/mongodb-odm": "^2.0", "doctrine/mongodb-odm-bundle": "^4.0", @@ -59,32 +60,32 @@ "ramsey/uuid": "^3.7", "ramsey/uuid-doctrine": "^1.4", "sebastian/object-enumerator": "^3.0.3", - "symfony/asset": "^3.4 || ^4.0", - "symfony/browser-kit": "^4.3", - "symfony/cache": "^3.4 || ^4.0", - "symfony/config": "^3.4 || ^4.0", - "symfony/console": "^3.4 || ^4.0", - "symfony/css-selector": "^3.4 || ^4.0", - "symfony/debug": "^3.4 || ^4.0", - "symfony/dependency-injection": "^3.4 || ^4.0", - "symfony/doctrine-bridge": "^3.4 || ^4.0", - "symfony/dom-crawler": "^3.4 || ^4.0", - "symfony/event-dispatcher": "^3.4 || ^4.0", - "symfony/expression-language": "^3.4 || ^4.0", - "symfony/finder": "^3.4 || ^4.0", - "symfony/form": "^3.4 || ^4.0", - "symfony/framework-bundle": "^4.3.2", - "symfony/http-client": "^4.3", + "symfony/asset": "^3.4 || ^4.0 || ^5.0", + "symfony/browser-kit": "^4.3 || ^5.0", + "symfony/cache": "^3.4 || ^4.0 || ^5.0", + "symfony/config": "^3.4 || ^4.0 || ^5.0", + "symfony/console": "^3.4 || ^4.0 || ^5.0", + "symfony/css-selector": "^3.4 || ^4.0 || ^5.0", + "symfony/debug": "^3.4 || ^4.0 || ^5.0", + "symfony/dependency-injection": "^3.4 || ^4.0 || ^5.0", + "symfony/doctrine-bridge": "^3.4 || ^4.0 || ^5.0", + "symfony/dom-crawler": "^3.4 || ^4.0 || ^5.0", + "symfony/event-dispatcher": "^3.4 || ^4.0 || ^5.0", + "symfony/expression-language": "^3.4 || ^4.0 || ^5.0", + "symfony/finder": "^3.4 || ^4.0 || ^5.0", + "symfony/form": "^3.4 || ^4.0 || ^5.0", + "symfony/framework-bundle": "^4.3.2 || ^5.0", + "symfony/http-client": "^4.3 || ^5.0", "symfony/mercure-bundle": "*", - "symfony/messenger": "^4.3", - "symfony/phpunit-bridge": "^4.3@dev", - "symfony/routing": "^3.4 || ^4.3", - "symfony/security-bundle": "^3.4 || ^4.0", - "symfony/security-core": "^4.3", - "symfony/twig-bundle": "^3.4 || ^4.0", - "symfony/validator": "^3.4 || ^4.0", - "symfony/web-profiler-bundle": "^4.2", - "symfony/yaml": "^3.4 || ^4.0", + "symfony/messenger": "^4.3 || ^5.0", + "symfony/phpunit-bridge": "^4.3 || ^5.0", + "symfony/routing": "^3.4 || ^4.3 || ^5.0", + "symfony/security-bundle": "^3.4 || ^4.0 || ^5.0", + "symfony/security-core": "^4.3 || ^5.0", + "symfony/twig-bundle": "^3.4 || ^4.0 || ^5.0", + "symfony/validator": "^3.4 || ^4.0 || ^5.0", + "symfony/web-profiler-bundle": "^4.2 || ^5.0", + "symfony/yaml": "^3.4 || ^4.0 || ^5.0", "twig/twig": "^1.42.3 || ^2.12", "webonyx/graphql-php": ">=0.13.1 <1.0" }, diff --git a/features/main/content_negotiation.feature b/features/main/content_negotiation.feature index b807e86b96b..71033af1f74 100644 --- a/features/main/content_negotiation.feature +++ b/features/main/content_negotiation.feature @@ -124,7 +124,7 @@ Feature: Content Negotiation support Then the response status code should be 406 And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8" - Scenario: Post an CSV body allowed on a single resource + Scenario: Post CSV body allowed on a single resource When I add "Accept" header equal to "application/xml" And I add "Content-Type" header equal to "text/csv" And I send a "POST" request to "/dummy_custom_formats" with body: diff --git a/phpstan.neon.dist b/phpstan.neon.dist index c1a32536fb4..9724777af5d 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -106,3 +106,14 @@ parameters: - '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Filter\\(Abstract|Exists|Order)Filter::filterProperty\(\) invoked with 7 parameters, 5-6 required\.#' - '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Filter\\(AbstractFilter|FilterInterface)::apply\(\) invoked with 5 parameters, 3-4 required\.#' - '#Method ApiPlatform\\Core\\PathResolver\\OperationPathResolverInterface::resolveOperationPath\(\) invoked with 4 parameters, 3 required\.#' + + # Expected, due to forward compatibility + - + message: '#Class Symfony\\Component\\ErrorRenderer\\ErrorRenderer not found\.#' + path: %currentWorkingDirectory%/tests/Fixtures/app/AppKernel.php + - + message: '#Parameter \$exception of method ApiPlatform\\Core\\Action\\ExceptionAction::__invoke\(\) has invalid typehint type Symfony\\Component\\ErrorRenderer\\Exception\\FlattenException\.#' + path: %currentWorkingDirectory%/src/Action/ExceptionAction.php + - + message: '#Call to method get(Class|Headers|StatusCode)\(\) on an unknown class Symfony\\Component\\ErrorRenderer\\Exception\\FlattenException\.#' + path: %currentWorkingDirectory%/src/Action/ExceptionAction.php diff --git a/src/Action/ExceptionAction.php b/src/Action/ExceptionAction.php index a47ffdb6da6..0aec32a935c 100644 --- a/src/Action/ExceptionAction.php +++ b/src/Action/ExceptionAction.php @@ -14,27 +14,14 @@ namespace ApiPlatform\Core\Action; use ApiPlatform\Core\Util\ErrorFormatGuesser; -use Symfony\Component\Debug\Exception\FlattenException; +use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException; +use Symfony\Component\ErrorRenderer\Exception\FlattenException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Serializer\SerializerInterface; /** - * Renders a normalized exception for a given {@see \Symfony\Component\Debug\Exception\FlattenException}. - * - * Usage: - * - * $exceptionAction = new ExceptionAction( - * new Serializer(), - * [ - * 'jsonproblem' => ['application/problem+json'], - * 'jsonld' => ['application/ld+json'], - * ], - * [ - * ExceptionInterface::class => Response::HTTP_BAD_REQUEST, - * InvalidArgumentException::class => Response::HTTP_BAD_REQUEST, - * ] - * ); + * Renders a normalized exception for a given {@see FlattenException} or {@see LegacyFlattenException}. * * @author Baptiste Meyer * @author Kévin Dunglas @@ -46,7 +33,7 @@ final class ExceptionAction private $exceptionToStatus; /** - * @param array $errorFormats A list of enabled formats, the first one will be the default + * @param array $errorFormats A list of enabled error formats * @param array $exceptionToStatus A list of exceptions mapped to their HTTP status code */ public function __construct(SerializerInterface $serializer, array $errorFormats, array $exceptionToStatus = []) @@ -58,8 +45,10 @@ public function __construct(SerializerInterface $serializer, array $errorFormats /** * Converts an exception to a JSON response. + * + * @param FlattenException|LegacyFlattenException $exception */ - public function __invoke(FlattenException $exception, Request $request): Response + public function __invoke($exception, Request $request): Response { $exceptionClass = $exception->getClass(); $statusCode = $exception->getStatusCode(); diff --git a/src/Bridge/Doctrine/EventListener/WriteListener.php b/src/Bridge/Doctrine/EventListener/WriteListener.php index abb74298497..2bcce027261 100644 --- a/src/Bridge/Doctrine/EventListener/WriteListener.php +++ b/src/Bridge/Doctrine/EventListener/WriteListener.php @@ -16,7 +16,7 @@ use ApiPlatform\Core\EventListener\WriteListener as BaseWriteListener; use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\Common\Persistence\ObjectManager; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; /** * Bridges Doctrine and the API system. @@ -39,10 +39,10 @@ public function __construct(ManagerRegistry $managerRegistry) /** * Persists, updates or delete data return by the controller if applicable. */ - public function onKernelView(GetResponseForControllerResultEvent $event): void + public function onKernelView(ViewEvent $event): void { $request = $event->getRequest(); - if ($request->isMethodSafe(false)) { + if ($request->isMethodSafe()) { return; } diff --git a/src/Bridge/Doctrine/Orm/ItemDataProvider.php b/src/Bridge/Doctrine/Orm/ItemDataProvider.php index eda84ddc296..980f2ca6e38 100644 --- a/src/Bridge/Doctrine/Orm/ItemDataProvider.php +++ b/src/Bridge/Doctrine/Orm/ItemDataProvider.php @@ -74,10 +74,7 @@ public function getItem(string $resourceClass, $id, string $operationName = null $id = $this->normalizeIdentifiers($id, $manager, $resourceClass); } if (!\is_array($id)) { - throw new \InvalidArgumentException(sprintf( - '$id must be array when "%s" key is set to true in the $context', - IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER - )); + throw new \InvalidArgumentException(sprintf('$id must be array when "%s" key is set to true in the $context', IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER)); } $identifiers = $id; diff --git a/src/Bridge/Doctrine/Orm/SubresourceDataProvider.php b/src/Bridge/Doctrine/Orm/SubresourceDataProvider.php index ae20bde2e65..9653228162c 100644 --- a/src/Bridge/Doctrine/Orm/SubresourceDataProvider.php +++ b/src/Bridge/Doctrine/Orm/SubresourceDataProvider.php @@ -142,9 +142,7 @@ private function buildQuery(array $identifiers, array $context, QueryNameGenerat $classMetadata = $manager->getClassMetadata($identifierResourceClass); if (!$classMetadata instanceof ClassMetadataInfo) { - throw new RuntimeException( - "The class metadata for $identifierResourceClass must be an instance of ClassMetadataInfo." - ); + throw new RuntimeException("The class metadata for $identifierResourceClass must be an instance of ClassMetadataInfo."); } $qb = $manager->createQueryBuilder(); diff --git a/src/Bridge/FosUser/EventListener.php b/src/Bridge/FosUser/EventListener.php index a24a9fb0454..cbc2401601e 100644 --- a/src/Bridge/FosUser/EventListener.php +++ b/src/Bridge/FosUser/EventListener.php @@ -16,7 +16,7 @@ use ApiPlatform\Core\Util\RequestAttributesExtractor; use FOS\UserBundle\Model\UserInterface; use FOS\UserBundle\Model\UserManagerInterface; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; /** * Bridges between FOSUserBundle and API Platform Core. @@ -36,7 +36,7 @@ public function __construct(UserManagerInterface $userManager) /** * Persists, updates or delete data return by the controller if applicable. */ - public function onKernelView(GetResponseForControllerResultEvent $event): void + public function onKernelView(ViewEvent $event): void { $request = $event->getRequest(); if (!RequestAttributesExtractor::extractAttributes($request)) { @@ -44,7 +44,7 @@ public function onKernelView(GetResponseForControllerResultEvent $event): void } $user = $event->getControllerResult(); - if (!$user instanceof UserInterface || $request->isMethodSafe(false)) { + if (!$user instanceof UserInterface || $request->isMethodSafe()) { return; } diff --git a/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php b/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php index 976c2e0ea67..83bebc0e64e 100644 --- a/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php +++ b/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php @@ -153,7 +153,7 @@ private function getContext(Request $request, Documentation $documentation): arr 'scopes' => $this->oauthScopes, ]; - if ($request->isMethodSafe(false) && null !== $resourceClass = $request->attributes->get('_api_resource_class')) { + if ($request->isMethodSafe() && null !== $resourceClass = $request->attributes->get('_api_resource_class')) { $swaggerData['id'] = $request->attributes->get('id'); $swaggerData['queryParameters'] = $request->query->all(); diff --git a/src/Bridge/Symfony/Bundle/EventListener/SwaggerUiListener.php b/src/Bridge/Symfony/Bundle/EventListener/SwaggerUiListener.php index e22fac5950c..7b56fd1bdd2 100644 --- a/src/Bridge/Symfony/Bundle/EventListener/SwaggerUiListener.php +++ b/src/Bridge/Symfony/Bundle/EventListener/SwaggerUiListener.php @@ -13,14 +13,14 @@ namespace ApiPlatform\Core\Bridge\Symfony\Bundle\EventListener; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; final class SwaggerUiListener { /** * Sets SwaggerUiAction as controller if the requested format is HTML. */ - public function onKernelRequest(GetResponseEvent $event): void + public function onKernelRequest(RequestEvent $event): void { $request = $event->getRequest(); if ( diff --git a/src/Bridge/Symfony/Routing/IriConverter.php b/src/Bridge/Symfony/Routing/IriConverter.php index 272312ba77c..001bb7f3bd9 100644 --- a/src/Bridge/Symfony/Routing/IriConverter.php +++ b/src/Bridge/Symfony/Routing/IriConverter.php @@ -122,10 +122,7 @@ public function getIriFromItem($item, int $referenceType = UrlGeneratorInterface try { $identifiers = $this->identifiersExtractor->getIdentifiersFromItem($item); } catch (RuntimeException $e) { - throw new InvalidArgumentException(sprintf( - 'Unable to generate an IRI for the item of type "%s"', - $resourceClass - ), $e->getCode(), $e); + throw new InvalidArgumentException(sprintf('Unable to generate an IRI for the item of type "%s"', $resourceClass), $e->getCode(), $e); } return $this->getItemIriFromResourceClass($resourceClass, $identifiers, $referenceType); @@ -155,10 +152,7 @@ public function getItemIriFromResourceClass(string $resourceClass, array $identi return $this->router->generate($routeName, ['id' => implode(';', $identifiers)], $referenceType); } catch (RoutingExceptionInterface $e) { - throw new InvalidArgumentException(sprintf( - 'Unable to generate an IRI for "%s".', - $resourceClass - ), $e->getCode(), $e); + throw new InvalidArgumentException(sprintf('Unable to generate an IRI for "%s".', $resourceClass), $e->getCode(), $e); } } @@ -184,10 +178,7 @@ public function getSubresourceIriFromResourceClass(string $resourceClass, array private function generateIdentifiersUrl(array $identifiers, string $resourceClass): array { if (0 === \count($identifiers)) { - throw new InvalidArgumentException(sprintf( - 'No identifiers defined for resource of type "%s"', - $resourceClass - )); + throw new InvalidArgumentException(sprintf('No identifiers defined for resource of type "%s"', $resourceClass)); } if (1 === \count($identifiers)) { diff --git a/src/Bridge/Symfony/Validator/EventListener/ValidateListener.php b/src/Bridge/Symfony/Validator/EventListener/ValidateListener.php index cc38f2e8cfb..6adfe433f91 100644 --- a/src/Bridge/Symfony/Validator/EventListener/ValidateListener.php +++ b/src/Bridge/Symfony/Validator/EventListener/ValidateListener.php @@ -18,7 +18,7 @@ use ApiPlatform\Core\Util\RequestAttributesExtractor; use ApiPlatform\Core\Validator\EventListener\ValidateListener as MainValidateListener; use Psr\Container\ContainerInterface; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; use Symfony\Component\Validator\Validator\ValidatorInterface; /** @@ -48,11 +48,11 @@ public function __construct(ValidatorInterface $validator, ResourceMetadataFacto * * @throws ValidationException */ - public function onKernelView(GetResponseForControllerResultEvent $event): void + public function onKernelView(ViewEvent $event): void { $request = $event->getRequest(); if ( - $request->isMethodSafe(false) + $request->isMethodSafe() || $request->isMethod('DELETE') || !($attributes = RequestAttributesExtractor::extractAttributes($request)) || !$attributes['receive'] diff --git a/src/Bridge/Symfony/Validator/EventListener/ValidationExceptionListener.php b/src/Bridge/Symfony/Validator/EventListener/ValidationExceptionListener.php index 9d00d6d5f33..c332aa49014 100644 --- a/src/Bridge/Symfony/Validator/EventListener/ValidationExceptionListener.php +++ b/src/Bridge/Symfony/Validator/EventListener/ValidationExceptionListener.php @@ -16,7 +16,7 @@ use ApiPlatform\Core\Bridge\Symfony\Validator\Exception\ValidationException; use ApiPlatform\Core\Util\ErrorFormatGuesser; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\Serializer\SerializerInterface; /** @@ -38,7 +38,7 @@ public function __construct(SerializerInterface $serializer, array $errorFormats /** * Returns a list of violations normalized in the Hydra format. */ - public function onKernelException(GetResponseForExceptionEvent $event): void + public function onKernelException(ExceptionEvent $event): void { $exception = $event->getException(); if (!$exception instanceof ValidationException) { diff --git a/src/EventListener/AddFormatListener.php b/src/EventListener/AddFormatListener.php index 11f19d630ee..ff97db88b81 100644 --- a/src/EventListener/AddFormatListener.php +++ b/src/EventListener/AddFormatListener.php @@ -19,7 +19,7 @@ use ApiPlatform\Core\Util\RequestAttributesExtractor; use Negotiation\Negotiator; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -62,7 +62,7 @@ public function __construct(Negotiator $negotiator, $resourceMetadataFactory, ar * @throws NotFoundHttpException * @throws NotAcceptableHttpException */ - public function onKernelRequest(GetResponseEvent $event): void + public function onKernelRequest(RequestEvent $event): void { $request = $event->getRequest(); if ( diff --git a/src/EventListener/DeserializeListener.php b/src/EventListener/DeserializeListener.php index ae0eb992d5a..ef63c1ed4ea 100644 --- a/src/EventListener/DeserializeListener.php +++ b/src/EventListener/DeserializeListener.php @@ -20,7 +20,7 @@ use ApiPlatform\Core\Serializer\SerializerContextBuilderInterface; use ApiPlatform\Core\Util\RequestAttributesExtractor; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\SerializerInterface; @@ -66,14 +66,14 @@ public function __construct(SerializerInterface $serializer, SerializerContextBu * * @throws UnsupportedMediaTypeHttpException */ - public function onKernelRequest(GetResponseEvent $event): void + public function onKernelRequest(RequestEvent $event): void { $request = $event->getRequest(); $method = $request->getMethod(); if ( 'DELETE' === $method - || $request->isMethodSafe(false) + || $request->isMethodSafe() || !($attributes = RequestAttributesExtractor::extractAttributes($request)) || !$attributes['receive'] || $this->isOperationAttributeDisabled($attributes, self::OPERATION_ATTRIBUTE_KEY) @@ -132,11 +132,7 @@ private function getFormat(Request $request, array $formats): string } } - throw new UnsupportedMediaTypeHttpException(sprintf( - 'The content-type "%s" is not supported. Supported MIME types are "%s".', - $contentType, - implode('", "', $supportedMimeTypes) - )); + throw new UnsupportedMediaTypeHttpException(sprintf('The content-type "%s" is not supported. Supported MIME types are "%s".', $contentType, implode('", "', $supportedMimeTypes))); } return $format; diff --git a/src/EventListener/ExceptionListener.php b/src/EventListener/ExceptionListener.php index b995e003258..d87f0ddc894 100644 --- a/src/EventListener/ExceptionListener.php +++ b/src/EventListener/ExceptionListener.php @@ -15,7 +15,7 @@ use ApiPlatform\Core\Util\RequestAttributesExtractor; use Psr\Log\LoggerInterface; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\EventListener\ExceptionListener as BaseExceptionListener; /** @@ -33,7 +33,7 @@ public function __construct($controller, LoggerInterface $logger = null, $debug $this->exceptionListener = new BaseExceptionListener($controller, $logger, $debug); } - public function onKernelException(GetResponseForExceptionEvent $event): void + public function onKernelException(ExceptionEvent $event): void { $request = $event->getRequest(); // Normalize exceptions only for routes managed by API Platform diff --git a/src/EventListener/ReadListener.php b/src/EventListener/ReadListener.php index 6d97441197f..87dbe3e945f 100644 --- a/src/EventListener/ReadListener.php +++ b/src/EventListener/ReadListener.php @@ -26,7 +26,7 @@ use ApiPlatform\Core\Util\CloneTrait; use ApiPlatform\Core\Util\RequestAttributesExtractor; use ApiPlatform\Core\Util\RequestParser; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** @@ -59,7 +59,7 @@ public function __construct(CollectionDataProviderInterface $collectionDataProvi * * @throws NotFoundHttpException */ - public function onKernelRequest(GetResponseEvent $event): void + public function onKernelRequest(RequestEvent $event): void { $request = $event->getRequest(); if ( diff --git a/src/EventListener/RespondListener.php b/src/EventListener/RespondListener.php index 52a0cea38af..b611399ae05 100644 --- a/src/EventListener/RespondListener.php +++ b/src/EventListener/RespondListener.php @@ -17,7 +17,7 @@ use ApiPlatform\Core\Metadata\Resource\ResourceMetadata; use ApiPlatform\Core\Util\RequestAttributesExtractor; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; /** * Builds the response object. @@ -41,7 +41,7 @@ public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFa /** * Creates a Response to send to the client according to the requested format. */ - public function onKernelView(GetResponseForControllerResultEvent $event): void + public function onKernelView(ViewEvent $event): void { $controllerResult = $event->getControllerResult(); $request = $event->getRequest(); diff --git a/src/EventListener/SerializeListener.php b/src/EventListener/SerializeListener.php index c0669484056..48669529353 100644 --- a/src/EventListener/SerializeListener.php +++ b/src/EventListener/SerializeListener.php @@ -23,7 +23,7 @@ use Fig\Link\Link; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; use Symfony\Component\Serializer\Encoder\EncoderInterface; use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; use Symfony\Component\Serializer\SerializerInterface; @@ -52,7 +52,7 @@ public function __construct(SerializerInterface $serializer, SerializerContextBu /** * Serializes the data to the requested format. */ - public function onKernelView(GetResponseForControllerResultEvent $event): void + public function onKernelView(ViewEvent $event): void { $controllerResult = $event->getControllerResult(); $request = $event->getRequest(); @@ -113,7 +113,7 @@ public function onKernelView(GetResponseForControllerResultEvent $event): void * * @throws RuntimeException */ - private function serializeRawData(GetResponseForControllerResultEvent $event, Request $request, $controllerResult): void + private function serializeRawData(ViewEvent $event, Request $request, $controllerResult): void { if (\is_object($controllerResult)) { $event->setControllerResult($this->serializer->serialize($controllerResult, $request->getRequestFormat(), $request->attributes->get('_api_normalization_context', []))); diff --git a/src/EventListener/WriteListener.php b/src/EventListener/WriteListener.php index 22c75df1f16..bab63301357 100644 --- a/src/EventListener/WriteListener.php +++ b/src/EventListener/WriteListener.php @@ -21,7 +21,7 @@ use ApiPlatform\Core\Util\RequestAttributesExtractor; use ApiPlatform\Core\Util\ResourceClassInfoTrait; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; /** * Bridges persistence and the API system. @@ -50,14 +50,14 @@ public function __construct(DataPersisterInterface $dataPersister, IriConverterI /** * Persists, updates or delete data return by the controller if applicable. */ - public function onKernelView(GetResponseForControllerResultEvent $event): void + public function onKernelView(ViewEvent $event): void { $controllerResult = $event->getControllerResult(); $request = $event->getRequest(); if ( $controllerResult instanceof Response - || $request->isMethodSafe(false) + || $request->isMethodSafe() || !($attributes = RequestAttributesExtractor::extractAttributes($request)) || !$attributes['persist'] || $this->isOperationAttributeDisabled($attributes, self::OPERATION_ATTRIBUTE_KEY) diff --git a/src/Filter/QueryParameterValidateListener.php b/src/Filter/QueryParameterValidateListener.php index e98c955cb03..c6583a02c44 100644 --- a/src/Filter/QueryParameterValidateListener.php +++ b/src/Filter/QueryParameterValidateListener.php @@ -19,7 +19,7 @@ use ApiPlatform\Core\Util\RequestAttributesExtractor; use Psr\Container\ContainerInterface; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; /** * Validates query parameters depending on filter description. @@ -38,11 +38,11 @@ public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFa $this->setFilterLocator($filterLocator); } - public function onKernelRequest(GetResponseEvent $event): void + public function onKernelRequest(RequestEvent $event): void { $request = $event->getRequest(); if ( - !$request->isMethodSafe(false) + !$request->isMethodSafe() || !($attributes = RequestAttributesExtractor::extractAttributes($request)) || !isset($attributes['collection_operation_name']) || 'get' !== ($operationName = $attributes['collection_operation_name']) diff --git a/src/GraphQl/Type/TypeBuilder.php b/src/GraphQl/Type/TypeBuilder.php index b557ce76b25..d13beacb973 100644 --- a/src/GraphQl/Type/TypeBuilder.php +++ b/src/GraphQl/Type/TypeBuilder.php @@ -77,11 +77,7 @@ public function getResourceObjectType(?string $resourceClass, ResourceMetadata $ if ($this->typesContainer->has($shortName)) { $resourceObjectType = $this->typesContainer->get($shortName); if (!($resourceObjectType instanceof ObjectType || $resourceObjectType instanceof NonNull)) { - throw new \UnexpectedValueException(sprintf( - 'Expected GraphQL type "%s" to be %s.', - $shortName, - implode('|', [ObjectType::class, NonNull::class]) - )); + throw new \UnexpectedValueException(sprintf('Expected GraphQL type "%s" to be %s.', $shortName, implode('|', [ObjectType::class, NonNull::class]))); } return $resourceObjectType; diff --git a/src/GraphQl/Type/TypesContainer.php b/src/GraphQl/Type/TypesContainer.php index 4c5cf9bc65d..cdd0a7d92d2 100644 --- a/src/GraphQl/Type/TypesContainer.php +++ b/src/GraphQl/Type/TypesContainer.php @@ -43,10 +43,7 @@ public function get($id): GraphQLType return $this->graphqlTypes[$id]; } - throw new TypeNotFoundException( - sprintf('Type with id "%s" is not present in the types container', $id), - $id - ); + throw new TypeNotFoundException(sprintf('Type with id "%s" is not present in the types container', $id), $id); } /** diff --git a/src/HttpCache/EventListener/AddHeadersListener.php b/src/HttpCache/EventListener/AddHeadersListener.php index dbd77f8e5e1..9ea49d7f951 100644 --- a/src/HttpCache/EventListener/AddHeadersListener.php +++ b/src/HttpCache/EventListener/AddHeadersListener.php @@ -15,7 +15,7 @@ use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface; use ApiPlatform\Core\Util\RequestAttributesExtractor; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; /** * Configures cache HTTP headers for the current response. @@ -43,7 +43,7 @@ public function __construct(bool $etag = false, int $maxAge = null, int $sharedM $this->resourceMetadataFactory = $resourceMetadataFactory; } - public function onKernelResponse(FilterResponseEvent $event): void + public function onKernelResponse(ResponseEvent $event): void { $request = $event->getRequest(); if (!$request->isMethodCacheable() || !RequestAttributesExtractor::extractAttributes($request)) { diff --git a/src/HttpCache/EventListener/AddTagsListener.php b/src/HttpCache/EventListener/AddTagsListener.php index 6db41c703ae..ff851e4372f 100644 --- a/src/HttpCache/EventListener/AddTagsListener.php +++ b/src/HttpCache/EventListener/AddTagsListener.php @@ -15,7 +15,7 @@ use ApiPlatform\Core\Api\IriConverterInterface; use ApiPlatform\Core\Util\RequestAttributesExtractor; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; /** * Sets the list of resources' IRIs included in this response in the "Cache-Tags" HTTP header. @@ -40,7 +40,7 @@ public function __construct(IriConverterInterface $iriConverter) /** * Adds the "Cache-Tags" header. */ - public function onKernelResponse(FilterResponseEvent $event): void + public function onKernelResponse(ResponseEvent $event): void { $request = $event->getRequest(); $response = $event->getResponse(); diff --git a/src/Hydra/EventListener/AddLinkHeaderListener.php b/src/Hydra/EventListener/AddLinkHeaderListener.php index d222c336c49..0e42a7fd2cb 100644 --- a/src/Hydra/EventListener/AddLinkHeaderListener.php +++ b/src/Hydra/EventListener/AddLinkHeaderListener.php @@ -17,7 +17,7 @@ use ApiPlatform\Core\JsonLd\ContextBuilder; use Fig\Link\GenericLinkProvider; use Fig\Link\Link; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; /** * Adds the HTTP Link header pointing to the Hydra documentation. @@ -36,7 +36,7 @@ public function __construct(UrlGeneratorInterface $urlGenerator) /** * Sends the Hydra header on each response. */ - public function onKernelResponse(FilterResponseEvent $event): void + public function onKernelResponse(ResponseEvent $event): void { $apiDocUrl = $this->urlGenerator->generate('api_doc', ['_format' => 'jsonld'], UrlGeneratorInterface::ABS_URL); $link = new Link(ContextBuilder::HYDRA_NS.'apiDocumentation', $apiDocUrl); diff --git a/src/Identifier/IdentifierConverter.php b/src/Identifier/IdentifierConverter.php index 53fc196f9a5..9faafd8ef54 100644 --- a/src/Identifier/IdentifierConverter.php +++ b/src/Identifier/IdentifierConverter.php @@ -18,6 +18,7 @@ use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface; use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface; use Symfony\Component\PropertyInfo\Type; +use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; /** * Identifier converter that chains identifier denormalizers. @@ -31,7 +32,10 @@ final class IdentifierConverter implements ContextAwareIdentifierConverterInterf private $identifierDenormalizers; private $resourceMetadataFactory; - public function __construct(IdentifiersExtractorInterface $identifiersExtractor, PropertyMetadataFactoryInterface $propertyMetadataFactory, $identifierDenormalizers, ResourceMetadataFactoryInterface $resourceMetadataFactory = null) + /** + * @param iterable $identifierDenormalizers + */ + public function __construct(IdentifiersExtractorInterface $identifiersExtractor, PropertyMetadataFactoryInterface $propertyMetadataFactory, iterable $identifierDenormalizers, ResourceMetadataFactoryInterface $resourceMetadataFactory = null) { $this->propertyMetadataFactory = $propertyMetadataFactory; $this->identifiersExtractor = $identifiersExtractor; @@ -65,14 +69,17 @@ public function convert(string $data, string $class, array $context = []): array throw new InvalidIdentifierException(sprintf('Invalid identifier "%1$s", "%1$s" was not found.', $key)); } - $metadata = $this->getIdentifierMetadata($class, $key); - foreach ($this->identifierDenormalizers as $normalizer) { - if (!$normalizer->supportsDenormalization($identifiers[$key], $metadata)) { + if (null === $type = $this->getIdentifierType($class, $key)) { + continue; + } + + foreach ($this->identifierDenormalizers as $identifierDenormalizer) { + if (!$identifierDenormalizer->supportsDenormalization($identifiers[$key], $type)) { continue; } try { - $identifiers[$key] = $normalizer->denormalize($identifiers[$key], $metadata); + $identifiers[$key] = $identifierDenormalizer->denormalize($identifiers[$key], $type); } catch (InvalidIdentifierException $e) { throw new InvalidIdentifierException(sprintf('Identifier "%s" could not be denormalized.', $key), $e->getCode(), $e); } @@ -82,12 +89,12 @@ public function convert(string $data, string $class, array $context = []): array return $identifiers; } - private function getIdentifierMetadata($class, $propertyName) + private function getIdentifierType(string $resourceClass, string $property): ?string { - if (!$type = $this->propertyMetadataFactory->create($class, $propertyName)->getType()) { + if (!$type = $this->propertyMetadataFactory->create($resourceClass, $property)->getType()) { return null; } - return Type::BUILTIN_TYPE_OBJECT === ($builtInType = $type->getBuiltinType()) ? $type->getClassName() : $builtInType; + return Type::BUILTIN_TYPE_OBJECT === ($builtinType = $type->getBuiltinType()) ? $type->getClassName() : $builtinType; } } diff --git a/src/JsonApi/EventListener/TransformFieldsetsParametersListener.php b/src/JsonApi/EventListener/TransformFieldsetsParametersListener.php index f1bb1f200a8..ec10a093f1f 100644 --- a/src/JsonApi/EventListener/TransformFieldsetsParametersListener.php +++ b/src/JsonApi/EventListener/TransformFieldsetsParametersListener.php @@ -14,7 +14,7 @@ namespace ApiPlatform\Core\JsonApi\EventListener; use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; /** * @see http://jsonapi.org/format/#fetching-sparse-fieldsets @@ -31,7 +31,7 @@ public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFa $this->resourceMetadataFactory = $resourceMetadataFactory; } - public function onKernelRequest(GetResponseEvent $event): void + public function onKernelRequest(RequestEvent $event): void { $request = $event->getRequest(); diff --git a/src/JsonApi/EventListener/TransformFilteringParametersListener.php b/src/JsonApi/EventListener/TransformFilteringParametersListener.php index 6aba979ba61..d4b36490c47 100644 --- a/src/JsonApi/EventListener/TransformFilteringParametersListener.php +++ b/src/JsonApi/EventListener/TransformFilteringParametersListener.php @@ -13,7 +13,7 @@ namespace ApiPlatform\Core\JsonApi\EventListener; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; /** * @see http://jsonapi.org/format/#fetching-filtering @@ -24,7 +24,7 @@ */ final class TransformFilteringParametersListener { - public function onKernelRequest(GetResponseEvent $event): void + public function onKernelRequest(RequestEvent $event): void { $request = $event->getRequest(); if ( diff --git a/src/JsonApi/EventListener/TransformPaginationParametersListener.php b/src/JsonApi/EventListener/TransformPaginationParametersListener.php index 289bbc67428..a8d2ae6f59c 100644 --- a/src/JsonApi/EventListener/TransformPaginationParametersListener.php +++ b/src/JsonApi/EventListener/TransformPaginationParametersListener.php @@ -13,7 +13,7 @@ namespace ApiPlatform\Core\JsonApi\EventListener; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; /** * @see http://jsonapi.org/format/#fetching-pagination @@ -24,7 +24,7 @@ */ final class TransformPaginationParametersListener { - public function onKernelRequest(GetResponseEvent $event): void + public function onKernelRequest(RequestEvent $event): void { $request = $event->getRequest(); diff --git a/src/JsonApi/EventListener/TransformSortingParametersListener.php b/src/JsonApi/EventListener/TransformSortingParametersListener.php index b221da4bd3c..5a364575571 100644 --- a/src/JsonApi/EventListener/TransformSortingParametersListener.php +++ b/src/JsonApi/EventListener/TransformSortingParametersListener.php @@ -13,7 +13,7 @@ namespace ApiPlatform\Core\JsonApi\EventListener; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; /** * @see http://jsonapi.org/format/#fetching-sorting @@ -31,7 +31,7 @@ public function __construct(string $orderParameterName = 'order') $this->orderParameterName = $orderParameterName; } - public function onKernelRequest(GetResponseEvent $event): void + public function onKernelRequest(RequestEvent $event): void { $request = $event->getRequest(); diff --git a/src/Mercure/EventListener/AddLinkHeaderListener.php b/src/Mercure/EventListener/AddLinkHeaderListener.php index 794310e3342..12b83bbed28 100644 --- a/src/Mercure/EventListener/AddLinkHeaderListener.php +++ b/src/Mercure/EventListener/AddLinkHeaderListener.php @@ -16,7 +16,7 @@ use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface; use Fig\Link\GenericLinkProvider; use Fig\Link\Link; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; /** * Adds the HTTP Link header pointing to the Mercure hub for resources having their updates dispatched. @@ -37,7 +37,7 @@ public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFa /** * Sends the Mercure header on each response. */ - public function onKernelResponse(FilterResponseEvent $event): void + public function onKernelResponse(ResponseEvent $event): void { $link = new Link('mercure', $this->hub); diff --git a/src/Security/EventListener/DenyAccessListener.php b/src/Security/EventListener/DenyAccessListener.php index f425ff98af8..c4a307a06d3 100644 --- a/src/Security/EventListener/DenyAccessListener.php +++ b/src/Security/EventListener/DenyAccessListener.php @@ -19,7 +19,7 @@ use ApiPlatform\Core\Security\ResourceAccessCheckerInterface; use ApiPlatform\Core\Util\RequestAttributesExtractor; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; @@ -53,18 +53,18 @@ public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFa @trigger_error(sprintf('Passing an instance of "%s" or null as second argument of "%s" is deprecated since API Platform 2.2 and will not be possible anymore in API Platform 3. Pass an instance of "%s" and no extra argument instead.', ExpressionLanguage::class, self::class, ResourceAccessCheckerInterface::class), E_USER_DEPRECATED); } - public function onKernelRequest(GetResponseEvent $event): void + public function onKernelRequest(RequestEvent $event): void { @trigger_error(sprintf('Method "%1$s::onKernelRequest" is deprecated since API Platform 2.4 and will not be available anymore in API Platform 3. Prefer calling "%1$s::onSecurity" instead.', self::class), E_USER_DEPRECATED); $this->onSecurityPostDenormalize($event); } - public function onSecurity(GetResponseEvent $event): void + public function onSecurity(RequestEvent $event): void { $this->checkSecurity($event->getRequest(), 'security', false); } - public function onSecurityPostDenormalize(GetResponseEvent $event): void + public function onSecurityPostDenormalize(RequestEvent $event): void { $request = $event->getRequest(); $this->checkSecurity($request, 'security_post_denormalize', true, [ diff --git a/src/Serializer/AbstractItemNormalizer.php b/src/Serializer/AbstractItemNormalizer.php index 7c067184f88..932c5ed9efc 100644 --- a/src/Serializer/AbstractItemNormalizer.php +++ b/src/Serializer/AbstractItemNormalizer.php @@ -281,13 +281,7 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref } elseif ($constructorParameter->isDefaultValueAvailable()) { $params[] = $constructorParameter->getDefaultValue(); } else { - throw new MissingConstructorArgumentsException( - sprintf( - 'Cannot create an instance of %s from serialized data because its constructor requires parameter "%s" to be present.', - $class, - $constructorParameter->name - ) - ); + throw new MissingConstructorArgumentsException(sprintf('Cannot create an instance of %s from serialized data because its constructor requires parameter "%s" to be present.', $class, $constructorParameter->name)); } } @@ -368,9 +362,7 @@ protected function validateType(string $attribute, Type $type, $value, string $f } if (!$isValid) { - throw new InvalidArgumentException(sprintf( - 'The type of the "%s" attribute must be "%s", "%s" given.', $attribute, $builtinType, \gettype($value) - )); + throw new InvalidArgumentException(sprintf('The type of the "%s" attribute must be "%s", "%s" given.', $attribute, $builtinType, \gettype($value))); } } @@ -382,9 +374,7 @@ protected function validateType(string $attribute, Type $type, $value, string $f protected function denormalizeCollection(string $attribute, PropertyMetadata $propertyMetadata, Type $type, string $className, $value, ?string $format, array $context): array { if (!\is_array($value)) { - throw new InvalidArgumentException(sprintf( - 'The type of the "%s" attribute must be "array", "%s" given.', $attribute, \gettype($value) - )); + throw new InvalidArgumentException(sprintf('The type of the "%s" attribute must be "array", "%s" given.', $attribute, \gettype($value))); } $collectionKeyType = $type->getCollectionKeyType(); @@ -393,10 +383,7 @@ protected function denormalizeCollection(string $attribute, PropertyMetadata $pr $values = []; foreach ($value as $index => $obj) { if (null !== $collectionKeyBuiltinType && !\call_user_func('is_'.$collectionKeyBuiltinType, $index)) { - throw new InvalidArgumentException(sprintf( - 'The type of the key "%s" must be "%s", "%s" given.', - $index, $collectionKeyBuiltinType, \gettype($index)) - ); + throw new InvalidArgumentException(sprintf('The type of the key "%s" must be "%s", "%s" given.', $index, $collectionKeyBuiltinType, \gettype($index))); } $values[$index] = $this->denormalizeRelation($attribute, $propertyMetadata, $className, $obj, $format, $this->createChildContext($context, $attribute, $format)); @@ -455,9 +442,7 @@ protected function denormalizeRelation(string $attributeName, PropertyMetadata $ if (!\is_array($value)) { if (!$supportsPlainIdentifiers) { - throw new UnexpectedValueException(sprintf( - 'Expected IRI or nested document for attribute "%s", "%s" given.', $attributeName, \gettype($value) - )); + throw new UnexpectedValueException(sprintf('Expected IRI or nested document for attribute "%s", "%s" given.', $attributeName, \gettype($value))); } $item = $this->itemDataProvider->getItem($className, $value, null, $context + ['fetch_data' => true]); diff --git a/src/Serializer/SerializerContextBuilder.php b/src/Serializer/SerializerContextBuilder.php index a38a69eaccd..6cab2e7265f 100644 --- a/src/Serializer/SerializerContextBuilder.php +++ b/src/Serializer/SerializerContextBuilder.php @@ -19,6 +19,7 @@ use ApiPlatform\Core\Swagger\Serializer\DocumentationNormalizer; use ApiPlatform\Core\Util\RequestAttributesExtractor; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Serializer\Encoder\CsvEncoder; /** * {@inheritdoc} @@ -60,8 +61,14 @@ public function createFromRequest(Request $request, bool $normalization, array $ $context['operation_type'] = $operationType; $context[$operationKey] = $attributes[$operationKey]; - if (!$normalization && !isset($context['api_allow_update'])) { - $context['api_allow_update'] = \in_array($request->getMethod(), ['PUT', 'PATCH'], true); + if (!$normalization) { + if (!isset($context['api_allow_update'])) { + $context['api_allow_update'] = \in_array($request->getMethod(), ['PUT', 'PATCH'], true); + } + + if ('csv' === $request->getContentType()) { + $context[CsvEncoder::AS_COLLECTION_KEY] = false; + } } $context['resource_class'] = $attributes['resource_class']; diff --git a/src/Validator/EventListener/ValidateListener.php b/src/Validator/EventListener/ValidateListener.php index ff1f00fd3eb..db7ded62613 100644 --- a/src/Validator/EventListener/ValidateListener.php +++ b/src/Validator/EventListener/ValidateListener.php @@ -19,7 +19,7 @@ use ApiPlatform\Core\Util\RequestAttributesExtractor; use ApiPlatform\Core\Validator\ValidatorInterface; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; /** * Validates data. @@ -46,14 +46,14 @@ public function __construct(ValidatorInterface $validator, ResourceMetadataFacto * * @throws ValidationException */ - public function onKernelView(GetResponseForControllerResultEvent $event): void + public function onKernelView(ViewEvent $event): void { $controllerResult = $event->getControllerResult(); $request = $event->getRequest(); if ( $controllerResult instanceof Response - || $request->isMethodSafe(false) + || $request->isMethodSafe() || $request->isMethod('DELETE') || !($attributes = RequestAttributesExtractor::extractAttributes($request)) || !$attributes['receive'] diff --git a/tests/Bridge/Doctrine/EventListener/WriteListenerTest.php b/tests/Bridge/Doctrine/EventListener/WriteListenerTest.php index c62a3445302..7071a6cdf5f 100644 --- a/tests/Bridge/Doctrine/EventListener/WriteListenerTest.php +++ b/tests/Bridge/Doctrine/EventListener/WriteListenerTest.php @@ -19,7 +19,7 @@ use Doctrine\Common\Persistence\ObjectManager; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; /** @@ -46,7 +46,7 @@ public function testOnKernelViewWithControllerResultAndPostMethod() $request = new Request(); $request->setMethod('POST'); $request->attributes->set('_api_resource_class', 'Dummy'); - $event = new GetResponseForControllerResultEvent($httpKernelProphecy->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, $dummy); + $event = new ViewEvent($httpKernelProphecy->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, $dummy); $writeListener->onKernelView($event); } @@ -69,7 +69,7 @@ public function testOnKernelViewWithControllerResultAndDeleteMethod() $request = new Request(); $request->setMethod('DELETE'); $request->attributes->set('_api_resource_class', 'Dummy'); - $eventProphecy = $this->prophesize(GetResponseForControllerResultEvent::class); + $eventProphecy = $this->prophesize(ViewEvent::class); $eventProphecy->setControllerResult(null)->shouldBeCalled(); $eventProphecy->getRequest()->willReturn($request); $eventProphecy->getControllerResult()->willReturn($dummy); @@ -95,7 +95,7 @@ public function testOnKernelViewWithSafeMethod() $request = new Request(); $request->setMethod('HEAD'); $request->attributes->set('_api_resource_class', 'Dummy'); - $event = new GetResponseForControllerResultEvent($httpKernelProphecy->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, $dummy); + $event = new ViewEvent($httpKernelProphecy->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, $dummy); $writeListener->onKernelView($event); } @@ -117,7 +117,7 @@ public function testOnKernelViewWithNoResourceClass() $httpKernelProphecy = $this->prophesize(HttpKernelInterface::class); $request = new Request(); $request->setMethod('POST'); - $event = new GetResponseForControllerResultEvent($httpKernelProphecy->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, $dummy); + $event = new ViewEvent($httpKernelProphecy->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, $dummy); $writeListener->onKernelView($event); } @@ -139,7 +139,7 @@ public function testOnKernelViewWithNoManager() $request = new Request(); $request->setMethod('DELETE'); $request->attributes->set('_api_resource_class', 'Dummy'); - $event = new GetResponseForControllerResultEvent($httpKernelProphecy->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, $dummy); + $event = new ViewEvent($httpKernelProphecy->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, $dummy); $writeListener->onKernelView($event); } diff --git a/tests/Bridge/FosUser/EventListenerTest.php b/tests/Bridge/FosUser/EventListenerTest.php index 796c6d2f13c..069a38fcc9e 100644 --- a/tests/Bridge/FosUser/EventListenerTest.php +++ b/tests/Bridge/FosUser/EventListenerTest.php @@ -19,7 +19,7 @@ use FOS\UserBundle\Model\UserManagerInterface; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; /** * @author Kévin Dunglas @@ -36,7 +36,7 @@ public function testDelete() $manager = $this->prophesize(UserManagerInterface::class); $manager->deleteUser($user)->shouldBeCalled(); - $event = $this->prophesize(GetResponseForControllerResultEvent::class); + $event = $this->prophesize(ViewEvent::class); $event->getControllerResult()->willReturn($user)->shouldBeCalled(); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->setControllerResult(null)->shouldBeCalled(); @@ -55,7 +55,7 @@ public function testUpdate() $manager = $this->prophesize(UserManagerInterface::class); $manager->updateUser($user)->shouldBeCalled(); - $event = $this->prophesize(GetResponseForControllerResultEvent::class); + $event = $this->prophesize(ViewEvent::class); $event->getControllerResult()->willReturn($user)->shouldBeCalled(); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->setControllerResult()->shouldNotBeCalled(); @@ -72,7 +72,7 @@ public function testNotApiRequest() $manager->deleteUser()->shouldNotBeCalled(); $manager->updateUser()->shouldNotBeCalled(); - $event = $this->prophesize(GetResponseForControllerResultEvent::class); + $event = $this->prophesize(ViewEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $listener = new EventListener($manager->reveal()); @@ -88,7 +88,7 @@ public function testNotUser() $manager->deleteUser()->shouldNotBeCalled(); $manager->updateUser()->shouldNotBeCalled(); - $event = $this->prophesize(GetResponseForControllerResultEvent::class); + $event = $this->prophesize(ViewEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->getControllerResult()->willReturn(new \stdClass()); @@ -104,7 +104,7 @@ public function testSafeMethod() $manager->deleteUser()->shouldNotBeCalled(); $manager->updateUser()->shouldNotBeCalled(); - $event = $this->prophesize(GetResponseForControllerResultEvent::class); + $event = $this->prophesize(ViewEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->getControllerResult()->willReturn(new User()); diff --git a/tests/Bridge/Symfony/Bundle/EventListener/SwaggerUiListenerTest.php b/tests/Bridge/Symfony/Bundle/EventListener/SwaggerUiListenerTest.php index 0b68f7b45c9..28c95a378f1 100644 --- a/tests/Bridge/Symfony/Bundle/EventListener/SwaggerUiListenerTest.php +++ b/tests/Bridge/Symfony/Bundle/EventListener/SwaggerUiListenerTest.php @@ -16,7 +16,7 @@ use ApiPlatform\Core\Bridge\Symfony\Bundle\EventListener\SwaggerUiListener; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; /** * @author Kévin Dunglas @@ -28,7 +28,7 @@ class SwaggerUiListenerTest extends TestCase */ public function testOnKernelRequest(Request $request, string $controller = null) { - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $listener = new SwaggerUiListener(); diff --git a/tests/Bridge/Symfony/Bundle/Twig/ApiPlatformProfilerPanelTest.php b/tests/Bridge/Symfony/Bundle/Twig/ApiPlatformProfilerPanelTest.php index bf6b7e199bc..28ed6dc624c 100644 --- a/tests/Bridge/Symfony/Bundle/Twig/ApiPlatformProfilerPanelTest.php +++ b/tests/Bridge/Symfony/Bundle/Twig/ApiPlatformProfilerPanelTest.php @@ -54,6 +54,8 @@ protected function setUp(): void $this->schemaTool->dropSchema($classes); $this->manager->clear(); $this->schemaTool->createSchema($classes); + + $this->ensureKernelShutdown(); } protected function tearDown(): void diff --git a/tests/Bridge/Symfony/Validator/EventListener/ValidateListenerTest.php b/tests/Bridge/Symfony/Validator/EventListener/ValidateListenerTest.php index 781116e84f7..d91d4c7b4f3 100644 --- a/tests/Bridge/Symfony/Validator/EventListener/ValidateListenerTest.php +++ b/tests/Bridge/Symfony/Validator/EventListener/ValidateListenerTest.php @@ -22,7 +22,7 @@ use Prophecy\Argument; use Psr\Container\ContainerInterface; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Validator\ConstraintViolationListInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; @@ -46,7 +46,7 @@ public function testNotAnApiPlatformRequest() $request = new Request(); $request->setMethod('POST'); - $event = $this->prophesize(GetResponseForControllerResultEvent::class); + $event = $this->prophesize(ViewEvent::class); $event->getRequest()->willReturn($request); $listener = new ValidateListener($validator, $resourceMetadataFactory); @@ -195,7 +195,7 @@ private function createEventObject($expectedValidationGroups, $data, bool $recei ]); $request->setMethod('POST'); - $event = new GetResponseForControllerResultEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $data); + $event = new ViewEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $data); return [$resourceMetadataFactory, $event]; } diff --git a/tests/Bridge/Symfony/Validator/EventListener/ValidationExceptionListenerTest.php b/tests/Bridge/Symfony/Validator/EventListener/ValidationExceptionListenerTest.php index 236eb56e69b..4d95e012500 100644 --- a/tests/Bridge/Symfony/Validator/EventListener/ValidationExceptionListenerTest.php +++ b/tests/Bridge/Symfony/Validator/EventListener/ValidationExceptionListenerTest.php @@ -19,7 +19,7 @@ use Prophecy\Argument; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\Validator\ConstraintViolationList; @@ -30,7 +30,7 @@ class ValidationExceptionListenerTest extends TestCase { public function testNotValidationException() { - $eventProphecy = $this->prophesize(GetResponseForExceptionEvent::class); + $eventProphecy = $this->prophesize(ExceptionEvent::class); $eventProphecy->getException()->willReturn(new \Exception())->shouldBeCalled(); $eventProphecy->setResponse()->shouldNotBeCalled(); @@ -45,7 +45,7 @@ public function testValidationException() $exceptionJson = '{"foo": "bar"}'; $list = new ConstraintViolationList([]); - $eventProphecy = $this->prophesize(GetResponseForExceptionEvent::class); + $eventProphecy = $this->prophesize(ExceptionEvent::class); $eventProphecy->getException()->willReturn(new ValidationException($list))->shouldBeCalled(); $eventProphecy->getRequest()->willReturn(new Request())->shouldBeCalled(); $eventProphecy->setResponse(Argument::allOf( diff --git a/tests/EventListener/AddFormatListenerTest.php b/tests/EventListener/AddFormatListenerTest.php index e3c0b636b57..3b618b9c2c5 100644 --- a/tests/EventListener/AddFormatListenerTest.php +++ b/tests/EventListener/AddFormatListenerTest.php @@ -21,7 +21,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -34,7 +34,7 @@ public function testNoResourceClass() { $request = new Request(); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request); $event = $eventProphecy->reveal(); @@ -73,7 +73,7 @@ private function doTestSupportedRequestFormat($resourceMetadataFactory): void $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get']); $request->setRequestFormat('xml'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request); $event = $eventProphecy->reveal(); @@ -89,7 +89,7 @@ public function testRespondFlag(): void $request = new Request([], [], ['_api_respond' => true]); $request->setRequestFormat('xml'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request); $event = $eventProphecy->reveal(); @@ -110,7 +110,7 @@ public function testUnsupportedRequestFormat(): void $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get']); $request->setRequestFormat('xml'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request); $event = $eventProphecy->reveal(); @@ -134,7 +134,7 @@ public function testSupportedAcceptHeader(): void $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get']); $request->headers->set('Accept', 'text/html, application/xhtml+xml, application/xml, application/json;q=0.9, */*;q=0.8'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request); $event = $eventProphecy->reveal(); @@ -161,7 +161,7 @@ public function testSupportedAcceptHeaderSymfonyBuiltInFormat(): void $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get']); $request->headers->set('Accept', 'application/json'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request); $event = $eventProphecy->reveal(); @@ -185,7 +185,7 @@ public function testAcceptAllHeader(): void $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get']); $request->headers->set('Accept', 'text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request); $event = $eventProphecy->reveal(); @@ -213,7 +213,7 @@ public function testUnsupportedAcceptHeader(): void $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get']); $request->headers->set('Accept', 'text/html, application/xhtml+xml, application/xml;q=0.9'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request); $event = $eventProphecy->reveal(); @@ -238,7 +238,7 @@ public function testUnsupportedAcceptHeaderSymfonyBuiltInFormat(): void $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get']); $request->headers->set('Accept', 'text/xml'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request); $event = $eventProphecy->reveal(); @@ -263,7 +263,7 @@ public function testInvalidAcceptHeader(): void $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get']); $request->headers->set('Accept', 'invalid'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request); $event = $eventProphecy->reveal(); @@ -286,7 +286,7 @@ public function testAcceptHeaderTakePrecedenceOverRequestFormat(): void $request->headers->set('Accept', 'application/json'); $request->setRequestFormat('xml'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request); $event = $eventProphecy->reveal(); @@ -312,7 +312,7 @@ public function testInvalidRouteFormat(): void $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get', '_format' => 'invalid']); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request); $event = $eventProphecy->reveal(); @@ -335,7 +335,7 @@ public function testResourceClassSupportedRequestFormat(): void $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get']); $request->setRequestFormat('csv'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $event = $eventProphecy->reveal(); diff --git a/tests/EventListener/DeserializeListenerTest.php b/tests/EventListener/DeserializeListenerTest.php index 74b1c3421d5..25b4e3b5507 100644 --- a/tests/EventListener/DeserializeListenerTest.php +++ b/tests/EventListener/DeserializeListenerTest.php @@ -22,7 +22,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\SerializerInterface; @@ -36,7 +36,7 @@ class DeserializeListenerTest extends TestCase public function testDoNotCallWhenRequestMethodIsSafe(): void { - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $request = new Request([], [], ['data' => new \stdClass()]); $request->setMethod('GET'); @@ -57,7 +57,7 @@ public function testDoNotCallWhenRequestMethodIsSafe(): void public function testDoNotCallWhenRequestNotManaged(): void { - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $request = new Request([], [], ['data' => new \stdClass()], [], [], [], '{}'); $request->setMethod('POST'); @@ -89,7 +89,7 @@ public function testDoNotDeserializeWhenReceiveFlagIsFalse(): void $request = new Request([], [], ['data' => new Dummy(), '_api_resource_class' => Dummy::class, '_api_collection_operation_name' => 'post', '_api_receive' => false]); $request->setMethod('POST'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request); $listener = new DeserializeListener($serializerProphecy->reveal(), $serializerContextBuilderProphecy->reveal(), $resourceMetadataFactoryProphecy->reveal()); @@ -115,7 +115,7 @@ public function testDoNotDeserializeWhenDisabledInOperationAttribute(): void $request = new Request([], [], ['data' => new Dummy(), '_api_resource_class' => Dummy::class, '_api_collection_operation_name' => 'post']); $request->setMethod('POST'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request); $listener = new DeserializeListener($serializerProphecy->reveal(), $serializerContextBuilderProphecy->reveal(), $resourceMetadataFactoryProphecy->reveal()); @@ -153,7 +153,7 @@ public function legacyTestDeserialize(string $method, bool $populateObject): voi private function doTestDeserialize(string $method, bool $populateObject, $resourceMetadataFactory): void { $result = $populateObject ? new \stdClass() : null; - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $request = new Request([], [], ['data' => $result, '_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'post'], [], [], [], '{}'); $request->setMethod($method); @@ -211,7 +211,7 @@ public function testLegacyDeserializeResourceClassSupportedFormat(string $method private function doTestDeserializeResourceClassSupportedFormat(string $method, bool $populateObject, $resourceMetadataFactory): void { $result = $populateObject ? new \stdClass() : null; - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $request = new Request([], [], ['data' => $result, '_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'post'], [], [], [], '{}'); $request->setMethod($method); @@ -263,7 +263,7 @@ public function testLegacyContentNegotiation(): void private function doTestContentNegotiation($resourceMetadataFactory): void { - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'post'], [], [], [], '{}'); $request->setMethod('POST'); @@ -292,7 +292,7 @@ public function testNotSupportedContentType(): void $this->expectException(UnsupportedMediaTypeHttpException::class); $this->expectExceptionMessage('The content-type "application/rdf+xml" is not supported. Supported MIME types are "application/ld+json", "text/xml".'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'post'], [], [], [], '{}'); $request->setMethod('POST'); @@ -328,7 +328,7 @@ public function testNoContentType(): void $this->expectException(UnsupportedMediaTypeHttpException::class); $this->expectExceptionMessage('The "Content-Type" header must exist.'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'post'], [], [], [], '{}'); $request->setMethod('POST'); diff --git a/tests/EventListener/ExceptionListenerTest.php b/tests/EventListener/ExceptionListenerTest.php index 3862d9caf2d..82b2afd19f7 100644 --- a/tests/EventListener/ExceptionListenerTest.php +++ b/tests/EventListener/ExceptionListenerTest.php @@ -18,7 +18,7 @@ use Prophecy\Argument; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; /** @@ -34,7 +34,7 @@ public function testOnKernelException(Request $request) $kernel = $this->prophesize(HttpKernelInterface::class); $kernel->handle(Argument::type(Request::class), HttpKernelInterface::SUB_REQUEST, false)->willReturn(new Response())->shouldBeCalled(); - $eventProphecy = $this->prophesize(GetResponseForExceptionEvent::class); + $eventProphecy = $this->prophesize(ExceptionEvent::class); $eventProphecy->getRequest()->willReturn($request); $eventProphecy->getException()->willReturn(new \Exception()); $eventProphecy->getKernel()->willReturn($kernel); @@ -54,7 +54,7 @@ public function getRequest() public function testDoNothingWhenNotAnApiCall() { - $eventProphecy = $this->prophesize(GetResponseForExceptionEvent::class); + $eventProphecy = $this->prophesize(ExceptionEvent::class); $eventProphecy->getRequest()->willReturn(new Request()); $eventProphecy->setResponse(Argument::type(Response::class))->shouldNotBeCalled(); @@ -67,7 +67,7 @@ public function testDoNothingWhenHtmlRequested() $request = new Request([], [], ['_api_respond' => true]); $request->setRequestFormat('html'); - $eventProphecy = $this->prophesize(GetResponseForExceptionEvent::class); + $eventProphecy = $this->prophesize(ExceptionEvent::class); $eventProphecy->getRequest()->willReturn($request); $eventProphecy->setResponse(Argument::type(Response::class))->shouldNotBeCalled(); diff --git a/tests/EventListener/ReadListenerTest.php b/tests/EventListener/ReadListenerTest.php index a659313df03..b2b29e16441 100644 --- a/tests/EventListener/ReadListenerTest.php +++ b/tests/EventListener/ReadListenerTest.php @@ -26,7 +26,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** @@ -47,7 +47,7 @@ public function testNotAnApiPlatformRequest() $subresourceDataProvider = $this->prophesize(SubresourceDataProviderInterface::class); $subresourceDataProvider->getSubresource()->shouldNotBeCalled(); - $event = $this->prophesize(GetResponseEvent::class); + $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn(new Request())->shouldBeCalled(); $listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal(), $subresourceDataProvider->reveal(), null, $identifierConverter->reveal()); @@ -68,7 +68,7 @@ public function testLegacyConstructor() $subresourceDataProvider = $this->prophesize(SubresourceDataProviderInterface::class); $subresourceDataProvider->getSubresource()->shouldNotBeCalled(); - $event = $this->prophesize(GetResponseEvent::class); + $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn(new Request())->shouldBeCalled(); $listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal(), $subresourceDataProvider->reveal()); @@ -91,7 +91,7 @@ public function testDoNotReadWhenReceiveFlagIsFalse() $request = new Request([], [], ['id' => 1, 'data' => new Dummy(), '_api_resource_class' => Dummy::class, '_api_item_operation_name' => 'put', '_api_receive' => false]); $request->setMethod('PUT'); - $event = $this->prophesize(GetResponseEvent::class); + $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request); $listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal(), $subresourceDataProvider->reveal(), null, $identifierConverter->reveal()); @@ -123,7 +123,7 @@ public function testDoNotReadWhenDisabledInOperationAttribute() $request = new Request([], [], ['id' => 1, 'data' => new Dummy(), '_api_resource_class' => Dummy::class, '_api_item_operation_name' => 'put']); $request->setMethod('PUT'); - $event = $this->prophesize(GetResponseEvent::class); + $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request); $listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal(), $subresourceDataProvider->reveal(), null, $identifierConverter->reveal(), $resourceMetadataFactoryProphecy->reveal()); @@ -146,7 +146,7 @@ public function testRetrieveCollectionPost() $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'post', '_api_format' => 'json', '_api_mime_type' => 'application/json'], [], [], [], '{}'); $request->setMethod('POST'); - $event = $this->prophesize(GetResponseEvent::class); + $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request); $listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal(), $subresourceDataProvider->reveal(), null, $identifierConverter->reveal()); @@ -172,7 +172,7 @@ public function testRetrieveCollectionGet() $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get', '_api_format' => 'json', '_api_mime_type' => 'application/json'], [], [], ['QUERY_STRING' => 'foo=bar']); $request->setMethod('GET'); - $event = $this->prophesize(GetResponseEvent::class); + $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal(), $subresourceDataProvider->reveal(), null, $identifierConverter->reveal()); @@ -200,7 +200,7 @@ public function testRetrieveItem() $request = new Request([], [], ['id' => 1, '_api_resource_class' => 'Foo', '_api_item_operation_name' => 'get', '_api_format' => 'json', '_api_mime_type' => 'application/json']); $request->setMethod('GET'); - $event = $this->prophesize(GetResponseEvent::class); + $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal(), $subresourceDataProvider->reveal(), null, $identifierConverter->reveal()); @@ -226,7 +226,7 @@ public function testRetrieveItemNoIdentifier() $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_item_operation_name' => 'get', '_api_format' => 'json', '_api_mime_type' => 'application/json']); $request->setMethod('GET'); - $event = $this->prophesize(GetResponseEvent::class); + $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal(), $subresourceDataProvider->reveal()); @@ -253,7 +253,7 @@ public function testRetrieveSubresource() $request = new Request([], [], ['id' => 1, '_api_resource_class' => 'Foo', '_api_subresource_operation_name' => 'get', '_api_format' => 'json', '_api_mime_type' => 'application/json', '_api_subresource_context' => ['identifiers' => [['id', 'Bar', true]], 'property' => 'bar']]); $request->setMethod('GET'); - $event = $this->prophesize(GetResponseEvent::class); + $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal(), $subresourceDataProvider->reveal(), null, $identifierConverter->reveal()); @@ -276,7 +276,7 @@ public function testRetrieveSubresourceNoDataProvider() $request = new Request([], [], ['id' => 1, '_api_resource_class' => 'Foo', '_api_subresource_operation_name' => 'get', '_api_format' => 'json', '_api_mime_type' => 'application/json', '_api_subresource_context' => ['identifiers' => [['id', 'Bar', true]], 'property' => 'bar']]); $request->setMethod('GET'); - $event = $this->prophesize(GetResponseEvent::class); + $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal()); @@ -300,7 +300,7 @@ public function testRetrieveSubresourceNotFound() $request = new Request([], [], ['id' => 1, '_api_resource_class' => 'Foo', '_api_subresource_operation_name' => 'get', '_api_format' => 'json', '_api_mime_type' => 'application/json', '_api_subresource_context' => ['identifiers' => [['id', 'Bar', true]], 'property' => 'bar']]); $request->setMethod('GET'); - $event = $this->prophesize(GetResponseEvent::class); + $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal(), $this->prophesize(SubresourceDataProviderInterface::class)->reveal(), null, $identifierConverter->reveal()); @@ -323,7 +323,7 @@ public function testRetrieveItemNotFound() $request = new Request([], [], ['id' => 22, '_api_resource_class' => 'Foo', '_api_item_operation_name' => 'get', '_api_format' => 'json', '_api_mime_type' => 'application/json']); $request->setMethod('GET'); - $event = $this->prophesize(GetResponseEvent::class); + $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal(), $subresourceDataProvider->reveal(), null, $identifierConverter->reveal()); @@ -344,7 +344,7 @@ public function testRetrieveBadItemNormalizedIdentifiers() $request = new Request([], [], ['id' => 1, '_api_resource_class' => 'Foo', '_api_item_operation_name' => 'get', '_api_format' => 'json', '_api_mime_type' => 'application/json']); $request->setMethod(Request::METHOD_GET); - $event = $this->prophesize(GetResponseEvent::class); + $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal(), $subresourceDataProvider->reveal(), null, $identifierConverter->reveal()); @@ -370,7 +370,7 @@ public function testRetrieveBadSubresourceNormalizedIdentifiers() $request = new Request([], [], ['id' => 1, '_api_resource_class' => 'Foo', '_api_subresource_operation_name' => 'get', '_api_format' => 'json', '_api_mime_type' => 'application/json', '_api_subresource_context' => ['identifiers' => [['id', 'Bar', true]], 'property' => 'bar']]); $request->setMethod(Request::METHOD_GET); - $event = $this->prophesize(GetResponseEvent::class); + $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal(), $subresourceDataProvider->reveal(), null, $identifierConverter->reveal()); diff --git a/tests/EventListener/RespondListenerTest.php b/tests/EventListener/RespondListenerTest.php index 04d73a262ec..b4abfc256eb 100644 --- a/tests/EventListener/RespondListenerTest.php +++ b/tests/EventListener/RespondListenerTest.php @@ -21,7 +21,7 @@ use Prophecy\Argument; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; /** @@ -33,7 +33,7 @@ public function testDoNotHandleResponse() { $request = new Request(); - $eventProphecy = $this->prophesize(GetResponseForControllerResultEvent::class); + $eventProphecy = $this->prophesize(ViewEvent::class); $eventProphecy->getControllerResult()->willReturn(new Response()); $eventProphecy->getRequest()->willReturn($request); $eventProphecy->setResponse(Argument::any())->shouldNotBeCalled(); @@ -46,7 +46,7 @@ public function testDoNotHandleWhenRespondFlagIsFalse() { $request = new Request([], [], ['_api_respond' => false]); - $eventProphecy = $this->prophesize(GetResponseForControllerResultEvent::class); + $eventProphecy = $this->prophesize(ViewEvent::class); $eventProphecy->getControllerResult()->willReturn('foo'); $eventProphecy->getRequest()->willReturn($request); $eventProphecy->setResponse(Argument::any())->shouldNotBeCalled(); @@ -61,7 +61,7 @@ public function testCreate200Response() $request->setRequestFormat('xml'); $kernelProphecy = $this->prophesize(HttpKernelInterface::class); - $event = new GetResponseForControllerResultEvent( + $event = new ViewEvent( $kernelProphecy->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, @@ -88,7 +88,7 @@ public function testCreate201Response() $request->setMethod('POST'); $request->setRequestFormat('xml'); - $event = new GetResponseForControllerResultEvent( + $event = new ViewEvent( $kernelProphecy->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, @@ -117,7 +117,7 @@ public function testCreate204Response() $request->setRequestFormat('xml'); $request->setMethod('DELETE'); - $event = new GetResponseForControllerResultEvent( + $event = new ViewEvent( $kernelProphecy->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, @@ -142,7 +142,7 @@ public function testSetSunsetHeader() $request = new Request([], [], ['_api_resource_class' => Dummy::class, '_api_item_operation_name' => 'get', '_api_respond' => true]); - $event = new GetResponseForControllerResultEvent( + $event = new ViewEvent( $kernelProphecy->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, @@ -166,7 +166,7 @@ public function testSetCustomStatus() $request = new Request([], [], ['_api_resource_class' => Dummy::class, '_api_item_operation_name' => 'get', '_api_respond' => true]); - $event = new GetResponseForControllerResultEvent( + $event = new ViewEvent( $kernelProphecy->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, @@ -185,7 +185,7 @@ public function testHandleResponse() { $request = new Request([], [], ['_api_resource_class' => Dummy::class, '_api_item_operation_name' => 'get', '_api_respond' => true]); $response = new Response(); - $eventProphecy = $this->prophesize(GetResponseForControllerResultEvent::class); + $eventProphecy = $this->prophesize(ViewEvent::class); $eventProphecy->getControllerResult()->willReturn($response); $eventProphecy->getRequest()->willReturn($request); $eventProphecy->setResponse($response)->shouldBeCalled(); diff --git a/tests/EventListener/SerializeListenerTest.php b/tests/EventListener/SerializeListenerTest.php index 8c1c163f263..55a0eac090c 100644 --- a/tests/EventListener/SerializeListenerTest.php +++ b/tests/EventListener/SerializeListenerTest.php @@ -23,7 +23,7 @@ use Prophecy\Argument; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; use Symfony\Component\Serializer\Encoder\EncoderInterface; use Symfony\Component\Serializer\SerializerInterface; @@ -39,7 +39,7 @@ public function testDoNotSerializeWhenControllerResultIsResponse() $request = new Request(); - $eventProphecy = $this->prophesize(GetResponseForControllerResultEvent::class); + $eventProphecy = $this->prophesize(ViewEvent::class); $eventProphecy->getControllerResult()->willReturn(new Response()); $eventProphecy->getRequest()->willReturn($request); @@ -62,7 +62,7 @@ public function testDoNotSerializeWhenRespondFlagIsFalse() $request = new Request([], [], ['data' => $dummy, '_api_resource_class' => Dummy::class, '_api_collection_operation_name' => 'post', '_api_respond' => false]); $request->setMethod('POST'); - $eventProphecy = $this->prophesize(GetResponseForControllerResultEvent::class); + $eventProphecy = $this->prophesize(ViewEvent::class); $eventProphecy->getControllerResult()->willReturn($dummy); $eventProphecy->getRequest()->willReturn($request); $eventProphecy->setControllerResult(Argument::any())->shouldNotBeCalled(); @@ -92,7 +92,7 @@ public function testDoNotSerializeWhenDisabledInOperationAttribute() $request = new Request([], [], ['data' => $dummy, '_api_resource_class' => Dummy::class, '_api_collection_operation_name' => 'post']); $request->setMethod('POST'); - $eventProphecy = $this->prophesize(GetResponseForControllerResultEvent::class); + $eventProphecy = $this->prophesize(ViewEvent::class); $eventProphecy->getControllerResult()->willReturn($dummy); $eventProphecy->getRequest()->willReturn($request); $eventProphecy->setControllerResult(Argument::any())->shouldNotBeCalled(); @@ -125,7 +125,7 @@ public function testSerializeCollectionOperation() $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get']); $request->setRequestFormat('xml'); - $eventProphecy = $this->prophesize(GetResponseForControllerResultEvent::class); + $eventProphecy = $this->prophesize(ViewEvent::class); $eventProphecy->getControllerResult()->willReturn(new \stdClass())->shouldBeCalled(); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $eventProphecy->setControllerResult('bar')->shouldBeCalled(); @@ -145,7 +145,7 @@ public function testSerializeCollectionOperationWithOutputClassDisabled() $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get', '_api_output_class' => false]); $request->setRequestFormat('xml'); - $eventProphecy = $this->prophesize(GetResponseForControllerResultEvent::class); + $eventProphecy = $this->prophesize(ViewEvent::class); $eventProphecy->getControllerResult()->willReturn(new \stdClass()); $eventProphecy->getRequest()->willReturn($request); $eventProphecy->setControllerResult(null)->shouldBeCalled(); @@ -180,7 +180,7 @@ public function testSerializeItemOperation() $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_item_operation_name' => 'get']); $request->setRequestFormat('xml'); - $eventProphecy = $this->prophesize(GetResponseForControllerResultEvent::class); + $eventProphecy = $this->prophesize(ViewEvent::class); $eventProphecy->getControllerResult()->willReturn(new \stdClass())->shouldBeCalled(); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $eventProphecy->setControllerResult('bar')->shouldBeCalled(); @@ -202,7 +202,7 @@ public function testEncode() $request = new Request([], [], ['_api_respond' => true]); $request->setRequestFormat('xml'); - $eventProphecy = $this->prophesize(GetResponseForControllerResultEvent::class); + $eventProphecy = $this->prophesize(ViewEvent::class); $eventProphecy->getControllerResult()->willReturn([])->shouldBeCalled(); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $eventProphecy->setControllerResult('bar')->shouldBeCalled(); diff --git a/tests/EventListener/WriteListenerTest.php b/tests/EventListener/WriteListenerTest.php index 911d3768b59..ce3aa4bab5c 100644 --- a/tests/EventListener/WriteListenerTest.php +++ b/tests/EventListener/WriteListenerTest.php @@ -24,7 +24,7 @@ use Prophecy\Argument; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; /** @@ -46,7 +46,7 @@ public function testOnKernelViewWithControllerResultAndPersist() $request = new Request([], [], ['_api_resource_class' => Dummy::class]); - $event = new GetResponseForControllerResultEvent( + $event = new ViewEvent( $this->prophesize(HttpKernelInterface::class)->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, @@ -78,7 +78,7 @@ public function testOnKernelViewWithControllerResultAndPersistReturningVoid() $request = new Request([], [], ['_api_resource_class' => Dummy::class]); - $event = new GetResponseForControllerResultEvent( + $event = new ViewEvent( $this->prophesize(HttpKernelInterface::class)->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, @@ -119,7 +119,7 @@ public function testOnKernelViewWithControllerResultAndPersistWithImmutableResou $request = new Request([], [], ['_api_resource_class' => Dummy::class]); foreach (['PATCH', 'PUT', 'POST'] as $httpMethod) { - $event = new GetResponseForControllerResultEvent( + $event = new ViewEvent( $this->prophesize(HttpKernelInterface::class)->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, @@ -155,7 +155,7 @@ public function testOnKernelViewDoNotCallIriConverterWhenOutputClassDisabled() $request = new Request([], [], ['_api_resource_class' => Dummy::class, '_api_collection_operation_name' => 'post']); $request->setMethod('POST'); - $event = new GetResponseForControllerResultEvent( + $event = new ViewEvent( $this->prophesize(HttpKernelInterface::class)->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, @@ -180,7 +180,7 @@ public function testOnKernelViewWithControllerResultAndRemove() $request = new Request([], [], ['_api_resource_class' => Dummy::class, '_api_item_operation_name' => 'delete']); $request->setMethod('DELETE'); - $event = new GetResponseForControllerResultEvent( + $event = new ViewEvent( $this->prophesize(HttpKernelInterface::class)->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, @@ -206,7 +206,7 @@ public function testOnKernelViewWithSafeMethod() $request = new Request([], [], ['_api_resource_class' => Dummy::class, '_api_item_operation_name' => 'head']); $request->setMethod('HEAD'); - $event = new GetResponseForControllerResultEvent( + $event = new ViewEvent( $this->prophesize(HttpKernelInterface::class)->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, @@ -229,7 +229,7 @@ public function testDoNotWriteWhenControllerResultIsResponse() $response = new Response(); - $event = new GetResponseForControllerResultEvent( + $event = new ViewEvent( $this->prophesize(HttpKernelInterface::class)->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, @@ -255,7 +255,7 @@ public function testDoNotWriteWhenPersistFlagIsFalse() $request = new Request([], [], ['data' => new Dummy(), '_api_resource_class' => Dummy::class, '_api_collection_operation_name' => 'post', '_api_persist' => false]); $request->setMethod('POST'); - $event = new GetResponseForControllerResultEvent( + $event = new ViewEvent( $this->prophesize(HttpKernelInterface::class)->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, @@ -290,7 +290,7 @@ public function testDoNotWriteWhenDisabledInOperationAttribute() $request = new Request([], [], ['data' => new Dummy(), '_api_resource_class' => Dummy::class, '_api_collection_operation_name' => 'post']); $request->setMethod('POST'); - $event = new GetResponseForControllerResultEvent( + $event = new ViewEvent( $this->prophesize(HttpKernelInterface::class)->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, @@ -317,7 +317,7 @@ public function testOnKernelViewWithNoResourceClass() $request = new Request(); $request->setMethod('POST'); - $event = new GetResponseForControllerResultEvent( + $event = new ViewEvent( $this->prophesize(HttpKernelInterface::class)->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, @@ -341,7 +341,7 @@ public function testOnKernelViewWithParentResourceClass() $request = new Request([], [], ['_api_resource_class' => ConcreteDummy::class, '_api_item_operation_name' => 'put', '_api_persist' => true]); $request->setMethod('PUT'); - $event = new GetResponseForControllerResultEvent( + $event = new ViewEvent( $this->prophesize(HttpKernelInterface::class)->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, @@ -367,7 +367,7 @@ public function testOnKernelViewWithNoDataPersisterSupport() $request = new Request([], [], ['_api_resource_class' => 'Dummy', '_api_collection_operation_name' => 'post']); $request->setMethod('POST'); - $event = new GetResponseForControllerResultEvent( + $event = new ViewEvent( $this->prophesize(HttpKernelInterface::class)->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, diff --git a/tests/Filter/QueryParameterValidateListenerTest.php b/tests/Filter/QueryParameterValidateListenerTest.php index dea8db68290..47e6efacfb2 100644 --- a/tests/Filter/QueryParameterValidateListenerTest.php +++ b/tests/Filter/QueryParameterValidateListenerTest.php @@ -22,7 +22,7 @@ use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; class QueryParameterValidateListenerTest extends TestCase { @@ -39,7 +39,7 @@ public function testOnKernelRequestWithUnsafeMethod() $request = new Request(); $request->setMethod('POST'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $this->assertNull( @@ -57,7 +57,7 @@ public function testOnKernelRequestWithWrongFilter() $request = new Request([], [], ['_api_resource_class' => Dummy::class, '_api_collection_operation_name' => 'get']); $request->setMethod('GET'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $this->filterLocatorProphecy->has('some_inexistent_filter')->shouldBeCalled(); @@ -78,7 +78,7 @@ public function testOnKernelRequestWithRequiredFilterNotSet() $request = new Request([], [], ['_api_resource_class' => Dummy::class, '_api_collection_operation_name' => 'get']); $request->setMethod('GET'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $this->filterLocatorProphecy @@ -118,7 +118,7 @@ public function testOnKernelRequestWithRequiredFilter() ); $request->setMethod('GET'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $this->filterLocatorProphecy diff --git a/tests/Fixtures/app/AppKernel.php b/tests/Fixtures/app/AppKernel.php index 91ba2ba57d1..bc4d14d590d 100644 --- a/tests/Fixtures/app/AppKernel.php +++ b/tests/Fixtures/app/AppKernel.php @@ -27,6 +27,7 @@ use Symfony\Bundle\WebProfilerBundle\WebProfilerBundle; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\ErrorRenderer\ErrorRenderer; use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Routing\RouteCollectionBuilder; use Symfony\Component\Security\Core\Encoder\SodiumPasswordEncoder; @@ -84,7 +85,7 @@ public function getProjectDir() protected function configureRoutes(RouteCollectionBuilder $routes) { - $routes->import("config/routing_{$this->getEnvironment()}.yml"); + $routes->import(__DIR__."/config/routing_{$this->getEnvironment()}.yml"); if ($_SERVER['LEGACY'] ?? true) { $routes->import('@NelmioApiDocBundle/Resources/config/routing.yml', '/nelmioapidoc'); @@ -130,6 +131,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load 'provider' => 'chain_provider', 'http_basic' => null, 'anonymous' => null, + 'stateless' => true, ], ], 'access_control' => [ @@ -152,6 +154,12 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load ]); } + $twigConfig = ['strict_variables' => '%kernel.debug%']; + if (class_exists(ErrorRenderer::class)) { + $twigConfig['exception_controller'] = null; + } + $c->prependExtensionConfig('twig', $twigConfig); + if ($_SERVER['LEGACY'] ?? true) { $c->prependExtensionConfig('nelmio_api_doc', [ 'sandbox' => [ diff --git a/tests/Fixtures/app/config/config_common.yml b/tests/Fixtures/app/config/config_common.yml index ecf6a1894cc..e4c861cbb4a 100644 --- a/tests/Fixtures/app/config/config_common.yml +++ b/tests/Fixtures/app/config/config_common.yml @@ -28,9 +28,6 @@ doctrine: auto_generate_proxy_classes: '%kernel.debug%' auto_mapping: true -twig: - strict_variables: '%kernel.debug%' - mercure: hubs: default: diff --git a/tests/HttpCache/EventListener/AddHeadersListenerTest.php b/tests/HttpCache/EventListener/AddHeadersListenerTest.php index bf96745e3ee..2e5e2af634a 100644 --- a/tests/HttpCache/EventListener/AddHeadersListenerTest.php +++ b/tests/HttpCache/EventListener/AddHeadersListenerTest.php @@ -20,7 +20,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; /** * @author Kévin Dunglas @@ -34,7 +34,7 @@ public function testDoNotSetHeaderWhenMethodNotCacheable() $response = new Response(); - $event = $this->prophesize(FilterResponseEvent::class); + $event = $this->prophesize(ResponseEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->getResponse()->willReturn($response)->shouldNotBeCalled(); @@ -50,7 +50,7 @@ public function testDoNotSetHeaderOnUnsuccessfulResponse() $response = new Response('{}', Response::HTTP_BAD_REQUEST); - $event = $this->prophesize(FilterResponseEvent::class); + $event = $this->prophesize(ResponseEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->getResponse()->willReturn($response)->shouldBeCalled(); @@ -65,7 +65,7 @@ public function testDoNotSetHeaderWhenNotAnApiOperation() $request = new Request(); $response = new Response(); - $event = $this->prophesize(FilterResponseEvent::class); + $event = $this->prophesize(ResponseEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->getResponse()->willReturn($response)->shouldNotBeCalled(); @@ -80,7 +80,7 @@ public function testDoNotSetHeaderWhenNoContent() $request = new Request([], [], ['_api_resource_class' => Dummy::class, '_api_item_operation_name' => 'get']); $response = new Response(); - $event = $this->prophesize(FilterResponseEvent::class); + $event = $this->prophesize(ResponseEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->getResponse()->willReturn($response)->shouldBeCalled(); @@ -95,7 +95,7 @@ public function testAddHeaders() $request = new Request([], [], ['_api_resource_class' => Dummy::class, '_api_item_operation_name' => 'get']); $response = new Response('some content', 200, ['Vary' => ['Accept', 'Cookie']]); - $event = $this->prophesize(FilterResponseEvent::class); + $event = $this->prophesize(ResponseEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->getResponse()->willReturn($response)->shouldBeCalled(); @@ -119,7 +119,7 @@ public function testDoNotSetHeaderWhenAlreadySet() // This also calls setPublic $response->setSharedMaxAge(400); - $event = $this->prophesize(FilterResponseEvent::class); + $event = $this->prophesize(ResponseEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->getResponse()->willReturn($response)->shouldBeCalled(); @@ -139,7 +139,7 @@ public function testSetHeadersFromResourceMetadata() $request = new Request([], [], ['_api_resource_class' => Dummy::class, '_api_item_operation_name' => 'get']); $response = new Response('some content', 200, ['Vary' => ['Accept', 'Cookie']]); - $event = $this->prophesize(FilterResponseEvent::class); + $event = $this->prophesize(ResponseEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->getResponse()->willReturn($response)->shouldBeCalled(); diff --git a/tests/HttpCache/EventListener/AddTagsListenerTest.php b/tests/HttpCache/EventListener/AddTagsListenerTest.php index 38472567322..8a88a43231f 100644 --- a/tests/HttpCache/EventListener/AddTagsListenerTest.php +++ b/tests/HttpCache/EventListener/AddTagsListenerTest.php @@ -19,7 +19,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; /** * @author Kévin Dunglas @@ -37,7 +37,7 @@ public function testDoNotSetHeaderWhenMethodNotCacheable() $response->setPublic(); $response->setEtag('foo'); - $event = $this->prophesize(FilterResponseEvent::class); + $event = $this->prophesize(ResponseEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->getResponse()->willReturn($response)->shouldBeCalled(); @@ -55,7 +55,7 @@ public function testDoNotSetHeaderWhenResponseNotCacheable() $response = new Response(); - $event = $this->prophesize(FilterResponseEvent::class); + $event = $this->prophesize(ResponseEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->getResponse()->willReturn($response)->shouldBeCalled(); @@ -75,7 +75,7 @@ public function testDoNotSetHeaderWhenNotAnApiOperation() $response->setPublic(); $response->setEtag('foo'); - $event = $this->prophesize(FilterResponseEvent::class); + $event = $this->prophesize(ResponseEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->getResponse()->willReturn($response)->shouldBeCalled(); @@ -95,7 +95,7 @@ public function testDoNotSetHeaderWhenEmptyTagList() $response->setPublic(); $response->setEtag('foo'); - $event = $this->prophesize(FilterResponseEvent::class); + $event = $this->prophesize(ResponseEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->getResponse()->willReturn($response)->shouldBeCalled(); @@ -115,7 +115,7 @@ public function testAddTags() $response->setPublic(); $response->setEtag('foo'); - $event = $this->prophesize(FilterResponseEvent::class); + $event = $this->prophesize(ResponseEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->getResponse()->willReturn($response)->shouldBeCalled(); @@ -136,7 +136,7 @@ public function testAddCollectionIri() $response->setPublic(); $response->setEtag('foo'); - $event = $this->prophesize(FilterResponseEvent::class); + $event = $this->prophesize(ResponseEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->getResponse()->willReturn($response)->shouldBeCalled(); @@ -157,7 +157,7 @@ public function testAddCollectionIriWhenCollectionIsEmpty() $response->setPublic(); $response->setEtag('foo'); - $event = $this->prophesize(FilterResponseEvent::class); + $event = $this->prophesize(ResponseEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->getResponse()->willReturn($response)->shouldBeCalled(); @@ -178,7 +178,7 @@ public function testAddSubResourceCollectionIri() $response->setPublic(); $response->setEtag('foo'); - $event = $this->prophesize(FilterResponseEvent::class); + $event = $this->prophesize(ResponseEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $event->getResponse()->willReturn($response)->shouldBeCalled(); diff --git a/tests/Hydra/EventListener/AddLinkHeaderListenerTest.php b/tests/Hydra/EventListener/AddLinkHeaderListenerTest.php index 4e9c4226cd4..193c5842bcf 100644 --- a/tests/Hydra/EventListener/AddLinkHeaderListenerTest.php +++ b/tests/Hydra/EventListener/AddLinkHeaderListenerTest.php @@ -19,7 +19,7 @@ use Fig\Link\Link; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\WebLink\HttpHeaderSerializer; /** @@ -35,7 +35,7 @@ public function testAddLinkHeader(string $expected, Request $request) $urlGenerator = $this->prophesize(UrlGeneratorInterface::class); $urlGenerator->generate('api_doc', ['_format' => 'jsonld'], UrlGeneratorInterface::ABS_URL)->willReturn('http://example.com/docs')->shouldBeCalled(); - $event = $this->prophesize(FilterResponseEvent::class); + $event = $this->prophesize(ResponseEvent::class); $event->getRequest()->willReturn($request)->shouldBeCalled(); $listener = new AddLinkHeaderListener($urlGenerator->reveal()); diff --git a/tests/JsonApi/EventListener/TransformFieldsetsParametersListenerTest.php b/tests/JsonApi/EventListener/TransformFieldsetsParametersListenerTest.php index 9e2d7133710..849af299d43 100644 --- a/tests/JsonApi/EventListener/TransformFieldsetsParametersListenerTest.php +++ b/tests/JsonApi/EventListener/TransformFieldsetsParametersListenerTest.php @@ -19,7 +19,7 @@ use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; class TransformFieldsetsParametersListenerTest extends TestCase { @@ -40,7 +40,7 @@ public function testOnKernelRequestWithInvalidFormat() $request = $expectedRequest->duplicate(); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $this->listener->onKernelRequest($eventProphecy->reveal()); @@ -50,7 +50,7 @@ public function testOnKernelRequestWithInvalidFormat() public function testOnKernelRequestWithInvalidFilter() { - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $expectedRequest = new Request(); $expectedRequest->setRequestFormat('jsonapi'); @@ -79,7 +79,7 @@ public function testOnKernelRequest() ); $request->setRequestFormat('jsonapi'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $this->listener->onKernelRequest($eventProphecy->reveal()); @@ -107,7 +107,7 @@ public function testOnKernelRequestWithIncludeWithoutFields() ); $request->setRequestFormat('jsonapi'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $this->listener->onKernelRequest($eventProphecy->reveal()); @@ -134,7 +134,7 @@ public function testOnKernelRequestWithWrongParametersTypesDoesnTAffectRequestAt ); $request->setRequestFormat('jsonapi'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $this->listener->onKernelRequest($eventProphecy->reveal()); diff --git a/tests/JsonApi/EventListener/TransformFilteringParametersListenerTest.php b/tests/JsonApi/EventListener/TransformFilteringParametersListenerTest.php index 6420cf5e005..551362561ff 100644 --- a/tests/JsonApi/EventListener/TransformFilteringParametersListenerTest.php +++ b/tests/JsonApi/EventListener/TransformFilteringParametersListenerTest.php @@ -16,7 +16,7 @@ use ApiPlatform\Core\JsonApi\EventListener\TransformFilteringParametersListener; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; /** * @author Baptiste Meyer @@ -37,7 +37,7 @@ public function testOnKernelRequestWithInvalidFormat() $request = $expectedRequest->duplicate(); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $this->listener->onKernelRequest($eventProphecy->reveal()); @@ -47,7 +47,7 @@ public function testOnKernelRequestWithInvalidFormat() public function testOnKernelRequestWithInvalidFilter() { - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $expectedRequest = new Request(); $expectedRequest->setRequestFormat('jsonapi'); @@ -72,7 +72,7 @@ public function testOnKernelRequest() $request = new Request(['filter' => ['foo' => 'bar', 'baz' => 'qux']]); $request->setRequestFormat('jsonapi'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $this->listener->onKernelRequest($eventProphecy->reveal()); diff --git a/tests/JsonApi/EventListener/TransformPaginationParametersListenerTest.php b/tests/JsonApi/EventListener/TransformPaginationParametersListenerTest.php index 5651a53454b..1399cc7dc50 100644 --- a/tests/JsonApi/EventListener/TransformPaginationParametersListenerTest.php +++ b/tests/JsonApi/EventListener/TransformPaginationParametersListenerTest.php @@ -16,7 +16,7 @@ use ApiPlatform\Core\JsonApi\EventListener\TransformPaginationParametersListener; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; /** * @author Baptiste Meyer @@ -37,7 +37,7 @@ public function testOnKernelRequestWithInvalidFormat() $request = $expectedRequest->duplicate(); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $this->listener->onKernelRequest($eventProphecy->reveal()); @@ -47,7 +47,7 @@ public function testOnKernelRequestWithInvalidFormat() public function testOnKernelRequestWithInvalidPage() { - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $expectedRequest = new Request(); $expectedRequest->setRequestFormat('jsonapi'); @@ -72,7 +72,7 @@ public function testOnKernelRequest() $request = new Request(['page' => ['size' => 5, 'number' => 3, 'error' => -1]]); $request->setRequestFormat('jsonapi'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $this->listener->onKernelRequest($eventProphecy->reveal()); diff --git a/tests/JsonApi/EventListener/TransformSortingParametersListenerTest.php b/tests/JsonApi/EventListener/TransformSortingParametersListenerTest.php index 4f4e39613b3..52f977584ab 100644 --- a/tests/JsonApi/EventListener/TransformSortingParametersListenerTest.php +++ b/tests/JsonApi/EventListener/TransformSortingParametersListenerTest.php @@ -16,7 +16,7 @@ use ApiPlatform\Core\JsonApi\EventListener\TransformSortingParametersListener; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; /** * @author Baptiste Meyer @@ -37,7 +37,7 @@ public function testOnKernelRequestWithInvalidFormat() $request = $expectedRequest->duplicate(); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $this->listener->onKernelRequest($eventProphecy->reveal()); @@ -47,7 +47,7 @@ public function testOnKernelRequestWithInvalidFormat() public function testOnKernelRequestWithInvalidFilter() { - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $expectedRequest = new Request(); $expectedRequest->setRequestFormat('jsonapi'); @@ -72,7 +72,7 @@ public function testOnKernelRequest() $request = new Request(['sort' => 'foo,-bar,-baz,qux']); $request->setRequestFormat('jsonapi'); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $this->listener->onKernelRequest($eventProphecy->reveal()); diff --git a/tests/Mercure/EventListener/AddLinkHeaderListenerTest.php b/tests/Mercure/EventListener/AddLinkHeaderListenerTest.php index 7ab4b7d6a51..e56d25486e2 100644 --- a/tests/Mercure/EventListener/AddLinkHeaderListenerTest.php +++ b/tests/Mercure/EventListener/AddLinkHeaderListenerTest.php @@ -21,7 +21,7 @@ use Fig\Link\Link; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\WebLink\HttpHeaderSerializer; /** @@ -39,7 +39,7 @@ public function testAddLinkHeader(string $expected, Request $request) $listener = new AddLinkHeaderListener($resourceMetadataFactoryProphecy->reveal(), 'https://demo.mercure.rocks/hub'); - $eventProphecy = $this->prophesize(FilterResponseEvent::class); + $eventProphecy = $this->prophesize(ResponseEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $listener->onKernelResponse($eventProphecy->reveal()); @@ -65,7 +65,7 @@ public function testDoNotAddHeader(Request $request) $listener = new AddLinkHeaderListener($resourceMetadataFactoryProphecy->reveal(), 'https://demo.mercure.rocks/hub'); - $eventProphecy = $this->prophesize(FilterResponseEvent::class); + $eventProphecy = $this->prophesize(ResponseEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $listener->onKernelResponse($eventProphecy->reveal()); diff --git a/tests/Security/EventListener/DenyAccessListenerTest.php b/tests/Security/EventListener/DenyAccessListenerTest.php index 94d951f4227..a151b32ff07 100644 --- a/tests/Security/EventListener/DenyAccessListenerTest.php +++ b/tests/Security/EventListener/DenyAccessListenerTest.php @@ -21,7 +21,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface; use Symfony\Component\Security\Core\Authentication\Token\AbstractToken; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; @@ -40,7 +40,7 @@ public function testNoResourceClass() { $request = new Request(); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $event = $eventProphecy->reveal(); @@ -56,7 +56,7 @@ public function testNoIsGrantedAttribute() { $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get']); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $event = $eventProphecy->reveal(); @@ -74,7 +74,7 @@ public function testIsGranted() $data = new \stdClass(); $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get', 'data' => $data]); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $event = $eventProphecy->reveal(); @@ -98,7 +98,7 @@ public function testAccessControl() $data = new \stdClass(); $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get', 'data' => $data]); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $event = $eventProphecy->reveal(); @@ -120,7 +120,7 @@ public function testIsNotGranted() $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get']); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $event = $eventProphecy->reveal(); @@ -143,7 +143,7 @@ public function testSecurityMessage() $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get']); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $event = $eventProphecy->reveal(); @@ -167,7 +167,7 @@ public function testIsGrantedLegacy() $data = new \stdClass(); $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get', 'data' => $data]); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $event = $eventProphecy->reveal(); @@ -192,7 +192,7 @@ public function testIsNotGrantedLegacy() $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get']); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $event = $eventProphecy->reveal(); @@ -217,7 +217,7 @@ public function testSecurityComponentNotAvailable() $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get']); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $event = $eventProphecy->reveal(); @@ -239,7 +239,7 @@ public function testExpressionLanguageNotInstalled() $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get']); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $event = $eventProphecy->reveal(); @@ -265,7 +265,7 @@ public function testNotBehindAFirewall() $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'get']); - $eventProphecy = $this->prophesize(GetResponseEvent::class); + $eventProphecy = $this->prophesize(RequestEvent::class); $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled(); $event = $eventProphecy->reveal(); diff --git a/tests/Validator/EventListener/ValidateListenerTest.php b/tests/Validator/EventListener/ValidateListenerTest.php index 56422cec36b..3260c688b61 100644 --- a/tests/Validator/EventListener/ValidateListenerTest.php +++ b/tests/Validator/EventListener/ValidateListenerTest.php @@ -23,7 +23,7 @@ use Prophecy\Argument; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; /** @@ -44,7 +44,7 @@ public function testNotAnApiPlatformRequest() $request = new Request(); $request->setMethod('POST'); - $eventProphecy = $this->prophesize(GetResponseForControllerResultEvent::class); + $eventProphecy = $this->prophesize(ViewEvent::class); $eventProphecy->getControllerResult()->willReturn([]); $eventProphecy->getRequest()->willReturn($request); @@ -81,7 +81,7 @@ public function testDoNotValidateWhenControllerResultIsResponse() $response = new Response(); - $eventProphecy = $this->prophesize(GetResponseForControllerResultEvent::class); + $eventProphecy = $this->prophesize(ViewEvent::class); $eventProphecy->getControllerResult()->willReturn($response); $eventProphecy->getRequest()->willReturn($request); @@ -101,7 +101,7 @@ public function testDoNotValidateWhenReceiveFlagIsFalse() $request = new Request([], [], ['data' => $dummy, '_api_resource_class' => DummyEntity::class, '_api_collection_operation_name' => 'post', '_api_receive' => false]); $request->setMethod('POST'); - $eventProphecy = $this->prophesize(GetResponseForControllerResultEvent::class); + $eventProphecy = $this->prophesize(ViewEvent::class); $eventProphecy->getControllerResult()->willReturn($dummy); $eventProphecy->getRequest()->willReturn($request); @@ -128,7 +128,7 @@ public function testDoNotValidateWhenDisabledInOperationAttribute() $request = new Request([], [], ['data' => $dummy, '_api_resource_class' => DummyEntity::class, '_api_collection_operation_name' => 'post']); $request->setMethod('POST'); - $eventProphecy = $this->prophesize(GetResponseForControllerResultEvent::class); + $eventProphecy = $this->prophesize(ViewEvent::class); $eventProphecy->getControllerResult()->willReturn($dummy); $eventProphecy->getRequest()->willReturn($request); @@ -175,7 +175,7 @@ private function createEventObject($expectedValidationGroups, $data, bool $recei ]); $request->setMethod('POST'); - $event = new GetResponseForControllerResultEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $data); + $event = new ViewEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $data); return [$resourceMetadataFactory, $event]; }