diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 683227cfd..688627a81 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -15,28 +15,37 @@ jobs: phpunit: name: "PHPUnit" runs-on: "ubuntu-20.04" + continue-on-error: ${{ matrix.can-fail }} strategy: matrix: include: - php-version: 7.2 composer-flags: "--prefer-lowest --prefer-stable" + can-fail: false - php-version: 7.3 composer-flags: "--prefer-stable" + can-fail: false - php-version: 7.4 composer-flags: "--prefer-stable" symfony-require: "4.4.*" + can-fail: false - php-version: 7.4 composer-flags: "--prefer-stable" - symfony-require: "5.1.*" + symfony-require: "5.3.*" + can-fail: false coverage: yes - php-version: 7.4 composer-flags: "--prefer-stable" - symfony-require: "5.2.*" + can-fail: true + symfony-require: "5.4.*@dev" - php-version: 8.0 - composer-flags: "--ignore-platform-reqs --prefer-stable" + composer-flags: "--prefer-stable" + can-fail: true + symfony-require: "6.0.*@dev" - php-version: 8.1 composer-flags: "--prefer-stable" + can-fail: false steps: - name: "Checkout" @@ -48,6 +57,7 @@ jobs: with: php-version: "${{ matrix.php-version }}" coverage: "xdebug" + tools: "composer:v2,flex" - name: "Install PHP without coverage" uses: "shivammathur/setup-php@v2" @@ -55,6 +65,7 @@ jobs: with: php-version: "${{ matrix.php-version }}" coverage: "none" + tools: "composer:v2,flex" - name: "Cache dependencies installed with composer" uses: "actions/cache@v2" @@ -67,7 +78,7 @@ jobs: env: SYMFONY_REQUIRE: "${{ matrix.symfony-require }}" run: | - composer global require --no-progress --no-scripts --no-plugins symfony/flex + composer remove friendsofphp/php-cs-fixer --dev --no-update composer update --no-interaction --no-progress ${{ matrix.composer-flags }} - name: "Run PHPUnit" diff --git a/Controller/AbstractFOSRestController.php b/Controller/AbstractFOSRestController.php index bf902fcb0..18e6ebdd7 100644 --- a/Controller/AbstractFOSRestController.php +++ b/Controller/AbstractFOSRestController.php @@ -14,10 +14,18 @@ use FOS\RestBundle\View\ViewHandlerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +$ref = new \ReflectionMethod(AbstractController::class, 'getSubscribedServices'); + +// Does the AbstractController::getSubscribedServices() method have a return type hint? +if (null !== $ref->getReturnType()) { + class_alias(PostSymfony6AbstractFOSRestController::class, 'FOS\RestBundle\Controller\BaseAbstractFOSRestController'); +} else { + class_alias(PreSymfony6AbstractFOSRestController::class, 'FOS\RestBundle\Controller\BaseAbstractFOSRestController'); +} /** * Controllers using the View functionality of FOSRestBundle. */ -abstract class AbstractFOSRestController extends AbstractController +abstract class AbstractFOSRestController extends BaseAbstractFOSRestController { use ControllerTrait; @@ -32,15 +40,4 @@ protected function getViewHandler() return $this->viewhandler; } - - /** - * {@inheritdoc} - */ - public static function getSubscribedServices() - { - $subscribedServices = parent::getSubscribedServices(); - $subscribedServices['fos_rest.view_handler'] = ViewHandlerInterface::class; - - return $subscribedServices; - } } diff --git a/Controller/Annotations/Route.php b/Controller/Annotations/Route.php index 9b2813bd9..677e0979c 100644 --- a/Controller/Annotations/Route.php +++ b/Controller/Annotations/Route.php @@ -86,22 +86,31 @@ public function __construct( $env ); } else { + if (\is_string($data)) { + $data = ['path' => $data]; + } elseif (!\is_array($data)) { + throw new \TypeError(sprintf('"%s": Argument $data is expected to be a string or array, got "%s".', __METHOD__, get_debug_type($data))); + } elseif (0 !== count($data) && [] === \array_intersect(\array_keys($data), ['path', 'name', 'requirements', 'options', 'defaults', 'host', 'methods', 'schemes', 'condition', 'priority', 'locale', 'format', 'utf8', 'stateless', 'env'])) { + $localizedPaths = $data; + $data = ['path' => $localizedPaths]; + } + parent::__construct( - $path, - $name, - $requirements, - $options, - $defaults, - $host, - $methods, - $schemes, - $condition, - $priority, - $locale, - $format, - $utf8, - $stateless, - $env + $data['path'] ?? $path, + $data['name'] ?? $name, + $data['requirements'] ?? $requirements, + $data['options'] ?? $options, + $data['defaults'] ?? $defaults, + $data['host'] ?? $host, + $data['methods'] ?? $methods, + $data['schemes'] ?? $schemes, + $data['condition'] ?? $condition, + $data['priority'] ?? $priority, + $data['locale'] ?? $locale, + $data['format'] ?? $format, + $data['utf8'] ?? $utf8, + $data['stateless'] ?? $stateless, + $data['env'] ?? $env ); } } diff --git a/Controller/PostSymfony6AbstractFOSRestController.php b/Controller/PostSymfony6AbstractFOSRestController.php new file mode 100644 index 000000000..444e6bf51 --- /dev/null +++ b/Controller/PostSymfony6AbstractFOSRestController.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\RestBundle\Controller; + +use FOS\RestBundle\View\ViewHandlerInterface; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; + +/** + * @internal + */ +abstract class PostSymfony6AbstractFOSRestController extends AbstractController +{ + /** + * {@inheritdoc} + */ + public static function getSubscribedServices(): array + { + $subscribedServices = parent::getSubscribedServices(); + $subscribedServices['fos_rest.view_handler'] = ViewHandlerInterface::class; + + return $subscribedServices; + } +} diff --git a/Controller/PreSymfony6AbstractFOSRestController.php b/Controller/PreSymfony6AbstractFOSRestController.php new file mode 100644 index 000000000..ebf72c293 --- /dev/null +++ b/Controller/PreSymfony6AbstractFOSRestController.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\RestBundle\Controller; + +use FOS\RestBundle\View\ViewHandlerInterface; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; + +/** + * @internal + */ +abstract class PreSymfony6AbstractFOSRestController extends AbstractController +{ + use ControllerTrait; + + /** + * @return array + */ + public static function getSubscribedServices() + { + $subscribedServices = parent::getSubscribedServices(); + $subscribedServices['fos_rest.view_handler'] = ViewHandlerInterface::class; + + return $subscribedServices; + } +} diff --git a/EventListener/BodyListener.php b/EventListener/BodyListener.php index 5bce9c3bc..1514b136d 100644 --- a/EventListener/BodyListener.php +++ b/EventListener/BodyListener.php @@ -15,6 +15,7 @@ use FOS\RestBundle\FOSRestBundle; use FOS\RestBundle\Normalizer\ArrayNormalizerInterface; use FOS\RestBundle\Normalizer\Exception\NormalizationException; +use Symfony\Component\HttpFoundation\InputBag; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\RequestEvent; @@ -88,7 +89,12 @@ public function onKernelRequest(RequestEvent $event): void $decoder = $this->decoderProvider->getDecoder($format); $data = $decoder->decode($content); if (is_array($data)) { - $request->request = new ParameterBag($data); + if (class_exists(InputBag::class)) { + $request->request = new InputBag($data); + } else { + $request->request = new ParameterBag($data); + } + $normalizeRequest = true; } else { throw new BadRequestHttpException('Invalid '.$format.' message received'); @@ -105,7 +111,11 @@ public function onKernelRequest(RequestEvent $event): void throw new BadRequestHttpException($e->getMessage()); } - $request->request = new ParameterBag($data); + if (class_exists(InputBag::class)) { + $request->request = new InputBag($data); + } else { + $request->request = new ParameterBag($data); + } } } diff --git a/Serializer/Normalizer/FlattenExceptionNormalizer.php b/Serializer/Normalizer/FlattenExceptionNormalizer.php index 249712850..05d445e36 100644 --- a/Serializer/Normalizer/FlattenExceptionNormalizer.php +++ b/Serializer/Normalizer/FlattenExceptionNormalizer.php @@ -37,7 +37,7 @@ public function __construct(ExceptionValueMap $statusCodeMap, ExceptionValueMap $this->rfc7807 = $rfc7807; } - public function normalize($exception, $format = null, array $context = []) + public function normalize($exception, $format = null, array $context = []): array { if (isset($context['status_code'])) { $statusCode = $context['status_code']; @@ -74,7 +74,7 @@ public function normalize($exception, $format = null, array $context = []) } } - public function supportsNormalization($data, $format = null, array $context = []) + public function supportsNormalization($data, $format = null, array $context = []): bool { return $data instanceof FlattenException && ($context[Serializer::FOS_BUNDLE_SERIALIZATION_CONTEXT] ?? false); } diff --git a/Tests/Controller/Annotations/QueryParamTest.php b/Tests/Controller/Annotations/QueryParamTest.php index 1237ff927..079525a11 100644 --- a/Tests/Controller/Annotations/QueryParamTest.php +++ b/Tests/Controller/Annotations/QueryParamTest.php @@ -14,6 +14,7 @@ use FOS\RestBundle\Controller\Annotations\AbstractScalarParam; use FOS\RestBundle\Controller\Annotations\QueryParam; use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpFoundation\InputBag; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; @@ -45,9 +46,15 @@ public function testValueGetter() ->willReturn('foo'); $request = $this->getMockBuilder(Request::class)->getMock(); - $parameterBag = new ParameterBag(); - $parameterBag->set('foo', 'foobar'); - $request->query = $parameterBag; + + if (class_exists(InputBag::class)) { + $bag = new InputBag(); + } else { + $bag = new ParameterBag(); + } + + $bag->set('foo', 'foobar'); + $request->query = $bag; $this->assertEquals('foobar', $this->param->getValue($request, 'bar')); } diff --git a/Tests/Controller/Annotations/RequestParamTest.php b/Tests/Controller/Annotations/RequestParamTest.php index 8114f8edf..a6ae61ca1 100644 --- a/Tests/Controller/Annotations/RequestParamTest.php +++ b/Tests/Controller/Annotations/RequestParamTest.php @@ -14,6 +14,7 @@ use FOS\RestBundle\Controller\Annotations\AbstractScalarParam; use FOS\RestBundle\Controller\Annotations\RequestParam; use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpFoundation\InputBag; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; @@ -45,9 +46,15 @@ public function testValueGetter() ->willReturn('foo'); $request = $this->getMockBuilder(Request::class)->getMock(); - $parameterBag = new ParameterBag(); - $parameterBag->set('foo', 'foobar'); - $request->request = $parameterBag; + + if (class_exists(InputBag::class)) { + $bag = new InputBag(); + } else { + $bag = new ParameterBag(); + } + + $bag->set('foo', 'foobar'); + $request->request = $bag; $this->assertEquals('foobar', $this->param->getValue($request, 'bar')); } diff --git a/Tests/Functional/Bundle/TestBundle/Controller/Version2Controller.php b/Tests/Functional/Bundle/TestBundle/Controller/Version2Controller.php index f69f90b72..f60dee566 100644 --- a/Tests/Functional/Bundle/TestBundle/Controller/Version2Controller.php +++ b/Tests/Functional/Bundle/TestBundle/Controller/Version2Controller.php @@ -47,7 +47,7 @@ public function versionPathAction(Request $request, $version) private function findExclusionStrategyVersion(Request $request) { $view = $this->view([]); - $response = $this->get('fos_rest.view_handler')->createResponse($view, $request, 'json'); + $response = $this->getViewHandler()->createResponse($view, $request, 'json'); return $view->getContext()->getVersion(); } diff --git a/Tests/Functional/Bundle/TestBundle/Controller/VersionController.php b/Tests/Functional/Bundle/TestBundle/Controller/VersionController.php index 834b91ebd..4dc489413 100644 --- a/Tests/Functional/Bundle/TestBundle/Controller/VersionController.php +++ b/Tests/Functional/Bundle/TestBundle/Controller/VersionController.php @@ -36,7 +36,7 @@ public function versionAction(Request $request, $version) private function findExclusionStrategyVersion(Request $request) { $view = $this->view([]); - $response = $this->get('fos_rest.view_handler')->createResponse($view, $request, 'json'); + $response = $this->getViewHandler()->createResponse($view, $request, 'json'); return $view->getContext()->getVersion(); } diff --git a/Tests/Functional/Bundle/TestBundle/Security/ApiToken53Authenticator.php b/Tests/Functional/Bundle/TestBundle/Security/ApiToken53Authenticator.php new file mode 100644 index 000000000..54331828c --- /dev/null +++ b/Tests/Functional/Bundle/TestBundle/Security/ApiToken53Authenticator.php @@ -0,0 +1,68 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\RestBundle\Tests\Functional\Bundle\TestBundle\Security; + +use FOS\RestBundle\Tests\Functional\Bundle\TestBundle\Entity\User; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; +use Symfony\Component\Security\Core\Exception\AuthenticationException; +use Symfony\Component\Security\Core\Exception\BadCredentialsException; +use Symfony\Component\Security\Http\Authenticator\AbstractAuthenticator; +use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge; +use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface; +use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport; + +class ApiToken53Authenticator extends AbstractAuthenticator +{ + protected $headerName = 'x-foo'; + protected $tokenValue = 'FOOBAR'; + + public function authenticate(Request $request): PassportInterface + { + $credentials = $request->headers->get($this->headerName); + + if (!$credentials || $credentials !== $this->tokenValue) { + throw new BadCredentialsException(); + } + + $userBadge = new UserBadge($this->tokenValue, function () { + $user = new User(); + $user->username = 'foo'; + $user->roles[] = 'ROLE_API'; + + return $user; + }); + + return new SelfValidatingPassport($userBadge); + } + + public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response + { + return null; + } + + public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response + { + return new JsonResponse(null, 401); + } + + public function supports(Request $request): ?bool + { + if (!$request->headers->has($this->headerName)) { + return false; + } + + return true; + } +} diff --git a/Tests/Functional/Bundle/TestBundle/Security/ApiTokenAuthenticator.php b/Tests/Functional/Bundle/TestBundle/Security/ApiTokenAuthenticator.php index c5ccae152..c0262e277 100644 --- a/Tests/Functional/Bundle/TestBundle/Security/ApiTokenAuthenticator.php +++ b/Tests/Functional/Bundle/TestBundle/Security/ApiTokenAuthenticator.php @@ -20,7 +20,7 @@ use Symfony\Component\Security\Core\Exception\BadCredentialsException; use Symfony\Component\Security\Http\Authenticator\AbstractAuthenticator; use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge; -use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface; +use Symfony\Component\Security\Http\Authenticator\Passport\Passport; use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport; class ApiTokenAuthenticator extends AbstractAuthenticator @@ -28,7 +28,7 @@ class ApiTokenAuthenticator extends AbstractAuthenticator protected $headerName = 'x-foo'; protected $tokenValue = 'FOOBAR'; - public function authenticate(Request $request): PassportInterface + public function authenticate(Request $request): Passport { $credentials = $request->headers->get($this->headerName); diff --git a/Tests/Functional/DependencyInjectionTest.php b/Tests/Functional/DependencyInjectionTest.php index a7b435852..af23f03b5 100644 --- a/Tests/Functional/DependencyInjectionTest.php +++ b/Tests/Functional/DependencyInjectionTest.php @@ -44,7 +44,7 @@ interface_exists(SerializationVisitorInterface::class) ? JMSHandlerRegistryV2::c ); } - protected static function getKernelClass() + protected static function getKernelClass(): string { return TestKernel::class; } @@ -52,7 +52,7 @@ protected static function getKernelClass() class TestKernel extends Kernel { - public function registerBundles() + public function registerBundles(): array { return [ new FrameworkBundle(), @@ -80,7 +80,7 @@ public function registerContainerConfiguration(LoaderInterface $loader) }); } - public function getCacheDir() + public function getCacheDir(): string { return sys_get_temp_dir().'/'.str_replace('\\', '-', get_class($this)).'/cache/'.$this->environment; } diff --git a/Tests/Functional/WebTestCase.php b/Tests/Functional/WebTestCase.php index 0d704241b..6d5479529 100644 --- a/Tests/Functional/WebTestCase.php +++ b/Tests/Functional/WebTestCase.php @@ -15,6 +15,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpKernel\Kernel; +use Symfony\Component\HttpKernel\KernelInterface; class WebTestCase extends BaseWebTestCase { @@ -28,14 +29,14 @@ protected static function deleteTmpDir($testCase) $fs->remove($dir); } - protected static function getKernelClass() + protected static function getKernelClass(): string { require_once __DIR__.'/app/AppKernel.php'; return AppKernel::class; } - protected static function createKernel(array $options = []) + protected static function createKernel(array $options = []): KernelInterface { $class = self::getKernelClass(); @@ -43,12 +44,12 @@ protected static function createKernel(array $options = []) throw new \InvalidArgumentException('The option "test_case" must be set.'); } - $debug = isset($options['debug']) ? $options['debug'] : true; + $debug = $options['debug'] ?? true; return new $class( $options['test_case'], - isset($options['root_config']) ? $options['root_config'] : 'config.yml', - isset($options['environment']) ? $options['environment'] : 'fosrestbundletest'.strtolower($options['test_case']).(int) $debug, + $options['root_config'] ?? 'config.yml', + $options['environment'] ?? 'fosrestbundletest'.strtolower($options['test_case']).(int) $debug, $debug ); } diff --git a/Tests/Functional/app/AppKernel.php b/Tests/Functional/app/AppKernel.php index a9c7f7f08..8aa6b4c18 100644 --- a/Tests/Functional/app/AppKernel.php +++ b/Tests/Functional/app/AppKernel.php @@ -70,7 +70,7 @@ public function __construct($testCase, $rootConfig, $environment, $debug) parent::__construct($environment, $debug); } - public function registerBundles() + public function registerBundles(): array { if (!file_exists($filename = $this->getProjectDir().'/'.$this->testCase.'/bundles.php')) { throw new \RuntimeException(sprintf('The bundles file "%s" does not exist.', $filename)); @@ -79,17 +79,17 @@ public function registerBundles() return include $filename; } - public function getProjectDir() + public function getProjectDir(): string { return __DIR__; } - public function getCacheDir() + public function getCacheDir(): string { return sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$this->testCase.'/cache/'.$this->environment; } - public function getLogDir() + public function getLogDir(): string { return sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$this->testCase.'/logs'; } @@ -114,7 +114,7 @@ public function unserialize($str) $this->__construct($a[0], $a[1], $a[2], $a[3]); } - protected function getKernelParameters() + protected function getKernelParameters(): array { $parameters = parent::getKernelParameters(); $parameters['kernel.test_case'] = $this->testCase; diff --git a/Tests/Functional/app/BasicAuth/security.php b/Tests/Functional/app/BasicAuth/security.php index 6729697cc..bde9ca252 100644 --- a/Tests/Functional/app/BasicAuth/security.php +++ b/Tests/Functional/app/BasicAuth/security.php @@ -32,7 +32,11 @@ ], ]; -$passwordHasherConfig = ['Symfony\Component\Security\Core\User\User' => 'plaintext']; +if (class_exists(\Symfony\Component\Security\Core\User\InMemoryUser::class)) { + $passwordHasherConfig = ['Symfony\Component\Security\Core\User\InMemoryUser' => 'plaintext']; +} else { + $passwordHasherConfig = ['Symfony\Component\Security\Core\User\User' => 'plaintext']; +} // BC layer to avoid deprecation warnings in symfony/security-bundle < 5.3 if (class_exists(\Symfony\Bundle\SecurityBundle\RememberMe\FirewallAwareRememberMeHandler::class)) { diff --git a/Tests/Functional/app/CustomGuardAuthenticator/security.php b/Tests/Functional/app/CustomGuardAuthenticator/security.php index 781caa4f2..1199cb2db 100644 --- a/Tests/Functional/app/CustomGuardAuthenticator/security.php +++ b/Tests/Functional/app/CustomGuardAuthenticator/security.php @@ -21,7 +21,11 @@ ], ]; -$passwordHasherConfig = ['Symfony\Component\Security\Core\User\User' => 'plaintext']; +if (class_exists(\Symfony\Component\Security\Core\User\InMemoryUser::class)) { + $passwordHasherConfig = ['Symfony\Component\Security\Core\User\InMemoryUser' => 'plaintext']; +} else { + $passwordHasherConfig = ['Symfony\Component\Security\Core\User\User' => 'plaintext']; +} // BC layer to avoid deprecation warnings in symfony/security-bundle < 5.3 if (class_exists(\Symfony\Bundle\SecurityBundle\RememberMe\FirewallAwareRememberMeHandler::class)) { diff --git a/Tests/Functional/app/CustomGuardAuthenticator/services.php b/Tests/Functional/app/CustomGuardAuthenticator/services.php index 2523bdd4e..91ebff2c1 100644 --- a/Tests/Functional/app/CustomGuardAuthenticator/services.php +++ b/Tests/Functional/app/CustomGuardAuthenticator/services.php @@ -10,10 +10,14 @@ */ return function (Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator $container) { - // BC layer to avoid deprecation warnings in symfony < 5.3 - if (class_exists(Symfony\Bundle\SecurityBundle\RememberMe\FirewallAwareRememberMeHandler::class)) { + if (class_exists(Symfony\Component\Security\Http\Authenticator\AbstractAuthenticator::class) && method_exists(Symfony\Component\Security\Http\Authenticator\AbstractAuthenticator::class, 'createToken')) { + // Authenticator for use on Symfony 5.4 and newer $tokenAuthenticatorClass = \FOS\RestBundle\Tests\Functional\Bundle\TestBundle\Security\ApiTokenAuthenticator::class; + } elseif (class_exists(Symfony\Bundle\SecurityBundle\RememberMe\FirewallAwareRememberMeHandler::class)) { + // Authenticator for use on Symfony 5.3 + $tokenAuthenticatorClass = \FOS\RestBundle\Tests\Functional\Bundle\TestBundle\Security\ApiToken53Authenticator::class; } else { + // Authenticator for use on Symfony 5.2 and earlier $tokenAuthenticatorClass = \FOS\RestBundle\Tests\Functional\Bundle\TestBundle\Security\ApiTokenGuardAuthenticator::class; } diff --git a/Tests/Request/ParamFetcherTest.php b/Tests/Request/ParamFetcherTest.php index 396c73e13..41ff6b6a4 100644 --- a/Tests/Request/ParamFetcherTest.php +++ b/Tests/Request/ParamFetcherTest.php @@ -154,7 +154,7 @@ public function testNoValidationErrors() ->expects($this->once()) ->method('validate') ->with('value', [new NotBlank()]) - ->willReturn([]); + ->willReturn($this->getMockBuilder(ConstraintViolationListInterface::class)->getMock()); $this->paramFetcher->setController($this->controller); diff --git a/Tests/Request/RequestBodyParamConverterTest.php b/Tests/Request/RequestBodyParamConverterTest.php index ad544e2e9..396f268fe 100644 --- a/Tests/Request/RequestBodyParamConverterTest.php +++ b/Tests/Request/RequestBodyParamConverterTest.php @@ -23,6 +23,7 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException; use Symfony\Component\Serializer\Exception\InvalidArgumentException as SymfonyInvalidArgumentException; +use Symfony\Component\Validator\ConstraintViolationListInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; /** @@ -146,19 +147,21 @@ public function testValidatorParameters() ->method('deserialize') ->willReturn('Object'); + $errors = $this->getMockBuilder(ConstraintViolationListInterface::class)->getMock(); + $validator = $this->getMockBuilder(ValidatorInterface::class)->getMock(); $validator ->expects($this->once()) ->method('validate') ->with('Object', null, ['foo']) - ->willReturn('fooError'); + ->willReturn($errors); $converter = new RequestBodyParamConverter($this->serializer, null, null, $validator, 'errors'); $request = $this->createRequest(null, 'application/json'); $configuration = $this->createConfiguration('FooClass', null, ['validator' => ['groups' => ['foo']]]); $this->launchExecution($converter, $request, $configuration); - $this->assertEquals('fooError', $request->attributes->get('errors')); + $this->assertEquals($errors, $request->attributes->get('errors')); } public function testValidatorSkipping() diff --git a/composer.json b/composer.json index b451eaef8..595c2380f 100644 --- a/composer.json +++ b/composer.json @@ -30,37 +30,38 @@ }, "require": { "php": "^7.2|^8.0", - "symfony/config": "^4.4|^5.0", - "symfony/dependency-injection": "^4.4|^5.0", - "symfony/event-dispatcher": "^4.4|^5.0", - "symfony/framework-bundle": "^4.4.1|^5.0", - "symfony/http-foundation": "^4.4|^5.0", - "symfony/http-kernel": "^4.4|^5.0", - "symfony/security-core": "^3.4|^4.3|^5.0", - "willdurand/negotiation": "^2.0|^3.0", - "willdurand/jsonp-callback-validator": "^1.0" + "symfony/config": "^4.4|^5.3|^6.0", + "symfony/dependency-injection": "^4.4|^5.3|^6.0", + "symfony/event-dispatcher": "^4.4|^5.3|^6.0", + "symfony/framework-bundle": "^4.4.1|^5.0|^6.0", + "symfony/http-foundation": "^4.4|^5.3|^6.0", + "symfony/http-kernel": "^4.4|^5.3|^6.0", + "symfony/routing": "^4.4|^5.3|^6.0", + "symfony/security-core": "^4.4|^5.3|^6.0", + "willdurand/jsonp-callback-validator": "^1.0", + "willdurand/negotiation": "^2.0|^3.0" }, "require-dev": { "doctrine/annotations": "^1.13.2", - "psr/log": "^1.0|^2.0|^3.0", - "sensio/framework-extra-bundle": "^5.2.3", - "symfony/phpunit-bridge": "^5.3.10", - "symfony/asset": "^4.4|^5.0", - "symfony/form": "^4.4|^5.0", - "symfony/mime": "^4.4|^5.0", - "symfony/validator": "^4.4|^5.0", - "symfony/serializer": "^4.4|^5.0", - "symfony/yaml": "^4.4|^5.0", - "symfony/security-bundle": "^4.4|^5.0", - "symfony/web-profiler-bundle": "^4.4|^5.0", - "symfony/twig-bundle": "^4.4|^5.0", - "symfony/browser-kit": "^4.4|^5.0", - "symfony/expression-language": "^4.4|^5.0", - "symfony/css-selector": "^4.4|^5.0", - "jms/serializer-bundle": "^2.4.3|^3.0.1|^4.0", + "friendsofphp/php-cs-fixer": "^3.0", "jms/serializer": "^1.13|^2.0|^3.0", + "jms/serializer-bundle": "^2.4.3|^3.0.1|^4.0", "psr/http-message": "^1.0", - "friendsofphp/php-cs-fixer": "^3.0" + "psr/log": "^1.0|^2.0|^3.0", + "sensio/framework-extra-bundle": "^5.2.3|^6.0", + "symfony/phpunit-bridge": "^5.3|^6.0", + "symfony/asset": "^4.4|^5.3|^6.0", + "symfony/browser-kit": "^4.4|^5.3|^6.0", + "symfony/css-selector": "^4.4|^5.3|^6.0", + "symfony/expression-language": "^4.4|^5.3|^6.0", + "symfony/form": "^4.4|^5.3|^6.0", + "symfony/mime": "^4.4|^5.3|^6.0", + "symfony/security-bundle": "^4.4|^5.3|^6.0", + "symfony/serializer": "^4.4|^5.3|^6.0", + "symfony/twig-bundle": "^4.4|^5.3|^6.0", + "symfony/validator": "^4.4|^5.3|^6.0", + "symfony/web-profiler-bundle": "^4.4|^5.3|^6.0", + "symfony/yaml": "^4.4|^5.3|^6.0" }, "suggest": { "sensio/framework-extra-bundle": "Add support for the request body converter and the view response listener, requires ^3.0", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 735317e1f..54b3cf347 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,8 @@ - + +