From 106c5ead8d4a3c6a0913773041f0f6db74633ad5 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Sat, 25 Jun 2022 11:17:43 +0200 Subject: [PATCH] Avoid deprecations for console commands (#1543) --- composer.json | 6 +++--- src/Command/ActivateUserCommand.php | 4 ++++ src/Command/ChangePasswordCommand.php | 4 ++++ src/Command/CreateUserCommand.php | 4 ++++ src/Command/DeactivateUserCommand.php | 4 ++++ src/Command/DemoteUserCommand.php | 4 ++++ src/Command/PromoteUserCommand.php | 4 ++++ tests/App/AppKernel.php | 8 ++++++++ tests/App/Resources/config/config.yaml | 1 + tests/App/Resources/config/config_sonata_block_v4.yaml | 2 ++ 10 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 tests/App/Resources/config/config_sonata_block_v4.yaml diff --git a/composer.json b/composer.json index 7c405825d..d3e596c8b 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "php": "^7.4 || ^8.0", "doctrine/collections": "^1.6", "doctrine/common": "^3.1", - "doctrine/persistence": "^2.1", + "doctrine/persistence": "^2.1 || ^3.0", "sonata-project/doctrine-extensions": "^1.13", "sonata-project/form-extensions": "^1.4", "sonata-project/twig-extensions": "^1.3", @@ -66,7 +66,7 @@ "psalm/plugin-phpunit": "^0.16", "psalm/plugin-symfony": "^3.0", "sonata-project/admin-bundle": "^4.9", - "sonata-project/block-bundle": "^4.0", + "sonata-project/block-bundle": "^4.11", "sonata-project/doctrine-orm-admin-bundle": "^4.0", "symfony/browser-kit": "^4.4 || ^5.4 || ^6.0", "symfony/console": "^4.4 || ^5.4 || ^6.0", @@ -76,7 +76,7 @@ }, "conflict": { "sonata-project/admin-bundle": "<4.9", - "sonata-project/block-bundle": "<4.0", + "sonata-project/block-bundle": "<4.11", "sonata-project/doctrine-orm-admin-bundle": "<4.0" }, "suggest": { diff --git a/src/Command/ActivateUserCommand.php b/src/Command/ActivateUserCommand.php index 90c25ec0d..420b16d99 100644 --- a/src/Command/ActivateUserCommand.php +++ b/src/Command/ActivateUserCommand.php @@ -14,6 +14,7 @@ namespace Sonata\UserBundle\Command; use Sonata\UserBundle\Model\UserManagerInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -22,8 +23,10 @@ /** * @internal */ +#[AsCommand(name: 'sonata:user:activate', description: 'Activate a user')] final class ActivateUserCommand extends Command { + // TODO: Remove static properties when support for Symfony < 6.0 is dropped. protected static $defaultName = 'sonata:user:activate'; protected static $defaultDescription = 'Activate a user'; @@ -41,6 +44,7 @@ protected function configure(): void \assert(null !== static::$defaultDescription); $this + // TODO: Remove setDescription when support for Symfony < 5.4 is dropped. ->setDescription(static::$defaultDescription) ->setDefinition([ new InputArgument('username', InputArgument::REQUIRED, 'The username'), diff --git a/src/Command/ChangePasswordCommand.php b/src/Command/ChangePasswordCommand.php index e9373638d..aa1dc1e03 100644 --- a/src/Command/ChangePasswordCommand.php +++ b/src/Command/ChangePasswordCommand.php @@ -14,6 +14,7 @@ namespace Sonata\UserBundle\Command; use Sonata\UserBundle\Model\UserManagerInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -22,8 +23,10 @@ /** * @internal */ +#[AsCommand(name: 'sonata:user:change-password', description: 'Change the password of a user')] final class ChangePasswordCommand extends Command { + // TODO: Remove static properties when support for Symfony < 6.0 is dropped. protected static $defaultName = 'sonata:user:change-password'; protected static $defaultDescription = 'Change the password of a user'; @@ -41,6 +44,7 @@ protected function configure(): void \assert(null !== static::$defaultDescription); $this + // TODO: Remove setDescription when support for Symfony < 5.4 is dropped. ->setDescription(static::$defaultDescription) ->setDefinition([ new InputArgument('username', InputArgument::REQUIRED, 'The username'), diff --git a/src/Command/CreateUserCommand.php b/src/Command/CreateUserCommand.php index 33d677d0f..e670acf6a 100644 --- a/src/Command/CreateUserCommand.php +++ b/src/Command/CreateUserCommand.php @@ -14,6 +14,7 @@ namespace Sonata\UserBundle\Command; use Sonata\UserBundle\Model\UserManagerInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -23,8 +24,10 @@ /** * @internal */ +#[AsCommand(name: 'sonata:user:create', description: 'Create a user')] final class CreateUserCommand extends Command { + // TODO: Remove static properties when support for Symfony < 6.0 is dropped. protected static $defaultName = 'sonata:user:create'; protected static $defaultDescription = 'Create a user'; @@ -42,6 +45,7 @@ protected function configure(): void \assert(null !== static::$defaultDescription); $this + // TODO: Remove setDescription when support for Symfony < 5.4 is dropped. ->setDescription(static::$defaultDescription) ->setDefinition([ new InputArgument('username', InputArgument::REQUIRED, 'The username'), diff --git a/src/Command/DeactivateUserCommand.php b/src/Command/DeactivateUserCommand.php index 9a8f3cf19..c19af4446 100644 --- a/src/Command/DeactivateUserCommand.php +++ b/src/Command/DeactivateUserCommand.php @@ -14,6 +14,7 @@ namespace Sonata\UserBundle\Command; use Sonata\UserBundle\Model\UserManagerInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -22,8 +23,10 @@ /** * @internal */ +#[AsCommand(name: 'sonata:user:deactivate', description: 'Deactivate a user')] final class DeactivateUserCommand extends Command { + // TODO: Remove static properties when support for Symfony < 6.0 is dropped. protected static $defaultName = 'sonata:user:deactivate'; protected static $defaultDescription = 'Deactivate a user'; @@ -41,6 +44,7 @@ protected function configure(): void \assert(null !== static::$defaultDescription); $this + // TODO: Remove setDescription when support for Symfony < 5.4 is dropped. ->setDescription(static::$defaultDescription) ->setDefinition([ new InputArgument('username', InputArgument::REQUIRED, 'The username'), diff --git a/src/Command/DemoteUserCommand.php b/src/Command/DemoteUserCommand.php index 4a2496249..1dc6fe87d 100644 --- a/src/Command/DemoteUserCommand.php +++ b/src/Command/DemoteUserCommand.php @@ -14,6 +14,7 @@ namespace Sonata\UserBundle\Command; use Sonata\UserBundle\Model\UserManagerInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -23,8 +24,10 @@ /** * @internal */ +#[AsCommand(name: 'sonata:user:demote', description: 'Demotes a user by removing a role')] final class DemoteUserCommand extends Command { + // TODO: Remove static properties when support for Symfony < 6.0 is dropped. protected static $defaultName = 'sonata:user:demote'; protected static $defaultDescription = 'Demotes a user by removing a role'; @@ -42,6 +45,7 @@ protected function configure(): void \assert(null !== static::$defaultDescription); $this + // TODO: Remove setDescription when support for Symfony < 5.4 is dropped. ->setDescription(static::$defaultDescription) ->setDefinition([ new InputArgument('username', InputArgument::REQUIRED, 'The username'), diff --git a/src/Command/PromoteUserCommand.php b/src/Command/PromoteUserCommand.php index fd309d6f4..ea91c1a39 100644 --- a/src/Command/PromoteUserCommand.php +++ b/src/Command/PromoteUserCommand.php @@ -14,6 +14,7 @@ namespace Sonata\UserBundle\Command; use Sonata\UserBundle\Model\UserManagerInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -23,8 +24,10 @@ /** * @internal */ +#[AsCommand(name: 'sonata:user:promote', description: 'Promotes a user by adding a role')] final class PromoteUserCommand extends Command { + // TODO: Remove static properties when support for Symfony < 6.0 is dropped. protected static $defaultName = 'sonata:user:promote'; protected static $defaultDescription = 'Promotes a user by adding a role'; @@ -42,6 +45,7 @@ protected function configure(): void \assert(null !== static::$defaultDescription); $this + // TODO: Remove setDescription when support for Symfony < 5.4 is dropped. ->setDescription(static::$defaultDescription) ->setDefinition([ new InputArgument('username', InputArgument::REQUIRED, 'The username'), diff --git a/tests/App/AppKernel.php b/tests/App/AppKernel.php index 293675dcd..9f64ff16d 100644 --- a/tests/App/AppKernel.php +++ b/tests/App/AppKernel.php @@ -17,6 +17,7 @@ use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; use Knp\Bundle\MenuBundle\KnpMenuBundle; use Sonata\AdminBundle\SonataAdminBundle; +use Sonata\BlockBundle\Cache\HttpCacheHandler; use Sonata\BlockBundle\SonataBlockBundle; use Sonata\Doctrine\Bridge\Symfony\SonataDoctrineBundle; use Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle; @@ -93,6 +94,9 @@ protected function configureRoutes($routes): void $routes->import(__DIR__.'/Resources/config/routing/routes.yaml'); } + /** + * @psalm-suppress DeprecatedClass + */ protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void { $loader->load(__DIR__.'/Resources/config/config.yaml'); @@ -103,6 +107,10 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa $loader->load(__DIR__.'/Resources/config/config_sf4.yaml'); } + if (class_exists(HttpCacheHandler::class)) { + $loader->load(__DIR__.'/Resources/config/config_sonata_block_v4.yaml'); + } + $container->setParameter('app.base_dir', $this->getBaseDir()); } diff --git a/tests/App/Resources/config/config.yaml b/tests/App/Resources/config/config.yaml index 7abe41257..b27490029 100644 --- a/tests/App/Resources/config/config.yaml +++ b/tests/App/Resources/config/config.yaml @@ -8,6 +8,7 @@ framework: enabled: true translator: enabled: true + http_method_override: false security: role_hierarchy: null diff --git a/tests/App/Resources/config/config_sonata_block_v4.yaml b/tests/App/Resources/config/config_sonata_block_v4.yaml new file mode 100644 index 000000000..b83465ccb --- /dev/null +++ b/tests/App/Resources/config/config_sonata_block_v4.yaml @@ -0,0 +1,2 @@ +sonata_block: + http_cache: false