diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index aa6e7b070..057c48b0f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -48,11 +48,6 @@ jobs: dependencies: lowest allowed-to-fail: false variant: normal - - php-version: '8.2' - dependencies: highest - allowed-to-fail: false - symfony-require: 4.4.* - variant: symfony/symfony:"4.4.*" - php-version: '8.2' dependencies: highest allowed-to-fail: false diff --git a/composer.json b/composer.json index cc7ca91e7..ce1c4a93e 100644 --- a/composer.json +++ b/composer.json @@ -27,25 +27,25 @@ "sonata-project/doctrine-extensions": "^1.13 || ^2.0", "sonata-project/form-extensions": "^1.4", "sonata-project/twig-extensions": "^1.3 || ^2.0", - "symfony/config": "^4.4.11 || ^5.4 || ^6.2", - "symfony/console": "^4.4 || ^5.4 || ^6.2", - "symfony/dependency-injection": "^4.4 || ^5.4 || ^6.2", - "symfony/event-dispatcher": "^4.4 || ^5.4 || ^6.2", - "symfony/form": "^4.4.20 || ^5.4 || ^6.2", - "symfony/framework-bundle": "^4.4 || ^5.4 || ^6.2", - "symfony/http-foundation": "^4.4 || ^5.4 || ^6.2", - "symfony/http-kernel": "^4.4 || ^5.4 || ^6.2", - "symfony/mailer": "^4.4 || ^5.4 || ^6.2", - "symfony/mime": "^4.4.10 || ^5.4 || ^6.2", - "symfony/options-resolver": "^4.4 || ^5.4 || ^6.2", - "symfony/routing": "^4.4 || ^5.4 || ^6.2", + "symfony/config": "^5.4 || ^6.2", + "symfony/console": "^5.4 || ^6.2", + "symfony/dependency-injection": "^5.4 || ^6.2", + "symfony/event-dispatcher": "^5.4 || ^6.2", + "symfony/form": "^5.4 || ^6.2", + "symfony/framework-bundle": "^5.4 || ^6.2", + "symfony/http-foundation": "^5.4 || ^6.2", + "symfony/http-kernel": "^5.4 || ^6.2", + "symfony/mailer": "^5.4 || ^6.2", + "symfony/mime": "^5.4 || ^6.2", + "symfony/options-resolver": "^5.4 || ^6.2", + "symfony/routing": "^5.4 || ^6.2", "symfony/security-acl": "^3.0", - "symfony/security-core": "^4.4.23 || ^5.4 || ^6.2", - "symfony/security-csrf": "^4.4 || ^5.4 || ^6.2", - "symfony/translation": "^4.4 || ^5.4 || ^6.2", - "symfony/translation-contracts": "^1.1 || ^2.5 || ^3.0", - "symfony/validator": "^4.4 || ^5.4 || ^6.2", - "twig/twig": "^2.14 || ^3.0" + "symfony/security-core": "^5.4 || ^6.2", + "symfony/security-csrf": "^5.4 || ^6.2", + "symfony/translation": "^5.4 || ^6.2", + "symfony/translation-contracts": "^2.5 || ^3.0", + "symfony/validator": "^5.4 || ^6.2", + "twig/twig": "^3.0" }, "require-dev": { "dama/doctrine-test-bundle": "^7.0", @@ -63,17 +63,17 @@ "phpstan/phpstan-symfony": "^1.0", "phpunit/phpunit": "^9.5", "psalm/plugin-phpunit": "^0.18", - "psalm/plugin-symfony": "^4.0 || ^5.0", + "psalm/plugin-symfony": "^5.0", "rector/rector": "^0.15", "sonata-project/admin-bundle": "^4.20", "sonata-project/block-bundle": "^4.11", "sonata-project/doctrine-orm-admin-bundle": "^4.0", - "symfony/browser-kit": "^4.4 || ^5.4 || ^6.2", - "symfony/console": "^4.4 || ^5.4 || ^6.2", - "symfony/filesystem": "^4.4 || ^5.4 || ^6.2", - "symfony/intl": "^4.4 || ^5.4 || ^6.2", + "symfony/browser-kit": "^5.4 || ^6.2", + "symfony/console": "^5.4 || ^6.2", + "symfony/filesystem": "^5.4 || ^6.2", + "symfony/intl": "^5.4 || ^6.2", "symfony/phpunit-bridge": "^6.2", - "vimeo/psalm": "^4.9.2 || ^5.0" + "vimeo/psalm": "^5.0" }, "conflict": { "sonata-project/admin-bundle": "<4.20", diff --git a/psalm-baseline.xml b/psalm-baseline.xml deleted file mode 100644 index dd62d36ab..000000000 --- a/psalm-baseline.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - UserPasswordEncoderInterface|UserPasswordHasherInterface - - - - - UserPasswordEncoderInterface|UserPasswordHasherInterface - - - diff --git a/psalm.xml b/psalm.xml index b8469b60c..16058b6f0 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,5 +1,5 @@ - + diff --git a/src/Command/ActivateUserCommand.php b/src/Command/ActivateUserCommand.php index 2fad45a2d..0d4601080 100644 --- a/src/Command/ActivateUserCommand.php +++ b/src/Command/ActivateUserCommand.php @@ -26,10 +26,6 @@ #[AsCommand(name: 'sonata:user:activate', description: 'Activate a user')] final class ActivateUserCommand extends Command { - // TODO: Remove static properties when support for Symfony < 5.4 is dropped. - protected static $defaultName = 'sonata:user:activate'; - protected static $defaultDescription = 'Activate a user'; - public function __construct(private UserManagerInterface $userManager) { parent::__construct(); @@ -37,11 +33,7 @@ public function __construct(private UserManagerInterface $userManager) 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 e47053122..435bbf35f 100644 --- a/src/Command/ChangePasswordCommand.php +++ b/src/Command/ChangePasswordCommand.php @@ -26,10 +26,6 @@ #[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 < 5.4 is dropped. - protected static $defaultName = 'sonata:user:change-password'; - protected static $defaultDescription = 'Change the password of a user'; - public function __construct(private UserManagerInterface $userManager) { parent::__construct(); @@ -37,11 +33,7 @@ public function __construct(private UserManagerInterface $userManager) 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'), new InputArgument('password', InputArgument::REQUIRED, 'The password'), diff --git a/src/Command/CreateUserCommand.php b/src/Command/CreateUserCommand.php index 0269793af..256932661 100644 --- a/src/Command/CreateUserCommand.php +++ b/src/Command/CreateUserCommand.php @@ -27,10 +27,6 @@ #[AsCommand(name: 'sonata:user:create', description: 'Create a user')] final class CreateUserCommand extends Command { - // TODO: Remove static properties when support for Symfony < 5.4 is dropped. - protected static $defaultName = 'sonata:user:create'; - protected static $defaultDescription = 'Create a user'; - public function __construct(private UserManagerInterface $userManager) { parent::__construct(); @@ -38,11 +34,7 @@ public function __construct(private UserManagerInterface $userManager) 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'), new InputArgument('email', InputArgument::REQUIRED, 'The email'), diff --git a/src/Command/DeactivateUserCommand.php b/src/Command/DeactivateUserCommand.php index 4c5c01dd4..253b63e9b 100644 --- a/src/Command/DeactivateUserCommand.php +++ b/src/Command/DeactivateUserCommand.php @@ -26,10 +26,6 @@ #[AsCommand(name: 'sonata:user:deactivate', description: 'Deactivate a user')] final class DeactivateUserCommand extends Command { - // TODO: Remove static properties when support for Symfony < 5.4 is dropped. - protected static $defaultName = 'sonata:user:deactivate'; - protected static $defaultDescription = 'Deactivate a user'; - public function __construct(private UserManagerInterface $userManager) { parent::__construct(); @@ -37,11 +33,7 @@ public function __construct(private UserManagerInterface $userManager) 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 7af817d4c..88503d6be 100644 --- a/src/Command/DemoteUserCommand.php +++ b/src/Command/DemoteUserCommand.php @@ -27,10 +27,6 @@ #[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 < 5.4 is dropped. - protected static $defaultName = 'sonata:user:demote'; - protected static $defaultDescription = 'Demotes a user by removing a role'; - public function __construct(private UserManagerInterface $userManager) { parent::__construct(); @@ -38,11 +34,7 @@ public function __construct(private UserManagerInterface $userManager) 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'), new InputArgument('role', InputArgument::OPTIONAL, 'The role'), diff --git a/src/Command/PromoteUserCommand.php b/src/Command/PromoteUserCommand.php index 9dd9e8cf4..0a16fa246 100644 --- a/src/Command/PromoteUserCommand.php +++ b/src/Command/PromoteUserCommand.php @@ -27,10 +27,6 @@ #[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 < 5.4 is dropped. - protected static $defaultName = 'sonata:user:promote'; - protected static $defaultDescription = 'Promotes a user by adding a role'; - public function __construct(private UserManagerInterface $userManager) { parent::__construct(); @@ -38,11 +34,7 @@ public function __construct(private UserManagerInterface $userManager) 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'), new InputArgument('role', InputArgument::OPTIONAL, 'The role'), diff --git a/src/DependencyInjection/SonataUserExtension.php b/src/DependencyInjection/SonataUserExtension.php index c3b1d9144..c63863210 100644 --- a/src/DependencyInjection/SonataUserExtension.php +++ b/src/DependencyInjection/SonataUserExtension.php @@ -78,9 +78,7 @@ public function load(array $configs, ContainerBuilder $container): void $this->configureResetting($config['resetting'], $container); } - if ($this->isConfigEnabled($container, $config['impersonating'])) { - $this->configureImpersonation($config['impersonating'], $container); - } + $this->configureImpersonation($config['impersonating'], $container); } /** @@ -186,7 +184,7 @@ private function configureImpersonation(array $config, ContainerBuilder $contain { $container->getDefinition('sonata.user.twig.global') ->replaceArgument(2, $config['enabled']) - ->replaceArgument(3, $config['route']) - ->replaceArgument(4, $config['parameters']); + ->replaceArgument(3, $config['route'] ?? '') + ->replaceArgument(4, $config['parameters'] ?? []); } } diff --git a/src/Document/UserManager.php b/src/Document/UserManager.php index a432e19a2..22db80ca6 100644 --- a/src/Document/UserManager.php +++ b/src/Document/UserManager.php @@ -19,7 +19,6 @@ use Sonata\UserBundle\Model\UserManagerInterface; use Sonata\UserBundle\Util\CanonicalFieldsUpdaterInterface; use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; -use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; /** * @author Hugo Briand @@ -29,25 +28,17 @@ final class UserManager extends BaseDocumentManager implements UserManagerInterface { /** - * TODO: Simplify this once support for Symfony 4.4 is dropped. - * - * @param UserPasswordEncoderInterface|UserPasswordHasherInterface $userPasswordHasher - * * @phpstan-param class-string $class */ public function __construct( string $class, ManagerRegistry $registry, private CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater, - // @phpstan-ignore-next-line - private object $userPasswordHasher + private UserPasswordHasherInterface $userPasswordHasher ) { parent::__construct($class, $registry); } - /** - * @psalm-suppress UndefinedDocblockClass - */ public function updatePassword(UserInterface $user): void { $plainPassword = $user->getPlainPassword(); @@ -56,12 +47,7 @@ public function updatePassword(UserInterface $user): void return; } - if ($this->userPasswordHasher instanceof UserPasswordHasherInterface) { - $password = $this->userPasswordHasher->hashPassword($user, $plainPassword); - } else { - // @phpstan-ignore-next-line - $password = $this->userPasswordHasher->encodePassword($user, $plainPassword); - } + $password = $this->userPasswordHasher->hashPassword($user, $plainPassword); $user->setPassword($password); $user->eraseCredentials(); diff --git a/src/Entity/UserManager.php b/src/Entity/UserManager.php index 260e4159b..1cc128212 100644 --- a/src/Entity/UserManager.php +++ b/src/Entity/UserManager.php @@ -19,7 +19,6 @@ use Sonata\UserBundle\Model\UserManagerInterface; use Sonata\UserBundle\Util\CanonicalFieldsUpdaterInterface; use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; -use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; /** * @author Hugo Briand @@ -29,25 +28,17 @@ final class UserManager extends BaseEntityManager implements UserManagerInterface { /** - * TODO: Simplify this once support for Symfony 4.4 is dropped. - * - * @param UserPasswordEncoderInterface|UserPasswordHasherInterface $userPasswordHasher - * * @phpstan-param class-string $class */ public function __construct( string $class, ManagerRegistry $registry, private CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater, - // @phpstan-ignore-next-line - private object $userPasswordHasher + private UserPasswordHasherInterface $userPasswordHasher ) { parent::__construct($class, $registry); } - /** - * @psalm-suppress UndefinedDocblockClass - */ public function updatePassword(UserInterface $user): void { $plainPassword = $user->getPlainPassword(); @@ -56,12 +47,7 @@ public function updatePassword(UserInterface $user): void return; } - if ($this->userPasswordHasher instanceof UserPasswordHasherInterface) { - $password = $this->userPasswordHasher->hashPassword($user, $plainPassword); - } else { - // @phpstan-ignore-next-line - $password = $this->userPasswordHasher->encodePassword($user, $plainPassword); - } + $password = $this->userPasswordHasher->hashPassword($user, $plainPassword); $user->setPassword($password); $user->eraseCredentials(); diff --git a/src/Model/BCPasswordAuthenticatedUserInterface.php b/src/Model/BCPasswordAuthenticatedUserInterface.php deleted file mode 100644 index ba126eb13..000000000 --- a/src/Model/BCPasswordAuthenticatedUserInterface.php +++ /dev/null @@ -1,29 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Sonata\UserBundle\Model; - -use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; - -/* TODO: Simplify this when dropping support for Symfony 4 */ -if (interface_exists(PasswordAuthenticatedUserInterface::class)) { - /** @psalm-suppress UnrecognizedStatement */ - interface BCPasswordAuthenticatedUserInterface extends PasswordAuthenticatedUserInterface - { - } -} else { - /** @psalm-suppress UnrecognizedStatement */ - interface BCPasswordAuthenticatedUserInterface - { - } -} diff --git a/src/Model/UserInterface.php b/src/Model/UserInterface.php index 0d810b706..e63ab52d7 100644 --- a/src/Model/UserInterface.php +++ b/src/Model/UserInterface.php @@ -14,9 +14,10 @@ namespace Sonata\UserBundle\Model; use Symfony\Component\Security\Core\User\EquatableInterface; +use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface as SymfonyUserInterface; -interface UserInterface extends SymfonyUserInterface, EquatableInterface, BCPasswordAuthenticatedUserInterface +interface UserInterface extends SymfonyUserInterface, EquatableInterface, PasswordAuthenticatedUserInterface { public const ROLE_DEFAULT = 'ROLE_USER'; public const ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN'; @@ -49,7 +50,7 @@ public function setPlainPassword(?string $password): void; public function setPassword(?string $password): void; /** - * TODO: Remove this method when dropping support for Symfony 4. + * TODO: Remove this method when dropping support for Symfony 5. */ public function getPassword(): ?string; diff --git a/src/Resources/config/actions.php b/src/Resources/config/actions.php index af8aadfdb..1bc50cf71 100644 --- a/src/Resources/config/actions.php +++ b/src/Resources/config/actions.php @@ -11,70 +11,68 @@ * file that was distributed with this source code. */ +namespace Symfony\Component\DependencyInjection\Loader\Configurator; + use Sonata\UserBundle\Action\CheckEmailAction; use Sonata\UserBundle\Action\CheckLoginAction; use Sonata\UserBundle\Action\LoginAction; use Sonata\UserBundle\Action\LogoutAction; use Sonata\UserBundle\Action\RequestAction; use Sonata\UserBundle\Action\ResetAction; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { - // Use "service" function for creating references to services when dropping support for Symfony 4.4 - // Use "param" function for creating references to parameters when dropping support for Symfony 5.1 $containerConfigurator->services() ->set('sonata.user.action.request', RequestAction::class) ->public() ->args([ - new ReferenceConfigurator('twig'), - new ReferenceConfigurator('router'), - new ReferenceConfigurator('security.authorization_checker'), - new ReferenceConfigurator('sonata.admin.pool'), - new ReferenceConfigurator('sonata.admin.global_template_registry'), - new ReferenceConfigurator('form.factory'), - new ReferenceConfigurator('sonata.user.manager.user'), - new ReferenceConfigurator('sonata.user.mailer'), - new ReferenceConfigurator('sonata.user.util.token_generator'), - 0, + service('twig'), + service('router'), + service('security.authorization_checker'), + service('sonata.admin.pool'), + service('sonata.admin.global_template_registry'), + service('form.factory'), + service('sonata.user.manager.user'), + service('sonata.user.mailer'), + service('sonata.user.util.token_generator'), + abstract_arg('retry ttl'), ]) ->set('sonata.user.action.check_email', CheckEmailAction::class) ->public() ->args([ - new ReferenceConfigurator('twig'), - new ReferenceConfigurator('router'), - new ReferenceConfigurator('sonata.admin.pool'), - new ReferenceConfigurator('sonata.admin.global_template_registry'), - 0, + service('twig'), + service('router'), + service('sonata.admin.pool'), + service('sonata.admin.global_template_registry'), + abstract_arg('token ttl'), ]) ->set('sonata.user.action.reset', ResetAction::class) ->public() ->args([ - new ReferenceConfigurator('twig'), - new ReferenceConfigurator('router'), - new ReferenceConfigurator('security.authorization_checker'), - new ReferenceConfigurator('sonata.admin.pool'), - new ReferenceConfigurator('sonata.admin.global_template_registry'), - new ReferenceConfigurator('form.factory'), - new ReferenceConfigurator('sonata.user.manager.user'), - new ReferenceConfigurator('translator'), - 0, + service('twig'), + service('router'), + service('security.authorization_checker'), + service('sonata.admin.pool'), + service('sonata.admin.global_template_registry'), + service('form.factory'), + service('sonata.user.manager.user'), + service('translator'), + abstract_arg('token ttl'), ]) ->set('sonata.user.action.login', LoginAction::class) ->public() ->args([ - new ReferenceConfigurator('twig'), - new ReferenceConfigurator('router'), - new ReferenceConfigurator('security.authentication_utils'), - new ReferenceConfigurator('sonata.admin.pool'), - new ReferenceConfigurator('sonata.admin.global_template_registry'), - new ReferenceConfigurator('security.token_storage'), - new ReferenceConfigurator('translator'), - (new ReferenceConfigurator('security.csrf.token_manager'))->nullOnInvalid(), + service('twig'), + service('router'), + service('security.authentication_utils'), + service('sonata.admin.pool'), + service('sonata.admin.global_template_registry'), + service('security.token_storage'), + service('translator'), + service('security.csrf.token_manager')->nullOnInvalid(), ]) ->set('sonata.user.action.check_login', CheckLoginAction::class) diff --git a/src/Resources/config/admin.php b/src/Resources/config/admin.php index fbc236c84..33b02daa3 100644 --- a/src/Resources/config/admin.php +++ b/src/Resources/config/admin.php @@ -11,52 +11,50 @@ * file that was distributed with this source code. */ +namespace Symfony\Component\DependencyInjection\Loader\Configurator; + use Sonata\UserBundle\Form\Type\RolesMatrixType; use Sonata\UserBundle\Security\RolesBuilder\AdminRolesBuilder; use Sonata\UserBundle\Security\RolesBuilder\MatrixRolesBuilder; use Sonata\UserBundle\Security\RolesBuilder\SecurityRolesBuilder; use Sonata\UserBundle\Twig\RolesMatrixExtension; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { - // Use "service" function for creating references to services when dropping support for Symfony 4.4 - // Use "param" function for creating references to parameters when dropping support for Symfony 5.1 $containerConfigurator->services() ->set('sonata.user.matrix_roles_builder', MatrixRolesBuilder::class) ->args([ - new ReferenceConfigurator('security.token_storage'), - new ReferenceConfigurator('sonata.user.admin_roles_builder'), - new ReferenceConfigurator('sonata.user.security_roles_builder'), + service('security.token_storage'), + service('sonata.user.admin_roles_builder'), + service('sonata.user.security_roles_builder'), ]) ->set('sonata.user.admin_roles_builder', AdminRolesBuilder::class) ->args([ - new ReferenceConfigurator('security.authorization_checker'), - new ReferenceConfigurator('sonata.admin.pool'), - new ReferenceConfigurator('sonata.admin.configuration'), - new ReferenceConfigurator('translator'), + service('security.authorization_checker'), + service('sonata.admin.pool'), + service('sonata.admin.configuration'), + service('translator'), ]) ->set('sonata.user.security_roles_builder', SecurityRolesBuilder::class) ->args([ - new ReferenceConfigurator('security.authorization_checker'), - new ReferenceConfigurator('sonata.admin.configuration'), - new ReferenceConfigurator('translator'), - '%security.role_hierarchy.roles%', + service('security.authorization_checker'), + service('sonata.admin.configuration'), + service('translator'), + param('security.role_hierarchy.roles'), ]) ->set('sonata.user.form.roles_matrix_type', RolesMatrixType::class) ->public() ->tag('form.type') ->args([ - new ReferenceConfigurator('sonata.user.matrix_roles_builder'), + service('sonata.user.matrix_roles_builder'), ]) ->set('sonata.user.roles_matrix_extension', RolesMatrixExtension::class) ->tag('twig.extension') ->args([ - new ReferenceConfigurator('sonata.user.matrix_roles_builder'), + service('sonata.user.matrix_roles_builder'), ]); }; diff --git a/src/Resources/config/admin_mongodb.php b/src/Resources/config/admin_mongodb.php index 474f7ad11..825fc76af 100644 --- a/src/Resources/config/admin_mongodb.php +++ b/src/Resources/config/admin_mongodb.php @@ -11,17 +11,15 @@ * file that was distributed with this source code. */ -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; +namespace Symfony\Component\DependencyInjection\Loader\Configurator; return static function (ContainerConfigurator $containerConfigurator): void { - // Use "param" function for creating references to parameters when dropping support for Symfony 5.1 $containerConfigurator->services() ->set('sonata.user.admin.user') ->tag('sonata.admin', [ - 'model_class' => '%sonata.user.user.class%', - 'controller' => '%sonata.user.admin.user.controller%', + 'model_class' => (string) param('sonata.user.user.class'), + 'controller' => (string) param('sonata.user.admin.user.controller'), 'manager_type' => 'doctrine_mongodb', 'group' => 'sonata_user', 'label' => 'users', @@ -30,6 +28,6 @@ 'icon' => '', ]) ->args([ - new ReferenceConfigurator('sonata.user.manager.user'), + service('sonata.user.manager.user'), ]); }; diff --git a/src/Resources/config/admin_orm.php b/src/Resources/config/admin_orm.php index 42d211fdb..1c396b836 100644 --- a/src/Resources/config/admin_orm.php +++ b/src/Resources/config/admin_orm.php @@ -11,17 +11,15 @@ * file that was distributed with this source code. */ -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; +namespace Symfony\Component\DependencyInjection\Loader\Configurator; return static function (ContainerConfigurator $containerConfigurator): void { - // Use "param" function for creating references to parameters when dropping support for Symfony 5.1 $containerConfigurator->services() ->set('sonata.user.admin.user') ->tag('sonata.admin', [ - 'model_class' => '%sonata.user.user.class%', - 'controller' => '%sonata.user.admin.user.controller%', + 'model_class' => (string) param('sonata.user.user.class'), + 'controller' => (string) param('sonata.user.admin.user.controller'), 'manager_type' => 'orm', 'group' => 'sonata_user', 'label' => 'users', @@ -30,6 +28,6 @@ 'icon' => '', ]) ->args([ - new ReferenceConfigurator('sonata.user.manager.user'), + service('sonata.user.manager.user'), ]); }; diff --git a/src/Resources/config/commands.php b/src/Resources/config/commands.php index 66f627313..9886b7a7b 100644 --- a/src/Resources/config/commands.php +++ b/src/Resources/config/commands.php @@ -11,52 +11,51 @@ * file that was distributed with this source code. */ +namespace Symfony\Component\DependencyInjection\Loader\Configurator; + use Sonata\UserBundle\Command\ActivateUserCommand; use Sonata\UserBundle\Command\ChangePasswordCommand; use Sonata\UserBundle\Command\CreateUserCommand; use Sonata\UserBundle\Command\DeactivateUserCommand; use Sonata\UserBundle\Command\DemoteUserCommand; use Sonata\UserBundle\Command\PromoteUserCommand; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { - // Use "service" function for creating references to services when dropping support for Symfony 4.4 $containerConfigurator->services() ->set('sonata.user.command.activate_user', ActivateUserCommand::class) ->tag('console.command') ->args([ - new ReferenceConfigurator('sonata.user.manager.user'), + service('sonata.user.manager.user'), ]) ->set('sonata.user.command.change_password', ChangePasswordCommand::class) ->tag('console.command') ->args([ - new ReferenceConfigurator('sonata.user.manager.user'), + service('sonata.user.manager.user'), ]) ->set('sonata.user.command.create_user', CreateUserCommand::class) ->tag('console.command') ->args([ - new ReferenceConfigurator('sonata.user.manager.user'), + service('sonata.user.manager.user'), ]) ->set('sonata.user.command.deactivate_user', DeactivateUserCommand::class) ->tag('console.command') ->args([ - new ReferenceConfigurator('sonata.user.manager.user'), + service('sonata.user.manager.user'), ]) ->set('sonata.user.command.promote_user', PromoteUserCommand::class) ->tag('console.command') ->args([ - new ReferenceConfigurator('sonata.user.manager.user'), + service('sonata.user.manager.user'), ]) ->set('sonata.user.command.demote_user', DemoteUserCommand::class) ->tag('console.command') ->args([ - new ReferenceConfigurator('sonata.user.manager.user'), + service('sonata.user.manager.user'), ]); }; diff --git a/src/Resources/config/form.php b/src/Resources/config/form.php index 59288e3b8..7792cde34 100644 --- a/src/Resources/config/form.php +++ b/src/Resources/config/form.php @@ -11,19 +11,18 @@ * file that was distributed with this source code. */ +namespace Symfony\Component\DependencyInjection\Loader\Configurator; + use Sonata\UserBundle\Form\Type\ResetPasswordRequestFormType; use Sonata\UserBundle\Form\Type\ResettingFormType; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { - // Use "service" function for creating references to services when dropping support for Symfony 4.4 - // Use "param" function for creating references to parameters when dropping support for Symfony 5.1 $containerConfigurator->services() ->set('sonata.user.form.type.resetting', ResettingFormType::class) ->tag('form.type', ['alias' => 'sonata_user_resetting']) ->args([ - '%sonata.user.user.class%', + param('sonata.user.user.class'), ]) ->set('sonata.user.form.type.reset_password_request', ResetPasswordRequestFormType::class) diff --git a/src/Resources/config/listener.php b/src/Resources/config/listener.php index 827184b55..8c42f5b6a 100644 --- a/src/Resources/config/listener.php +++ b/src/Resources/config/listener.php @@ -11,17 +11,16 @@ * file that was distributed with this source code. */ +namespace Symfony\Component\DependencyInjection\Loader\Configurator; + use Sonata\UserBundle\Listener\LastLoginListener; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { - // Use "service" function for creating references to services when dropping support for Symfony 4 $containerConfigurator->services() ->set('sonata.user.listener.last_login', LastLoginListener::class) ->tag('kernel.event_subscriber') ->args([ - new ReferenceConfigurator('sonata.user.manager.user'), + service('sonata.user.manager.user'), ]); }; diff --git a/src/Resources/config/mailer.php b/src/Resources/config/mailer.php index c6a6c6ec3..a38083db1 100644 --- a/src/Resources/config/mailer.php +++ b/src/Resources/config/mailer.php @@ -11,21 +11,19 @@ * file that was distributed with this source code. */ +namespace Symfony\Component\DependencyInjection\Loader\Configurator; + use Sonata\UserBundle\Mailer\Mailer; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { - // Use "service" function for creating references to services when dropping support for Symfony 4 - // Use "param" function for creating references to parameters when dropping support for Symfony 5.1 $containerConfigurator->services() ->set('sonata.user.mailer.default', Mailer::class) ->args([ - new ReferenceConfigurator('router'), - new ReferenceConfigurator('twig'), - new ReferenceConfigurator('mailer'), - [], - '', + service('router'), + service('twig'), + service('mailer'), + abstract_arg('from email'), + abstract_arg('email template'), ]); }; diff --git a/src/Resources/config/mongodb.php b/src/Resources/config/mongodb.php index 00523db2e..c2825e49f 100644 --- a/src/Resources/config/mongodb.php +++ b/src/Resources/config/mongodb.php @@ -11,34 +11,26 @@ * file that was distributed with this source code. */ +namespace Symfony\Component\DependencyInjection\Loader\Configurator; + use Sonata\UserBundle\Document\UserManager; use Sonata\UserBundle\Listener\UserListener; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; -use Symfony\Component\Security\Http\Authentication\AuthenticatorManager; return static function (ContainerConfigurator $containerConfigurator): void { - /** - * TODO: Simplify this when dropping support for Symfony 4. - */ - $passwordHasherId = class_exists(AuthenticatorManager::class) ? 'security.password_hasher' : 'security.password_encoder'; - - // Use "service" function for creating references to services when dropping support for Symfony 4 - // Use "param" function for creating references to parameters when dropping support for Symfony 5.1 $containerConfigurator->services() ->set('sonata.user.manager.user', UserManager::class) ->args([ - '%sonata.user.user.class%', - new ReferenceConfigurator('doctrine_mongodb'), - new ReferenceConfigurator('sonata.user.util.canonical_fields_updater'), - new ReferenceConfigurator($passwordHasherId), + param('sonata.user.user.class'), + service('doctrine_mongodb'), + service('sonata.user.util.canonical_fields_updater'), + service('security.password_hasher'), ]) ->set('sonata.user.listener.user', UserListener::class) ->tag('doctrine_mongodb.odm.event_subscriber') ->args([ - new ReferenceConfigurator('sonata.user.util.canonical_fields_updater'), - new ReferenceConfigurator('sonata.user.manager.user'), + service('sonata.user.util.canonical_fields_updater'), + service('sonata.user.manager.user'), ]); }; diff --git a/src/Resources/config/orm.php b/src/Resources/config/orm.php index 9881aae4f..38e0d752e 100644 --- a/src/Resources/config/orm.php +++ b/src/Resources/config/orm.php @@ -11,34 +11,26 @@ * file that was distributed with this source code. */ +namespace Symfony\Component\DependencyInjection\Loader\Configurator; + use Sonata\UserBundle\Entity\UserManager; use Sonata\UserBundle\Listener\UserListener; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; -use Symfony\Component\Security\Http\Authentication\AuthenticatorManager; return static function (ContainerConfigurator $containerConfigurator): void { - /** - * TODO: Simplify this when dropping support for Symfony 4. - */ - $passwordHasherId = class_exists(AuthenticatorManager::class) ? 'security.password_hasher' : 'security.password_encoder'; - - // Use "service" function for creating references to services when dropping support for Symfony 4 - // Use "param" function for creating references to parameters when dropping support for Symfony 5.1 $containerConfigurator->services() ->set('sonata.user.manager.user', UserManager::class) ->args([ - '%sonata.user.user.class%', - new ReferenceConfigurator('doctrine'), - new ReferenceConfigurator('sonata.user.util.canonical_fields_updater'), - new ReferenceConfigurator($passwordHasherId), + param('sonata.user.user.class'), + service('doctrine'), + service('sonata.user.util.canonical_fields_updater'), + service('security.password_hasher'), ]) ->set('sonata.user.listener.user', UserListener::class) ->tag('doctrine.event_subscriber') ->args([ - new ReferenceConfigurator('sonata.user.util.canonical_fields_updater'), - new ReferenceConfigurator('sonata.user.manager.user'), + service('sonata.user.util.canonical_fields_updater'), + service('sonata.user.manager.user'), ]); }; diff --git a/src/Resources/config/security.php b/src/Resources/config/security.php index 5bc1750f2..d51afc6b0 100644 --- a/src/Resources/config/security.php +++ b/src/Resources/config/security.php @@ -11,16 +11,15 @@ * file that was distributed with this source code. */ +namespace Symfony\Component\DependencyInjection\Loader\Configurator; + use Sonata\UserBundle\Security\UserProvider; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { - // Use "service" function for creating references to services when dropping support for Symfony 4 $containerConfigurator->services() ->set('sonata.user.security.user_provider', UserProvider::class) ->args([ - new ReferenceConfigurator('sonata.user.manager.user'), + service('sonata.user.manager.user'), ]); }; diff --git a/src/Resources/config/security_acl.php b/src/Resources/config/security_acl.php index 9db446e49..331fae37f 100644 --- a/src/Resources/config/security_acl.php +++ b/src/Resources/config/security_acl.php @@ -11,22 +11,21 @@ * file that was distributed with this source code. */ +namespace Symfony\Component\DependencyInjection\Loader\Configurator; + use Sonata\UserBundle\Security\Authorization\Voter\UserAclVoter; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { - // Use "service" function for creating references to services when dropping support for Symfony 4 $containerConfigurator->services() ->set('security.acl.voter.user_permissions', UserAclVoter::class) ->tag('monolog.logger', ['channel' => 'security']) ->tag('security.voter', ['priority' => 255]) ->args([ - new ReferenceConfigurator('security.acl.provider'), - new ReferenceConfigurator('security.acl.object_identity_retrieval_strategy'), - new ReferenceConfigurator('security.acl.security_identity_retrieval_strategy'), - new ReferenceConfigurator('security.acl.permission.map'), - (new ReferenceConfigurator('logger'))->nullOnInvalid(), + service('security.acl.provider'), + service('security.acl.object_identity_retrieval_strategy'), + service('security.acl.security_identity_retrieval_strategy'), + service('security.acl.permission.map'), + service('logger')->nullOnInvalid(), ]); }; diff --git a/src/Resources/config/twig.php b/src/Resources/config/twig.php index c227b1be0..6695113af 100644 --- a/src/Resources/config/twig.php +++ b/src/Resources/config/twig.php @@ -11,20 +11,19 @@ * file that was distributed with this source code. */ +namespace Symfony\Component\DependencyInjection\Loader\Configurator; + use Sonata\UserBundle\Twig\GlobalVariables; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { - // Use "service" function for creating references to services when dropping support for Symfony 4 $containerConfigurator->services() ->set('sonata.user.twig.global', GlobalVariables::class) ->args([ - (new ReferenceConfigurator('sonata.admin.pool'))->nullOnInvalid(), - '', - false, - '', - [], + service('sonata.admin.pool')->nullOnInvalid(), + abstract_arg('default avatar'), + abstract_arg('impersonating enabled'), + abstract_arg('impersonating route'), + abstract_arg('impersonating route parameters'), ]); }; diff --git a/src/Resources/config/util.php b/src/Resources/config/util.php index 549566502..5ac0e87f1 100644 --- a/src/Resources/config/util.php +++ b/src/Resources/config/util.php @@ -11,9 +11,10 @@ * file that was distributed with this source code. */ +namespace Symfony\Component\DependencyInjection\Loader\Configurator; + use Sonata\UserBundle\Util\CanonicalFieldsUpdater; use Sonata\UserBundle\Util\TokenGenerator; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { $containerConfigurator->services() diff --git a/src/Resources/config/validator.php b/src/Resources/config/validator.php index a6df3cd45..2aa662dd1 100644 --- a/src/Resources/config/validator.php +++ b/src/Resources/config/validator.php @@ -11,17 +11,16 @@ * file that was distributed with this source code. */ +namespace Symfony\Component\DependencyInjection\Loader\Configurator; + use Sonata\UserBundle\Validator\UserInitializer; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { - // Use "service" function for creating references to services when dropping support for Symfony 4 $containerConfigurator->services() ->set('sonata.user.validator.user_initializer', UserInitializer::class) ->tag('validator.initializer') ->args([ - new ReferenceConfigurator('sonata.user.util.canonical_fields_updater'), + service('sonata.user.util.canonical_fields_updater'), ]); }; diff --git a/src/Resources/views/Admin/Core/user_block.html.twig b/src/Resources/views/Admin/Core/user_block.html.twig index b150035e2..a50928398 100644 --- a/src/Resources/views/Admin/Core/user_block.html.twig +++ b/src/Resources/views/Admin/Core/user_block.html.twig @@ -15,11 +15,7 @@ file that was distributed with this source code. {% set _logout_uri = url('sonata_user_admin_security_logout') %} {% set _logout_text = 'user_block_logout'|trans({}, 'SonataUserBundle') %} - {# TODO: Remove the check for the IS_IMPERSONATOR constant when dropping support for Symfony 4.4 #} - {% if sonata_user.isImpersonatingEnabled and (constant('Symfony\\Component\\Security\\Core\\Authorization\\Voter\\AuthenticatedVoter::IS_IMPERSONATOR') is defined ? - is_granted('IS_IMPERSONATOR') : - is_granted('ROLE_PREVIOUS_ADMIN')) - %} + {% if sonata_user.isImpersonatingEnabled and is_granted('IS_IMPERSONATOR') %} {% set _bg_class = 'bg-light-green' %} {% set _logout_uri = url(sonata_user.impersonatingRoute, sonata_user.impersonatingRouteParameters|merge({'_switch_user': '_exit'})) %} {% set _logout_text = 'switch_user_exit'|trans({}, 'SonataUserBundle') %} diff --git a/src/Security/UserProvider.php b/src/Security/UserProvider.php index 6b971dd80..7b52804ec 100644 --- a/src/Security/UserProvider.php +++ b/src/Security/UserProvider.php @@ -15,9 +15,7 @@ use Sonata\UserBundle\Model\UserInterface; use Sonata\UserBundle\Model\UserManagerInterface; -use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; -use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use Symfony\Component\Security\Core\Exception\UserNotFoundException; use Symfony\Component\Security\Core\User\UserInterface as SecurityUserInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; @@ -41,7 +39,7 @@ public function loadUserByIdentifier(string $identifier): SecurityUserInterface $user = $this->findUser($identifier); if (null === $user || !$user->isEnabled()) { - throw $this->buildUserNotFoundException(sprintf('Username "%s" does not exist.', $identifier)); + throw new UserNotFoundException(sprintf('Username "%s" does not exist.', $identifier)); } return $user; @@ -58,7 +56,7 @@ public function refreshUser(SecurityUserInterface $user): SecurityUserInterface } if (null === $reloadedUser = $this->userManager->findOneBy(['id' => $user->getId()])) { - throw $this->buildUserNotFoundException(sprintf('User with ID "%s" could not be reloaded.', $user->getId() ?? '')); + throw new UserNotFoundException(sprintf('User with ID "%s" could not be reloaded.', $user->getId() ?? '')); } return $reloadedUser; @@ -78,19 +76,4 @@ private function findUser(string $username): ?UserInterface { return $this->userManager->findUserByUsernameOrEmail($username); } - - /** - * TODO: Simplify when dropping support for Symfony 4. - * - * @psalm-suppress UndefinedClass, InvalidReturnType, InvalidReturnStatement - */ - private function buildUserNotFoundException(string $message): AuthenticationException - { - if (!class_exists(UserNotFoundException::class)) { - // @phpstan-ignore-next-line - return new UsernameNotFoundException($message); - } - - return new UserNotFoundException($message); - } } diff --git a/tests/App/AppKernel.php b/tests/App/AppKernel.php index 496017fd5..1d38abf99 100644 --- a/tests/App/AppKernel.php +++ b/tests/App/AppKernel.php @@ -33,7 +33,6 @@ use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; use Symfony\Component\Security\Http\Attribute\IsGranted; -use Symfony\Component\Security\Http\Authentication\AuthenticatorManager; /** * @author Javier Spagnoletti @@ -76,12 +75,7 @@ public function getProjectDir(): string return __DIR__; } - /** - * TODO: Add typehint when support for Symfony < 5.1 is dropped. - * - * @param RoutingConfigurator $routes - */ - protected function configureRoutes($routes): void + protected function configureRoutes(RoutingConfigurator $routes): void { $routes->import(__DIR__.'/config/routes.yaml'); } @@ -93,12 +87,8 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa { $loader->load(__DIR__.'/config/config.yaml'); - if (class_exists(IsGranted::class)) { - $loader->load(__DIR__.'/config/config_sf6.yaml'); - } elseif (class_exists(AuthenticatorManager::class)) { + if (!class_exists(IsGranted::class)) { $loader->load(__DIR__.'/config/config_sf5.yaml'); - } else { - $loader->load(__DIR__.'/config/config_sf4.yaml'); } if (class_exists(HttpCacheHandler::class)) { diff --git a/tests/App/config/config.yaml b/tests/App/config/config.yaml index 6346a9b7c..9071d4001 100644 --- a/tests/App/config/config.yaml +++ b/tests/App/config/config.yaml @@ -8,7 +8,12 @@ framework: enabled: true translator: enabled: true + router: + utf8: true http_method_override: false + session: + storage_factory_id: session.storage.factory.mock_file + assets: security: role_hierarchy: null @@ -25,6 +30,7 @@ security: firewalls: main: + lazy: true pattern: /(.*) provider: sonata_user_bundle context: user @@ -40,6 +46,10 @@ security: lifetime: 2629746 path: / + password_hashers: + Sonata\UserBundle\Model\UserInterface: + algorithm: plaintext + twig: exception_controller: null strict_variables: true diff --git a/tests/App/config/config_sf4.yaml b/tests/App/config/config_sf4.yaml deleted file mode 100644 index 25a7c36f8..000000000 --- a/tests/App/config/config_sf4.yaml +++ /dev/null @@ -1,11 +0,0 @@ -framework: - session: - storage_id: session.storage.mock_file - -security: - encoders: - Sonata\UserBundle\Model\UserInterface: plaintext - - firewalls: - main: - anonymous: true diff --git a/tests/App/config/config_sf5.yaml b/tests/App/config/config_sf5.yaml index 539948ae3..f1e0ffdd4 100644 --- a/tests/App/config/config_sf5.yaml +++ b/tests/App/config/config_sf5.yaml @@ -1,15 +1,2 @@ -framework: - session: - storage_factory_id: session.storage.factory.mock_file - assets: - security: enable_authenticator_manager: true - - password_hashers: - Sonata\UserBundle\Model\UserInterface: - algorithm: plaintext - - firewalls: - main: - lazy: true diff --git a/tests/App/config/config_sf6.yaml b/tests/App/config/config_sf6.yaml deleted file mode 100644 index 57b51ed86..000000000 --- a/tests/App/config/config_sf6.yaml +++ /dev/null @@ -1,13 +0,0 @@ -framework: - session: - storage_factory_id: session.storage.factory.mock_file - assets: - -security: - password_hashers: - Sonata\UserBundle\Model\UserInterface: - algorithm: plaintext - - firewalls: - main: - lazy: true diff --git a/tests/Functional/Action/LoginActionTest.php b/tests/Functional/Action/LoginActionTest.php index 02948ddcc..bc074e3f2 100644 --- a/tests/Functional/Action/LoginActionTest.php +++ b/tests/Functional/Action/LoginActionTest.php @@ -62,15 +62,9 @@ public function testItSubmitsLoginFormWithDisabledUser(): void static::assertRouteSame('sonata_user_admin_security_login'); } - /** - * @psalm-suppress UndefinedPropertyFetch - */ private function prepareData(bool $enabled = true): void { - // TODO: Simplify this when dropping support for Symfony 4. - // @phpstan-ignore-next-line - $container = method_exists(self::class, 'getContainer') ? static::getContainer() : static::$container; - $manager = $container->get('doctrine.orm.entity_manager'); + $manager = static::getContainer()->get('doctrine.orm.entity_manager'); \assert($manager instanceof EntityManagerInterface); $user = new User(); diff --git a/tests/Functional/Action/RequestActionTest.php b/tests/Functional/Action/RequestActionTest.php index 2dffb272d..4d4ff16ec 100644 --- a/tests/Functional/Action/RequestActionTest.php +++ b/tests/Functional/Action/RequestActionTest.php @@ -36,9 +36,6 @@ public function testItSubmitsResetPasswordRequestWithNonExistentUser(): void { $client = static::createClient(); - // TODO: Remove this line when the issue gets solved: https://github.com/symfony/symfony/issues/45580 - $client->disableReboot(); - $client->request('GET', '/request'); static::assertResponseIsSuccessful(); @@ -59,9 +56,6 @@ public function testItSubmitsResetPasswordRequest(): void { $client = static::createClient(); - // TODO: Remove this line when the issue gets solved: https://github.com/symfony/symfony/issues/45580 - $client->disableReboot(); - $this->prepareData(); $client->request('GET', '/request'); @@ -86,15 +80,9 @@ public function testItSubmitsResetPasswordRequest(): void static::assertRouteSame('sonata_user_admin_resetting_check_email'); } - /** - * @psalm-suppress UndefinedPropertyFetch - */ private function prepareData(): void { - // TODO: Simplify this when dropping support for Symfony 4. - // @phpstan-ignore-next-line - $container = method_exists(self::class, 'getContainer') ? static::getContainer() : static::$container; - $manager = $container->get('doctrine.orm.entity_manager'); + $manager = static::getContainer()->get('doctrine.orm.entity_manager'); \assert($manager instanceof EntityManagerInterface); $user = new User(); diff --git a/tests/Functional/Action/ResetActionTest.php b/tests/Functional/Action/ResetActionTest.php index d12e0636d..2229dcfd3 100644 --- a/tests/Functional/Action/ResetActionTest.php +++ b/tests/Functional/Action/ResetActionTest.php @@ -56,9 +56,6 @@ public function testItResetsPassword(): void { $client = static::createClient(); - // TODO: Remove this line when the issue gets solved: https://github.com/symfony/symfony/issues/45580 - $client->disableReboot(); - $user = $this->prepareData(); $confirmationToken = $user->getConfirmationToken(); \assert(null !== $confirmationToken); @@ -82,15 +79,9 @@ public function testItResetsPassword(): void static::assertSame($user->getPassword(), 'new_password'); } - /** - * @psalm-suppress UndefinedPropertyFetch - */ private function prepareData(): UserInterface { - // TODO: Simplify this when dropping support for Symfony 4. - // @phpstan-ignore-next-line - $container = method_exists(self::class, 'getContainer') ? static::getContainer() : static::$container; - $manager = $container->get('doctrine.orm.entity_manager'); + $manager = static::getContainer()->get('doctrine.orm.entity_manager'); \assert($manager instanceof EntityManagerInterface); $user = new User(); @@ -108,15 +99,9 @@ private function prepareData(): UserInterface return $user; } - /** - * @psalm-suppress UndefinedPropertyFetch - */ private function refreshUser(UserInterface $user): UserInterface { - // TODO: Simplify this when dropping support for Symfony 4. - // @phpstan-ignore-next-line - $container = method_exists(self::class, 'getContainer') ? static::getContainer() : static::$container; - $manager = $container->get('doctrine.orm.entity_manager'); + $manager = static::getContainer()->get('doctrine.orm.entity_manager'); \assert($manager instanceof EntityManagerInterface); $user = $manager->find(User::class, $user->getId()); diff --git a/tests/Functional/Admin/UserAdminTest.php b/tests/Functional/Admin/UserAdminTest.php index 5d51ee548..05fea33af 100644 --- a/tests/Functional/Admin/UserAdminTest.php +++ b/tests/Functional/Admin/UserAdminTest.php @@ -96,9 +96,6 @@ public function testUpdatePassword(): void { $client = self::createClient(); - // TODO: Remove this line when the issue gets solved: https://github.com/symfony/symfony/issues/45580 - $client->disableReboot(); - $user = $this->prepareData(); static::assertSame('random_password', $user->getPassword()); @@ -121,9 +118,6 @@ public function testRoleMatrixExcludedDefaultRoleIsNotVisible(): void { $client = self::createClient(); - // TODO: Remove this line when the issue gets solved: https://github.com/symfony/symfony/issues/45580 - $client->disableReboot(); - $user = $this->prepareData(); $token = $this->loginUser($user, $client); @@ -139,15 +133,9 @@ public function testRoleMatrixExcludedDefaultRoleIsNotVisible(): void static::assertStringNotContainsString(UserInterface::ROLE_DEFAULT, (string) $client->getResponse()->getContent()); } - /** - * @psalm-suppress UndefinedPropertyFetch - */ private function prepareData(): UserInterface { - // TODO: Simplify this when dropping support for Symfony 4. - // @phpstan-ignore-next-line - $container = method_exists(self::class, 'getContainer') ? static::getContainer() : static::$container; - $manager = $container->get('doctrine.orm.entity_manager'); + $manager = static::getContainer()->get('doctrine.orm.entity_manager'); \assert($manager instanceof EntityManagerInterface); $user = new User(); @@ -165,15 +153,9 @@ private function prepareData(): UserInterface return $user; } - /** - * @psalm-suppress UndefinedPropertyFetch - */ private function refreshUser(UserInterface $user): UserInterface { - // TODO: Simplify this when dropping support for Symfony 4. - // @phpstan-ignore-next-line - $container = method_exists(self::class, 'getContainer') ? static::getContainer() : static::$container; - $manager = $container->get('doctrine.orm.entity_manager'); + $manager = static::getContainer()->get('doctrine.orm.entity_manager'); \assert($manager instanceof EntityManagerInterface); $user = $manager->find(User::class, $user->getId()); @@ -184,16 +166,10 @@ private function refreshUser(UserInterface $user): UserInterface private function loginUser(UserInterface $user, KernelBrowser $client): TokenInterface { - // TODO: Simplify this when dropping support for Symfony 4. - /** @psalm-suppress UndefinedPropertyFetch */ - // @phpstan-ignore-next-line - $container = method_exists(self::class, 'getContainer') ? static::getContainer() : static::$container; - $tokenStorage = $container->get('security.token_storage'); + $tokenStorage = static::getContainer()->get('security.token_storage'); \assert($tokenStorage instanceof TokenStorageInterface); - /** @psalm-suppress UndefinedPropertyFetch, TooManyArguments, NullArgument, InvalidArgument, UnusedPsalmSuppress */ - // @phpstan-ignore-next-line - $token = method_exists(UsernamePasswordToken::class, 'getCredentials') ? new UsernamePasswordToken($user, null, 'main', $user->getRoles()) : new UsernamePasswordToken($user, 'main', $user->getRoles()); + $token = new UsernamePasswordToken($user, 'main', $user->getRoles()); $tokenStorage->setToken($token); $sessionId = 'test-sonata-user-bundle'; diff --git a/tests/Functional/Command/ActivateUserCommandTest.php b/tests/Functional/Command/ActivateUserCommandTest.php index bd440d098..26662c33c 100644 --- a/tests/Functional/Command/ActivateUserCommandTest.php +++ b/tests/Functional/Command/ActivateUserCommandTest.php @@ -63,15 +63,9 @@ public function testActivatesUser(): void static::assertStringContainsString('User "sonata-user-test" has been activated.', $this->commandTester->getDisplay()); } - /** - * @psalm-suppress UndefinedPropertyFetch - */ private function prepareData(string $username, bool $enabled): UserInterface { - // TODO: Simplify this when dropping support for Symfony 4. - // @phpstan-ignore-next-line - $container = method_exists(static::class, 'getContainer') ? static::getContainer() : static::$container; - $manager = $container->get('doctrine.orm.entity_manager'); + $manager = static::getContainer()->get('doctrine.orm.entity_manager'); \assert($manager instanceof EntityManagerInterface); $user = new User(); @@ -89,15 +83,9 @@ private function prepareData(string $username, bool $enabled): UserInterface return $user; } - /** - * @psalm-suppress UndefinedPropertyFetch - */ private function refreshUser(UserInterface $user): UserInterface { - // TODO: Simplify this when dropping support for Symfony 4. - // @phpstan-ignore-next-line - $container = method_exists(static::class, 'getContainer') ? static::getContainer() : static::$container; - $manager = $container->get('doctrine.orm.entity_manager'); + $manager = static::getContainer()->get('doctrine.orm.entity_manager'); \assert($manager instanceof EntityManagerInterface); $user = $manager->find(User::class, $user->getId()); diff --git a/tests/Functional/Command/ChangePasswordCommandTest.php b/tests/Functional/Command/ChangePasswordCommandTest.php index e219ac7fa..ded6fc6a2 100644 --- a/tests/Functional/Command/ChangePasswordCommandTest.php +++ b/tests/Functional/Command/ChangePasswordCommandTest.php @@ -60,15 +60,9 @@ public function testChangesUserPassword(): void static::assertStringContainsString('Changed password for user "sonata-user-test".', $this->commandTester->getDisplay()); } - /** - * @psalm-suppress UndefinedPropertyFetch - */ private function prepareData(string $username, string $password): UserInterface { - // TODO: Simplify this when dropping support for Symfony 4. - // @phpstan-ignore-next-line - $container = method_exists(static::class, 'getContainer') ? static::getContainer() : static::$container; - $manager = $container->get('doctrine.orm.entity_manager'); + $manager = static::getContainer()->get('doctrine.orm.entity_manager'); \assert($manager instanceof EntityManagerInterface); $user = new User(); @@ -86,15 +80,9 @@ private function prepareData(string $username, string $password): UserInterface return $user; } - /** - * @psalm-suppress UndefinedPropertyFetch - */ private function refreshUser(UserInterface $user): UserInterface { - // TODO: Simplify this when dropping support for Symfony 4. - // @phpstan-ignore-next-line - $container = method_exists(static::class, 'getContainer') ? static::getContainer() : static::$container; - $manager = $container->get('doctrine.orm.entity_manager'); + $manager = static::getContainer()->get('doctrine.orm.entity_manager'); \assert($manager instanceof EntityManagerInterface); $user = $manager->find(User::class, $user->getId()); diff --git a/tests/Functional/Command/CreateUserCommandTest.php b/tests/Functional/Command/CreateUserCommandTest.php index a08491b1f..4ab9abb1b 100644 --- a/tests/Functional/Command/CreateUserCommandTest.php +++ b/tests/Functional/Command/CreateUserCommandTest.php @@ -77,15 +77,9 @@ public function testCreatesAnSuperAdminUser(): void static::assertTrue($createdUser->isSuperAdmin()); } - /** - * @psalm-suppress UndefinedPropertyFetch - */ private function find(string $username): UserInterface { - // TODO: Simplify this when dropping support for Symfony 4. - // @phpstan-ignore-next-line - $container = method_exists(static::class, 'getContainer') ? static::getContainer() : static::$container; - $manager = $container->get('sonata.user.manager.user'); + $manager = static::getContainer()->get('sonata.user.manager.user'); \assert($manager instanceof UserManagerInterface); $user = $manager->findUserByUsername($username); diff --git a/tests/Functional/Command/DeactivateUserCommandTest.php b/tests/Functional/Command/DeactivateUserCommandTest.php index 0db23fd33..28b58a623 100644 --- a/tests/Functional/Command/DeactivateUserCommandTest.php +++ b/tests/Functional/Command/DeactivateUserCommandTest.php @@ -63,15 +63,9 @@ public function testDeactivatesUser(): void static::assertStringContainsString('User "sonata-user-test" has been activated.', $this->commandTester->getDisplay()); } - /** - * @psalm-suppress UndefinedPropertyFetch - */ private function prepareData(string $username, bool $enabled): UserInterface { - // TODO: Simplify this when dropping support for Symfony 4. - // @phpstan-ignore-next-line - $container = method_exists(static::class, 'getContainer') ? static::getContainer() : static::$container; - $manager = $container->get('doctrine.orm.entity_manager'); + $manager = static::getContainer()->get('doctrine.orm.entity_manager'); \assert($manager instanceof EntityManagerInterface); $user = new User(); @@ -89,15 +83,9 @@ private function prepareData(string $username, bool $enabled): UserInterface return $user; } - /** - * @psalm-suppress UndefinedPropertyFetch - */ private function refreshUser(UserInterface $user): UserInterface { - // TODO: Simplify this when dropping support for Symfony 4. - // @phpstan-ignore-next-line - $container = method_exists(static::class, 'getContainer') ? static::getContainer() : static::$container; - $manager = $container->get('doctrine.orm.entity_manager'); + $manager = static::getContainer()->get('doctrine.orm.entity_manager'); \assert($manager instanceof EntityManagerInterface); $user = $manager->find(User::class, $user->getId()); diff --git a/tests/Functional/Command/DemoteUserCommandTest.php b/tests/Functional/Command/DemoteUserCommandTest.php index 267a44cef..6370cb3a6 100644 --- a/tests/Functional/Command/DemoteUserCommandTest.php +++ b/tests/Functional/Command/DemoteUserCommandTest.php @@ -113,16 +113,11 @@ public function testBecomeNormalUser(): void } /** - * @psalm-suppress UndefinedPropertyFetch - * * @param string[] $roles */ private function prepareData(string $username, bool $superAdmin, array $roles): UserInterface { - // TODO: Simplify this when dropping support for Symfony 4. - // @phpstan-ignore-next-line - $container = method_exists(static::class, 'getContainer') ? static::getContainer() : static::$container; - $manager = $container->get('doctrine.orm.entity_manager'); + $manager = static::getContainer()->get('doctrine.orm.entity_manager'); \assert($manager instanceof EntityManagerInterface); $user = new User(); @@ -141,15 +136,9 @@ private function prepareData(string $username, bool $superAdmin, array $roles): return $user; } - /** - * @psalm-suppress UndefinedPropertyFetch - */ private function refreshUser(UserInterface $user): UserInterface { - // TODO: Simplify this when dropping support for Symfony 4. - // @phpstan-ignore-next-line - $container = method_exists(static::class, 'getContainer') ? static::getContainer() : static::$container; - $manager = $container->get('doctrine.orm.entity_manager'); + $manager = static::getContainer()->get('doctrine.orm.entity_manager'); \assert($manager instanceof EntityManagerInterface); $user = $manager->find(User::class, $user->getId()); diff --git a/tests/Functional/Command/PromoteUserCommandTest.php b/tests/Functional/Command/PromoteUserCommandTest.php index 576220cd5..68fcfa4fc 100644 --- a/tests/Functional/Command/PromoteUserCommandTest.php +++ b/tests/Functional/Command/PromoteUserCommandTest.php @@ -113,16 +113,11 @@ public function testBecomeSuperAdmin(): void } /** - * @psalm-suppress UndefinedPropertyFetch - * * @param string[] $roles */ private function prepareData(string $username, bool $superAdmin, array $roles): UserInterface { - // TODO: Simplify this when dropping support for Symfony 4. - // @phpstan-ignore-next-line - $container = method_exists(static::class, 'getContainer') ? static::getContainer() : static::$container; - $manager = $container->get('doctrine.orm.entity_manager'); + $manager = static::getContainer()->get('doctrine.orm.entity_manager'); \assert($manager instanceof EntityManagerInterface); $user = new User(); @@ -141,15 +136,9 @@ private function prepareData(string $username, bool $superAdmin, array $roles): return $user; } - /** - * @psalm-suppress UndefinedPropertyFetch - */ private function refreshUser(UserInterface $user): UserInterface { - // TODO: Simplify this when dropping support for Symfony 4. - // @phpstan-ignore-next-line - $container = method_exists(static::class, 'getContainer') ? static::getContainer() : static::$container; - $manager = $container->get('doctrine.orm.entity_manager'); + $manager = static::getContainer()->get('doctrine.orm.entity_manager'); \assert($manager instanceof EntityManagerInterface); $user = $manager->find(User::class, $user->getId()); diff --git a/tests/Security/UserProviderTest.php b/tests/Security/UserProviderTest.php index b3ca00bd3..f427886ce 100644 --- a/tests/Security/UserProviderTest.php +++ b/tests/Security/UserProviderTest.php @@ -20,7 +20,6 @@ use Sonata\UserBundle\Tests\App\Entity\User; use Sonata\UserBundle\Tests\Entity\User as EntityUser; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; -use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use Symfony\Component\Security\Core\Exception\UserNotFoundException; use Symfony\Component\Security\Core\User\UserInterface; @@ -53,17 +52,11 @@ public function testLoadUserByUsername(): void static::assertSame($user, $this->userProvider->loadUserByUsername('foobar')); } - /** - * TODO: Simplify exception expectation when dropping support for Symfony 4.4. - * - * @psalm-suppress UndefinedClass, PossiblyInvalidArgument - */ public function testLoadUserByInvalidUsername(): void { $this->userManager->expects(static::once())->method('findUserByUsernameOrEmail'); - // @phpstan-ignore-next-line - $this->expectException(class_exists(UserNotFoundException::class) ? UserNotFoundException::class : UsernameNotFoundException::class); + $this->expectException(UserNotFoundException::class); $this->userProvider->loadUserByUsername('foobar'); } @@ -86,11 +79,6 @@ public function testRefreshUserBy(): void static::assertSame($refreshedUser, $this->userProvider->refreshUser($user)); } - /** - * TODO: Simplify exception expectation when dropping support for Symfony 4.4. - * - * @psalm-suppress UndefinedClass, PossiblyInvalidArgument - */ public function testRefreshDeleted(): void { $user = new User(); @@ -100,8 +88,7 @@ public function testRefreshDeleted(): void ->method('getClass') ->willReturn($user::class); - // @phpstan-ignore-next-line - $this->expectException(class_exists(UserNotFoundException::class) ? UserNotFoundException::class : UsernameNotFoundException::class); + $this->expectException(UserNotFoundException::class); $this->userProvider->refreshUser($user); }