Skip to content

Commit

Permalink
Avoid deprecations for console commands (#1543)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed Jun 25, 2022
1 parent f73376b commit 106c5ea
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 3 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
4 changes: 4 additions & 0 deletions src/Command/ActivateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';

Expand All @@ -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'),
Expand Down
4 changes: 4 additions & 0 deletions src/Command/ChangePasswordCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';

Expand All @@ -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'),
Expand Down
4 changes: 4 additions & 0 deletions src/Command/CreateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';

Expand All @@ -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'),
Expand Down
4 changes: 4 additions & 0 deletions src/Command/DeactivateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';

Expand All @@ -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'),
Expand Down
4 changes: 4 additions & 0 deletions src/Command/DemoteUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';

Expand All @@ -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'),
Expand Down
4 changes: 4 additions & 0 deletions src/Command/PromoteUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';

Expand All @@ -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'),
Expand Down
8 changes: 8 additions & 0 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand All @@ -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());
}

Expand Down
1 change: 1 addition & 0 deletions tests/App/Resources/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ framework:
enabled: true
translator:
enabled: true
http_method_override: false

security:
role_hierarchy: null
Expand Down
2 changes: 2 additions & 0 deletions tests/App/Resources/config/config_sonata_block_v4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sonata_block:
http_cache: false

0 comments on commit 106c5ea

Please sign in to comment.