Skip to content

Commit

Permalink
Deprecation since Symfony 5.1: NodeDefinition::setDeprecated() requir…
Browse files Browse the repository at this point in the history
…es 3 arguments (#580)

- Deprecation since Symfony 5.1
- Add Symfony 5.2 to CI allowed failures
- Fix deprecations in tests
- Test Symfony 5.1 on PHP 7.2
  • Loading branch information
StudioMaX committed Jun 3, 2020
1 parent 7d9294b commit e0de164
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 15 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ matrix:
env: SYMFONY_VERSION="4.4.*"
- php: 7.4
env: SYMFONY_VERSION="5.0.*"
- php: 7.2
env: SYMFONY_VERSION="5.1.*"
- php: 7.4
env: SYMFONY_VERSION="5.1.*"
- php: 7.4
env: SYMFONY_VERSION="5.1.*" STABILITY="dev"
env: SYMFONY_VERSION="5.2.*" STABILITY="dev"

allow_failures:
- php: 7.4
env: SYMFONY_VERSION="5.1.*" STABILITY="dev"
env: SYMFONY_VERSION="5.2.*" STABILITY="dev"

dist: xenial
sudo: false
Expand Down
22 changes: 21 additions & 1 deletion DependencyInjection/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Snc\RedisBundle\DependencyInjection\Configuration;

use Symfony\Component\Config\Definition\BaseNode;
use function method_exists;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand Down Expand Up @@ -267,7 +268,7 @@ private function addProfilerStorageSection(ArrayNodeDefinition $rootNode)
$rootNode
->children()
->arrayNode('profiler_storage')
->setDeprecated('Redis profiler storage is not available anymore since Symfony 4.4')
->setDeprecated(...$this->getProfilerStorageDeprecationMessage())
->canBeUnset()
->children()
->scalarNode('client')->isRequired()->end()
Expand All @@ -276,4 +277,23 @@ private function addProfilerStorageSection(ArrayNodeDefinition $rootNode)
->end()
->end();
}

/**
* Keep compatibility with symfony/config < 5.1
*
* The signature of method NodeDefinition::setDeprecated() has been updated to
* NodeDefinition::setDeprecation(string $package, string $version, string $message).
*
* @return array
*/
private function getProfilerStorageDeprecationMessage(): array
{
$message = 'Redis profiler storage is not available anymore since Symfony 4.4';

if (method_exists(BaseNode::class, 'getDeprecation')) {
return ['snc/redis-bundle', '3.2.0', $message];
}

return [$message];
}
}
6 changes: 3 additions & 3 deletions Tests/Functional/App/Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function home(Request $request, \Redis $redis)
{
$redis->set('foo', 'bar');

return JsonResponse::create([
return new JsonResponse([
'result' => $redis->get('foo'),
]);
}
Expand All @@ -45,7 +45,7 @@ public function createUser()
$em->persist($user);
$em->flush();

return JsonResponse::create(['result' => 'ok']);
return new JsonResponse(['result' => 'ok']);
}

public function viewUser()
Expand All @@ -55,7 +55,7 @@ public function viewUser()
/** @var User $user */
$user = $repository->findOneBy(['username' => 'foo']);

return JsonResponse::create([
return new JsonResponse([
'id' => $user->getId(),
'username' => $user->getUsername(),
'email' => $user->getEmail(),
Expand Down
46 changes: 37 additions & 9 deletions Tests/Functional/App/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use Symfony\Component\Routing\RouteCollectionBuilder;

/**
* Kernel
*
* @author Niels Keurentjes <niels.keurentjes@omines.com>
*/
class Kernel extends BaseKernel
abstract class AbstractKernel extends BaseKernel
{
use MicroKernelTrait;

Expand All @@ -45,15 +46,16 @@ public function registerBundles()
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
{
$loader->load(__DIR__ . '/config.yaml');
}

protected function configureRoutes(RouteCollectionBuilder $routes)
{
$controller = Controller::class;

$routes->add('/', "{$controller}::home");
$routes->add('/user/create', "{$controller}::createUser");
$routes->add('/user/view', "{$controller}::viewUser");
// Since symfony/framework-bundle 5.1: Not setting the "framework.router.utf8" configuration option
// is deprecated, it will default to "true" in version 6.0.
if (self::VERSION_ID >= 50100) {
$container->loadFromExtension('framework', [
'router' => [
'utf8' => false,
]
]);
}
}

public function getProjectDir()
Expand All @@ -66,3 +68,29 @@ public function getRootDir()
return __DIR__ . '/var';
}
}

// RouteCollectionBuilder is deprecated since symfony/routing 5.1
if (AbstractKernel::VERSION_ID >= 50100) {
class Kernel extends AbstractKernel {
protected function configureRoutes(RoutingConfigurator $routes): void
{
$controller = Controller::class;

$routes->add('home', '/')->controller("{$controller}::home");
$routes->add('create_user', '/user/create')->controller("{$controller}::createUser");
$routes->add('view_user', '/user/view')->controller("{$controller}::viewUser");
}
}
} else {
class Kernel extends AbstractKernel {
protected function configureRoutes(RouteCollectionBuilder $routes)
{
$controller = Controller::class;

$routes->add('/', "{$controller}::home");
$routes->add('/user/create', "{$controller}::createUser");
$routes->add('/user/view', "{$controller}::viewUser");
}
}
}

0 comments on commit e0de164

Please sign in to comment.