Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed SF 6.1 and SF 6.2 deprecations #2377

Merged
merged 16 commits into from
Jan 6, 2023
8 changes: 6 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ jobs:
- php-version: 8.1
composer-flags: ""
can-fail: false
symfony-require: "6.1.*"
- php-version: 8.1
composer-flags: ""
can-fail: false

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v3"

- name: "Install PHP with XDebug"
uses: "shivammathur/setup-php@v2"
Expand All @@ -68,7 +72,7 @@ jobs:
tools: "composer:v2,flex"

- name: "Cache dependencies installed with composer"
uses: "actions/cache@v2"
uses: "actions/cache@v3"
with:
path: "~/.composer/cache"
key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
Expand Down
2 changes: 1 addition & 1 deletion Request/RequestBodyParamConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function apply(Request $request, ParamConverter $configuration): bool
}
$this->configureContext($context = new Context(), $arrayContext);

$format = $request->getContentType();
$format = method_exists(Request::class, 'getContentTypeFormat') ? $request->getContentTypeFormat() : $request->getContentType();
if (null === $format) {
return $this->throwException(new UnsupportedMediaTypeHttpException(), $configuration);
}
Expand Down
4 changes: 2 additions & 2 deletions Serializer/Normalizer/FlattenExceptionNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
use FOS\RestBundle\Util\ExceptionValueMap;
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
*
* @internal
*/
final class FlattenExceptionNormalizer implements ContextAwareNormalizerInterface
final class FlattenExceptionNormalizer implements NormalizerInterface
{
private $statusCodeMap;
private $messagesMap;
Expand Down
2 changes: 1 addition & 1 deletion Serializer/Normalizer/FormErrorNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function normalize($object, $format = null, array $context = []): array
/**
* {@inheritdoc}
*/
public function supportsNormalization($data, $format = null): bool
public function supportsNormalization($data, $format = null, array $context = []): bool
{
return $data instanceof FormInterface && $data->isSubmitted() && !$data->isValid();
}
Expand Down
23 changes: 17 additions & 6 deletions Tests/EventListener/FormatListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
use FOS\RestBundle\FOSRestBundle;
use FOS\RestBundle\Negotiation\FormatNegotiator;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\ChainRequestMatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestMatcher;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Kernel;

/**
* Request listener test.
Expand All @@ -44,7 +46,7 @@ public function testOnKernelControllerNegotiation()
$requestStack = new RequestStack();
$requestStack->push($request);
$formatNegotiator = new FormatNegotiator($requestStack);
$formatNegotiator->add(new RequestMatcher('/'), [
$formatNegotiator->add($this->getRequestMatcher('/'), [
'fallback_format' => 'xml',
]);

Expand Down Expand Up @@ -72,7 +74,7 @@ public function testOnKernelControllerNoZone()
->will($this->returnValue($request));

$formatNegotiator = new FormatNegotiator($requestStack);
$formatNegotiator->add(new RequestMatcher('/'), ['fallback_format' => 'json']);
$formatNegotiator->add($this->getRequestMatcher('/'), ['fallback_format' => 'json']);

$listener = new FormatListener($formatNegotiator);

Expand All @@ -98,8 +100,8 @@ public function testOnKernelControllerNegotiationStopped()
->will($this->returnValue($request));

$formatNegotiator = new FormatNegotiator($requestStack);
$formatNegotiator->add(new RequestMatcher('/'), ['stop' => true]);
$formatNegotiator->add(new RequestMatcher('/'), ['fallback_format' => 'json']);
$formatNegotiator->add($this->getRequestMatcher('/'), ['stop' => true]);
$formatNegotiator->add($this->getRequestMatcher('/'), ['fallback_format' => 'json']);

$listener = new FormatListener($formatNegotiator);

Expand Down Expand Up @@ -157,7 +159,7 @@ public function testUseSpecifiedFormat($format, $result)
$requestStack = new RequestStack();
$requestStack->push($request);
$formatNegotiator = new FormatNegotiator($requestStack);
$formatNegotiator->add(new RequestMatcher('/'), [
$formatNegotiator->add($this->getRequestMatcher('/'), [
'fallback_format' => 'xml',
]);

Expand Down Expand Up @@ -202,7 +204,7 @@ public function testSfFragmentFormat()
$requestStack = new RequestStack();
$requestStack->push($request);
$formatNegotiator = new FormatNegotiator($requestStack);
$formatNegotiator->add(new RequestMatcher('/'), [
$formatNegotiator->add($this->getRequestMatcher('/'), [
'fallback_format' => 'json',
]);

Expand All @@ -212,4 +214,13 @@ public function testSfFragmentFormat()

$this->assertEquals($request->getRequestFormat(), 'json');
}

private function getRequestMatcher(string $path)
{
if (Kernel::VERSION_ID < 60200) {
return new RequestMatcher($path);
}

return new ChainRequestMatcher([new RequestMatcher\PathRequestMatcher($path)]);
}
}
6 changes: 1 addition & 5 deletions Tests/Functional/app/BasicAuth/config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
imports:
- { resource: ../config/default.yml }
- { resource: security.php }

framework:
serializer:
enabled: true
router: { resource: "%kernel.project_dir%/BasicAuth/routing.yml" }
- { resource: framework.php }

fos_rest:
zone:
Expand Down
25 changes: 25 additions & 0 deletions Tests/Functional/app/BasicAuth/framework.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of the FOSRestBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

$frameworkConfig = [
'serializer' => [
'enabled' => true,
],
'router' => [
'resource' => '%kernel.project_dir%/BasicAuth/routing.yml',
],
];

if (\Symfony\Component\HttpKernel\Kernel::VERSION_ID >= 60100) {
$frameworkConfig['http_method_override'] = true;
}

$container->loadFromExtension('framework', $frameworkConfig);
7 changes: 6 additions & 1 deletion Tests/Functional/app/BasicAuth/security.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

use Symfony\Component\HttpKernel\Kernel;

$securityConfig = [
'providers' => [
'in_memory' => [
Expand Down Expand Up @@ -41,7 +43,10 @@
// BC layer to avoid deprecation warnings in symfony/security-bundle < 5.3
if (class_exists(\Symfony\Bundle\SecurityBundle\RememberMe\FirewallAwareRememberMeHandler::class)) {
$securityConfig['password_hashers'] = $passwordHasherConfig;
$securityConfig['enable_authenticator_manager'] = true;
// BC layer to avoid deprecation warnings in symfony/security-bundle < 6.2
if (Kernel::VERSION_ID < 60200) {
$securityConfig['enable_authenticator_manager'] = true;
}
} else {
$securityConfig['encoders'] = $passwordHasherConfig;
}
Expand Down
10 changes: 1 addition & 9 deletions Tests/Functional/app/Configuration/config.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
imports:
- { resource: ../config/default.yml }
- { resource: ../config/sensio_framework_extra.yml }
- { resource: framework.php }
- { resource: security.php }

framework:
annotations:
enabled: true
property_access: ~
serializer:
enabled: true
router: { resource: "%kernel.project_dir%/Configuration/routing.yml" }
profiler: { only_exceptions: false }

fos_rest:
view:
mime_types: true
Expand Down
32 changes: 32 additions & 0 deletions Tests/Functional/app/Configuration/framework.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the FOSRestBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

$frameworkConfig = [
'annotations' => [
'enabled' => true,
],
'property_access' => null,
'serializer' => [
'enabled' => true,
],
'router' => [
'resource' => '%kernel.project_dir%/BasicAuth/routing.yml',
],
'profiler' => [
'only_exceptions' => false,
],
];

if (\Symfony\Component\HttpKernel\Kernel::VERSION_ID >= 60100) {
$frameworkConfig['http_method_override'] = true;
}

$container->loadFromExtension('framework', $frameworkConfig);
7 changes: 6 additions & 1 deletion Tests/Functional/app/CustomGuardAuthenticator/security.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

use Symfony\Component\HttpKernel\Kernel;

$securityConfig = [
'providers' => [
'in_memory' => [
Expand All @@ -30,7 +32,10 @@
// BC layer to avoid deprecation warnings in symfony/security-bundle < 5.3
if (class_exists(\Symfony\Bundle\SecurityBundle\RememberMe\FirewallAwareRememberMeHandler::class)) {
$securityConfig['password_hashers'] = $passwordHasherConfig;
$securityConfig['enable_authenticator_manager'] = true;
// BC layer to avoid deprecation warnings in symfony/security-bundle < 6.2
if (Kernel::VERSION_ID < 60200) {
$securityConfig['enable_authenticator_manager'] = true;
}
$securityConfig['firewalls'] = [
'default' => [
'provider' => 'in_memory',
Expand Down
10 changes: 8 additions & 2 deletions Tests/Functional/app/config/framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
];
}

$container->loadFromExtension('framework', [
$frameworkConfig = [
'annotations' => [
'enabled' => true,
],
Expand All @@ -35,4 +35,10 @@
'form' => null,
'session' => $sessionConfig,
'default_locale' => 'en',
]);
];

if (\Symfony\Component\HttpKernel\Kernel::VERSION_ID >= 60100) {
$frameworkConfig['http_method_override'] = true;
}

$container->loadFromExtension('framework', $frameworkConfig);
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"doctrine/annotations": "^1.13.2",
"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|^5.0@beta",
"jms/serializer-bundle": "^2.4.3|^3.0.1|^4.0|^5.0",
"psr/http-message": "^1.0",
"psr/log": "^1.0|^2.0|^3.0",
"sensio/framework-extra-bundle": "^6.1",
Expand Down