diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b6b129beb..963425835 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,19 +15,11 @@ jobs: fail-fast: false matrix: php: - - '7.4' - - '8.0' - '8.1' - '8.2' - '8.3' symfony-versions: [false] include: - - description: 'Symfony 4.*' - php: '7.4' - symfony-versions: '^4.4' - - description: 'Symfony 5.*' - php: '8.1' - symfony-versions: '^5.4' - description: 'Symfony 6.*' php: '8.2' symfony-versions: '^6.4' diff --git a/composer.json b/composer.json index 99683afbf..a6a236e8b 100644 --- a/composer.json +++ b/composer.json @@ -21,41 +21,42 @@ } ], "require": { - "php": "^7.4 || ^8.0", + "php": "^8.1", "ext-dom": "*", "ext-json": "*", - "symfony/config": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0 || ^7.0", + "symfony/config": "^6.4 || ^7.0", + "symfony/dependency-injection": "^6.4 || ^7.0", "symfony/deprecation-contracts": "^2.5 || ^3.5", - "symfony/event-dispatcher": "^4.4 || ^5.0 || ^6.0 || ^7.0", + "symfony/event-dispatcher": "^6.4 || ^7.0", "symfony/event-dispatcher-contracts": "^1.1 || ^2.0 || ^3.0", - "symfony/form": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/http-foundation": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/http-kernel": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/options-resolver": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/routing": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/security-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/security-core": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/translation": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/twig-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/validator": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "twig/twig": "^1.34 || ^2.4 || ^3.0" + "symfony/form": "^6.4 || ^7.0", + "symfony/framework-bundle": "^6.4 || ^7.0", + "symfony/http-foundation": "^6.4 || ^7.0", + "symfony/http-kernel": "^6.4 || ^7.0", + "symfony/options-resolver": "^6.4 || ^7.0", + "symfony/password-hasher": "^6.4 || ^7.0", + "symfony/routing": "^6.4 || ^7.0", + "symfony/security-bundle": "^6.4 || ^7.0", + "symfony/security-core": "^6.4 || ^7.0", + "symfony/translation": "^6.4 || ^7.0", + "symfony/twig-bundle": "^6.4 || ^7.0", + "symfony/validator": "^6.4 || ^7.0", + "twig/twig": "^2.13 || ^3.0" }, "conflict": { "doctrine/doctrine-bundle": "<1.3", "doctrine/persistence": "<1.3", - "symfony/doctrine-bridge": "<4.4" + "symfony/doctrine-bridge": "<6.4" }, "require-dev": { "doctrine/doctrine-bundle": "^1.3 || ^2", "friendsofphp/php-cs-fixer": "^3.0.2, !=3.5.0", "swiftmailer/swiftmailer": "^4.3 || ^5.0 || ^6.0", - "symfony/console": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/mailer": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/mime": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/phpunit-bridge": "^6.1", - "symfony/yaml": "^4.4 || ^5.0 || ^6.0 || ^7.0" + "symfony/console": "^6.4 || ^7.0", + "symfony/mailer": "^6.4 || ^7.0", + "symfony/mime": "^6.4 || ^7.0", + "symfony/phpunit-bridge": "^6.4 || ^7.0", + "symfony/yaml": "^6.4 || ^7.0" }, "config": { "sort-packages": true diff --git a/src/Command/ActivateUserCommand.php b/src/Command/ActivateUserCommand.php index 7f81404ce..8455b64c6 100644 --- a/src/Command/ActivateUserCommand.php +++ b/src/Command/ActivateUserCommand.php @@ -28,9 +28,6 @@ #[AsCommand(name: 'fos:user:activate', description: 'Activate a user')] final class ActivateUserCommand extends Command { - // BC with Symfony <5.3 - protected static $defaultName = 'fos:user:activate'; - private $userManipulator; public function __construct(UserManipulator $userManipulator) @@ -43,9 +40,6 @@ public function __construct(UserManipulator $userManipulator) protected function configure(): void { $this - // BC with Symfony <5.3 - ->setName('fos:user:activate') - ->setDescription('Activate a user') ->setDefinition([ new InputArgument('username', InputArgument::REQUIRED, 'The username'), ]) diff --git a/src/Command/ChangePasswordCommand.php b/src/Command/ChangePasswordCommand.php index c6cd94781..653bef173 100644 --- a/src/Command/ChangePasswordCommand.php +++ b/src/Command/ChangePasswordCommand.php @@ -26,9 +26,6 @@ #[AsCommand(name: 'fos:user:change-password', description: 'Change the password of a user.')] final class ChangePasswordCommand extends Command { - // BC with Symfony <5.3 - protected static $defaultName = 'fos:user:change-password'; - private $userManipulator; public function __construct(UserManipulator $userManipulator) @@ -41,9 +38,6 @@ public function __construct(UserManipulator $userManipulator) protected function configure(): void { $this - // BC with Symfony <5.3 - ->setName('fos:user:change-password') - ->setDescription('Change the password of a user.') ->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 abba0d43d..3623c18dd 100644 --- a/src/Command/CreateUserCommand.php +++ b/src/Command/CreateUserCommand.php @@ -31,9 +31,6 @@ #[AsCommand(name: 'fos:user:create', description: 'Create a user.')] final class CreateUserCommand extends Command { - // BC with Symfony <5.3 - protected static $defaultName = 'fos:user:create'; - private $userManipulator; public function __construct(UserManipulator $userManipulator) @@ -46,9 +43,6 @@ public function __construct(UserManipulator $userManipulator) protected function configure(): void { $this - // BC with Symfony <5.3 - ->setName('fos:user:create') - ->setDescription('Create a user.') ->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 3b1ce69f6..1f5849a7b 100644 --- a/src/Command/DeactivateUserCommand.php +++ b/src/Command/DeactivateUserCommand.php @@ -28,9 +28,6 @@ #[AsCommand(name: 'fos:user:deactivate', description: 'Deactivate a user')] final class DeactivateUserCommand extends Command { - // BC with Symfony <5.3 - protected static $defaultName = 'fos:user:deactivate'; - private $userManipulator; public function __construct(UserManipulator $userManipulator) @@ -43,9 +40,6 @@ public function __construct(UserManipulator $userManipulator) protected function configure(): void { $this - // BC with Symfony <5.3 - ->setName('fos:user:deactivate') - ->setDescription('Deactivate a user') ->setDefinition([ new InputArgument('username', InputArgument::REQUIRED, 'The username'), ]) diff --git a/src/Command/DemoteUserCommand.php b/src/Command/DemoteUserCommand.php index 9b4c130fe..99e0a9c62 100644 --- a/src/Command/DemoteUserCommand.php +++ b/src/Command/DemoteUserCommand.php @@ -24,17 +24,11 @@ #[AsCommand(name: 'fos:user:demote', description: 'Demote a user by removing a role')] final class DemoteUserCommand extends RoleCommand { - // BC with Symfony <5.3 - protected static $defaultName = 'fos:user:demote'; - protected function configure(): void { parent::configure(); $this - // BC with Symfony <5.3 - ->setName('fos:user:demote') - ->setDescription('Demote a user by removing a role') ->setHelp(<<<'EOT' The fos:user:demote command demotes a user by removing a role diff --git a/src/Command/PromoteUserCommand.php b/src/Command/PromoteUserCommand.php index abfc3a804..fb88ae7b1 100644 --- a/src/Command/PromoteUserCommand.php +++ b/src/Command/PromoteUserCommand.php @@ -26,17 +26,11 @@ #[AsCommand(name: 'fos:user:promote', description: 'Promotes a user by adding a role')] final class PromoteUserCommand extends RoleCommand { - // BC with Symfony <5.3 - protected static $defaultName = 'fos:user:promote'; - protected function configure(): void { parent::configure(); $this - // BC with Symfony <5.3 - ->setName('fos:user:promote') - ->setDescription('Promotes a user by adding a role') ->setHelp(<<<'EOT' The fos:user:promote command promotes a user by adding a role diff --git a/src/CompatibilityUtil.php b/src/CompatibilityUtil.php deleted file mode 100644 index 9ee482e35..000000000 --- a/src/CompatibilityUtil.php +++ /dev/null @@ -1,35 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace FOS\UserBundle; - -use Symfony\Component\EventDispatcher\GenericEvent; -use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; -use Symfony\Contracts\EventDispatcher\Event; -use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; - -/** - * @internal - */ -final class CompatibilityUtil -{ - public static function upgradeEventDispatcher(EventDispatcherInterface $eventDispatcher): EventDispatcherInterface - { - // On Symfony 5.0+, the legacy proxy is a no-op and it is deprecated in 5.1+ - // Detecting the parent class of GenericEvent (which changed in 5.0) allows to avoid using the deprecated no-op API. - if (is_subclass_of(GenericEvent::class, Event::class)) { - return $eventDispatcher; - } - - // BC layer for Symfony 4.4 where we need to apply the decorating proxy in case of non-upgraded dispatcher. - return LegacyEventDispatcherProxy::decorate($eventDispatcher); - } -} diff --git a/src/Controller/ChangePasswordController.php b/src/Controller/ChangePasswordController.php index e3448efbe..84525c360 100644 --- a/src/Controller/ChangePasswordController.php +++ b/src/Controller/ChangePasswordController.php @@ -11,7 +11,6 @@ namespace FOS\UserBundle\Controller; -use FOS\UserBundle\CompatibilityUtil; use FOS\UserBundle\Event\FilterUserResponseEvent; use FOS\UserBundle\Event\FormEvent; use FOS\UserBundle\Event\GetResponseUserEvent; @@ -40,7 +39,7 @@ final class ChangePasswordController extends AbstractController public function __construct(EventDispatcherInterface $eventDispatcher, FactoryInterface $formFactory, UserManagerInterface $userManager) { - $this->eventDispatcher = CompatibilityUtil::upgradeEventDispatcher($eventDispatcher); + $this->eventDispatcher = $eventDispatcher; $this->formFactory = $formFactory; $this->userManager = $userManager; } diff --git a/src/Controller/ProfileController.php b/src/Controller/ProfileController.php index cc8b4d70c..d45f65167 100644 --- a/src/Controller/ProfileController.php +++ b/src/Controller/ProfileController.php @@ -11,7 +11,6 @@ namespace FOS\UserBundle\Controller; -use FOS\UserBundle\CompatibilityUtil; use FOS\UserBundle\Event\FilterUserResponseEvent; use FOS\UserBundle\Event\FormEvent; use FOS\UserBundle\Event\GetResponseUserEvent; @@ -39,7 +38,7 @@ final class ProfileController extends AbstractController public function __construct(EventDispatcherInterface $eventDispatcher, FactoryInterface $formFactory, UserManagerInterface $userManager) { - $this->eventDispatcher = CompatibilityUtil::upgradeEventDispatcher($eventDispatcher); + $this->eventDispatcher = $eventDispatcher; $this->formFactory = $formFactory; $this->userManager = $userManager; } diff --git a/src/Controller/RegistrationController.php b/src/Controller/RegistrationController.php index 9e9188fae..4ed4b1fbf 100644 --- a/src/Controller/RegistrationController.php +++ b/src/Controller/RegistrationController.php @@ -11,7 +11,6 @@ namespace FOS\UserBundle\Controller; -use FOS\UserBundle\CompatibilityUtil; use FOS\UserBundle\Event\FilterUserResponseEvent; use FOS\UserBundle\Event\FormEvent; use FOS\UserBundle\Event\GetResponseUserEvent; @@ -43,7 +42,7 @@ final class RegistrationController extends AbstractController public function __construct(EventDispatcherInterface $eventDispatcher, FactoryInterface $formFactory, UserManagerInterface $userManager, TokenStorageInterface $tokenStorage) { - $this->eventDispatcher = CompatibilityUtil::upgradeEventDispatcher($eventDispatcher); + $this->eventDispatcher = $eventDispatcher; $this->formFactory = $formFactory; $this->userManager = $userManager; $this->tokenStorage = $tokenStorage; @@ -178,9 +177,6 @@ private function getTargetUrlFromSession(SessionInterface $session): ?string if (method_exists($token, 'getFirewallName')) { $firewallName = $token->getFirewallName(); - } elseif (method_exists($token, 'getProviderKey')) { - // BC with Symfony 5.x - $firewallName = $token->getProviderKey(); } else { return null; } diff --git a/src/Controller/ResettingController.php b/src/Controller/ResettingController.php index 367b58294..fd36771a8 100644 --- a/src/Controller/ResettingController.php +++ b/src/Controller/ResettingController.php @@ -11,7 +11,6 @@ namespace FOS\UserBundle\Controller; -use FOS\UserBundle\CompatibilityUtil; use FOS\UserBundle\Event\FilterUserResponseEvent; use FOS\UserBundle\Event\FormEvent; use FOS\UserBundle\Event\GetResponseNullableUserEvent; @@ -51,7 +50,7 @@ final class ResettingController extends AbstractController */ public function __construct(EventDispatcherInterface $eventDispatcher, FactoryInterface $formFactory, UserManagerInterface $userManager, TokenGeneratorInterface $tokenGenerator, MailerInterface $mailer, $retryTtl) { - $this->eventDispatcher = CompatibilityUtil::upgradeEventDispatcher($eventDispatcher); + $this->eventDispatcher = $eventDispatcher; $this->formFactory = $formFactory; $this->userManager = $userManager; $this->tokenGenerator = $tokenGenerator; diff --git a/src/DependencyInjection/Compiler/ConfigurePasswordHasherPass.php b/src/DependencyInjection/Compiler/ConfigurePasswordHasherPass.php deleted file mode 100644 index 95f017b6a..000000000 --- a/src/DependencyInjection/Compiler/ConfigurePasswordHasherPass.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace FOS\UserBundle\DependencyInjection\Compiler; - -use FOS\UserBundle\Util\PasswordUpdater; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Reference; - -/** - * @internal - */ -final class ConfigurePasswordHasherPass implements CompilerPassInterface -{ - public function process(ContainerBuilder $container): void - { - if ($container->has('security.password_hasher_factory')) { - return; - } - - // If we don't have the new service for password-hasher, use the old implementation based on the EncoderFactoryInterface - $def = $container->getDefinition('fos_user.util.password_updater'); - - $def->setClass(PasswordUpdater::class); - $def->setArgument(0, new Reference('security.encoder_factory')); - } -} diff --git a/src/DependencyInjection/Compiler/InjectRememberMeServicesPass.php b/src/DependencyInjection/Compiler/InjectRememberMeServicesPass.php index 1d51ddc56..ac5d382d6 100644 --- a/src/DependencyInjection/Compiler/InjectRememberMeServicesPass.php +++ b/src/DependencyInjection/Compiler/InjectRememberMeServicesPass.php @@ -32,10 +32,6 @@ public function process(ContainerBuilder $container): void if ($container->has('security.authenticator.remember_me_handler.'.$firewallName)) { $loginManager->replaceArgument(4, new Reference('security.authenticator.remember_me_handler.'.$firewallName)); - } elseif ($container->hasDefinition('security.authentication.rememberme.services.persistent.'.$firewallName)) { - $loginManager->replaceArgument(4, new Reference('security.authentication.rememberme.services.persistent.'.$firewallName)); - } elseif ($container->hasDefinition('security.authentication.rememberme.services.simplehash.'.$firewallName)) { - $loginManager->replaceArgument(4, new Reference('security.authentication.rememberme.services.simplehash.'.$firewallName)); } } } diff --git a/src/EventListener/AuthenticationListener.php b/src/EventListener/AuthenticationListener.php index 15f7efac2..6494672cd 100644 --- a/src/EventListener/AuthenticationListener.php +++ b/src/EventListener/AuthenticationListener.php @@ -11,7 +11,6 @@ namespace FOS\UserBundle\EventListener; -use FOS\UserBundle\CompatibilityUtil; use FOS\UserBundle\Event\FilterUserResponseEvent; use FOS\UserBundle\Event\UserEvent; use FOS\UserBundle\FOSUserEvents; @@ -62,7 +61,6 @@ public static function getSubscribedEvents(): array */ public function authenticate(FilterUserResponseEvent $event, $eventName, EventDispatcherInterface $eventDispatcher) { - $eventDispatcher = CompatibilityUtil::upgradeEventDispatcher($eventDispatcher); try { $this->loginManager->logInUser($this->firewallName, $event->getUser(), $event->getResponse()); diff --git a/src/FOSUserBundle.php b/src/FOSUserBundle.php index d6860b824..b51398739 100644 --- a/src/FOSUserBundle.php +++ b/src/FOSUserBundle.php @@ -15,7 +15,6 @@ use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass; use FOS\UserBundle\DependencyInjection\Compiler\CheckForSessionPass; use FOS\UserBundle\DependencyInjection\Compiler\CheckForSwiftMailerPass; -use FOS\UserBundle\DependencyInjection\Compiler\ConfigurePasswordHasherPass; use FOS\UserBundle\DependencyInjection\Compiler\InjectRememberMeServicesPass; use FOS\UserBundle\DependencyInjection\Compiler\InjectUserCheckerPass; use FOS\UserBundle\DependencyInjection\Compiler\ValidationPass; @@ -31,7 +30,6 @@ final class FOSUserBundle extends Bundle public function build(ContainerBuilder $container): void { parent::build($container); - $container->addCompilerPass(new ConfigurePasswordHasherPass()); $container->addCompilerPass(new ValidationPass()); $container->addCompilerPass(new InjectUserCheckerPass()); $container->addCompilerPass(new InjectRememberMeServicesPass()); diff --git a/src/Model/UserInterface.php b/src/Model/UserInterface.php index 9cbfc5620..9f3b521f5 100644 --- a/src/Model/UserInterface.php +++ b/src/Model/UserInterface.php @@ -14,22 +14,6 @@ use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface as BaseUserInterface; -if (interface_exists(PasswordAuthenticatedUserInterface::class)) { - /** - * @internal Only for back compatibility. Remove / merge when dropping support for Symfony 4 - */ - interface CompatUserInterface extends PasswordAuthenticatedUserInterface, BaseUserInterface - { - } -} else { - /** - * @internal Only for back compatibility. Remove / merge when dropping support for Symfony 4 - */ - interface CompatUserInterface extends BaseUserInterface - { - } -} - /** * Implementations of that interface must be serializable. The mechanism * being used to support serialization is up for the implementation. @@ -40,7 +24,7 @@ interface CompatUserInterface extends BaseUserInterface * @author Johannes M. Schmitt * @author Julian Finkler */ -interface UserInterface extends CompatUserInterface +interface UserInterface extends PasswordAuthenticatedUserInterface, BaseUserInterface { public const ROLE_DEFAULT = 'ROLE_USER'; diff --git a/src/Security/LoginManager.php b/src/Security/LoginManager.php index 014f58041..7f606de23 100644 --- a/src/Security/LoginManager.php +++ b/src/Security/LoginManager.php @@ -16,10 +16,8 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; -use Symfony\Component\Security\Core\Authorization\Voter\CacheableVoterInterface; use Symfony\Component\Security\Core\User\UserCheckerInterface; use Symfony\Component\Security\Http\RememberMe\RememberMeHandlerInterface; -use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface; use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface; /** @@ -50,22 +48,15 @@ class LoginManager implements LoginManagerInterface private $requestStack; /** - * @var RememberMeHandlerInterface|RememberMeServicesInterface|null + * @var RememberMeHandlerInterface|null */ private $rememberMeHandler; - /** - * @param RememberMeHandlerInterface|RememberMeServicesInterface|null $rememberMeHandler - */ public function __construct(TokenStorageInterface $tokenStorage, UserCheckerInterface $userChecker, SessionAuthenticationStrategyInterface $sessionStrategy, RequestStack $requestStack, - $rememberMeHandler = null + ?RememberMeHandlerInterface $rememberMeHandler = null ) { - if (null !== $rememberMeHandler && !$rememberMeHandler instanceof RememberMeHandlerInterface && !$rememberMeHandler instanceof RememberMeServicesInterface) { - throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be an instance of "%s|%s|null", "%s" given.', __METHOD__, RememberMeHandlerInterface::class, RememberMeServicesInterface::class, \is_object($rememberMeHandler) ? \get_class($rememberMeHandler) : \gettype($rememberMeHandler))); - } - $this->tokenStorage = $tokenStorage; $this->userChecker = $userChecker; $this->sessionStrategy = $sessionStrategy; @@ -83,9 +74,7 @@ final public function logInUser($firewallName, UserInterface $user, ?Response $r if (null !== $request) { $this->sessionStrategy->onAuthentication($request, $token); - if (null !== $response && $this->rememberMeHandler instanceof RememberMeServicesInterface) { - $this->rememberMeHandler->loginSuccess($request, $response, $token); - } elseif ($this->rememberMeHandler instanceof RememberMeHandlerInterface) { + if ($this->rememberMeHandler instanceof RememberMeHandlerInterface) { $this->rememberMeHandler->createRememberMeCookie($user); } } @@ -100,11 +89,6 @@ final public function logInUser($firewallName, UserInterface $user, ?Response $r */ protected function createToken($firewall, UserInterface $user) { - // Bc layer for Symfony <5.4 - if (!interface_exists(CacheableVoterInterface::class)) { - return new UsernamePasswordToken($user, null, $firewall, $user->getRoles()); - } - return new UsernamePasswordToken($user, $firewall, $user->getRoles()); } } diff --git a/src/Util/UserManipulator.php b/src/Util/UserManipulator.php index 8b1e289f1..9554ec9a7 100644 --- a/src/Util/UserManipulator.php +++ b/src/Util/UserManipulator.php @@ -11,7 +11,6 @@ namespace FOS\UserBundle\Util; -use FOS\UserBundle\CompatibilityUtil; use FOS\UserBundle\Event\UserEvent; use FOS\UserBundle\FOSUserEvents; use FOS\UserBundle\Model\UserInterface; @@ -55,7 +54,7 @@ class UserManipulator public function __construct(UserManagerInterface $userManager, EventDispatcherInterface $dispatcher, RequestStack $requestStack) { $this->userManager = $userManager; - $this->dispatcher = CompatibilityUtil::upgradeEventDispatcher($dispatcher); + $this->dispatcher = $dispatcher; $this->requestStack = $requestStack; } diff --git a/tests/Util/CanonicalizerTest.php b/tests/Util/CanonicalizerTest.php index 3216c4abf..2fff2aaf3 100644 --- a/tests/Util/CanonicalizerTest.php +++ b/tests/Util/CanonicalizerTest.php @@ -33,7 +33,7 @@ public function canonicalizeProvider() return [ [null, null], ['FOO', 'foo'], - [chr(171), PHP_VERSION_ID < 50600 ? chr(171) : '?'], + [chr(171), '?'], ]; } } diff --git a/tests/Util/PasswordUpdaterTest.php b/tests/Util/PasswordUpdaterTest.php deleted file mode 100644 index 621a24921..000000000 --- a/tests/Util/PasswordUpdaterTest.php +++ /dev/null @@ -1,126 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace FOS\UserBundle\Tests\Util; - -use FOS\UserBundle\Tests\TestUser; -use FOS\UserBundle\Util\PasswordUpdater; -use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase; -use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface; -use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface; - -/** - * @group legacy - */ -class PasswordUpdaterTest extends TestCase -{ - /** - * @var PasswordUpdater - */ - private $updater; - /** - * @var EncoderFactoryInterface&MockObject - */ - private $encoderFactory; - - protected function setUp(): void - { - if (!interface_exists(EncoderFactoryInterface::class)) { - $this->markTestSkipped('The PasswordUpdater class does not support Symfony 6+.'); - } - - $this->encoderFactory = $this->getMockBuilder(EncoderFactoryInterface::class)->getMock(); - - $this->updater = new PasswordUpdater($this->encoderFactory); - } - - public function testUpdatePassword() - { - $encoder = $this->getMockPasswordEncoder(); - $user = new TestUser(); - $user->setPlainPassword('password'); - - $this->encoderFactory->expects($this->once()) - ->method('getEncoder') - ->with($user) - ->will($this->returnValue($encoder)); - - $encoder->expects($this->once()) - ->method('encodePassword') - ->with('password', $this->isType('string')) - ->will($this->returnValue('encodedPassword')); - - $this->updater->hashPassword($user); - $this->assertSame('encodedPassword', $user->getPassword(), '->updatePassword() sets encoded password'); - $this->assertNotNull($user->getSalt()); - $this->assertNull($user->getPlainPassword(), '->updatePassword() erases credentials'); - } - - public function testUpdatePasswordWithBCrypt() - { - if (!class_exists('Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder')) { - $this->markTestSkipped('This test requires Symfony 4'); - } - - $encoder = $this->getMockBuilder('Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder') - ->disableOriginalConstructor() - ->getMock(); - $user = new TestUser(); - $user->setPlainPassword('password'); - $user->setSalt('old_salt'); - - $this->encoderFactory->expects($this->once()) - ->method('getEncoder') - ->with($user) - ->will($this->returnValue($encoder)); - - $encoder->expects($this->once()) - ->method('encodePassword') - ->with('password', $this->isNull()) - ->will($this->returnValue('encodedPassword')); - - $this->updater->hashPassword($user); - $this->assertSame('encodedPassword', $user->getPassword(), '->updatePassword() sets encoded password'); - $this->assertNull($user->getSalt()); - $this->assertNull($user->getPlainPassword(), '->updatePassword() erases credentials'); - } - - public function testDoesNotUpdateWithEmptyPlainPassword() - { - $user = new TestUser(); - $user->setPassword('hash'); - - $user->setPlainPassword(''); - - $this->updater->hashPassword($user); - $this->assertSame('hash', $user->getPassword()); - } - - public function testDoesNotUpdateWithoutPlainPassword() - { - $user = new TestUser(); - $user->setPassword('hash'); - - $user->setPlainPassword(null); - - $this->updater->hashPassword($user); - $this->assertSame('hash', $user->getPassword()); - } - - /** - * @return PasswordEncoderInterface&MockObject - */ - private function getMockPasswordEncoder() - { - return $this->getMockBuilder(PasswordEncoderInterface::class)->getMock(); - } -}