diff --git a/.travis.yml b/.travis.yml index f8a502c985..5fd7131ea3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ php: - 5.6 - 7.0 - 7.1 - - hhvm env: global: @@ -19,9 +18,9 @@ matrix: - php: 5.5 env: COMPOSER_FLAGS="--prefer-lowest" - php: 5.6 - env: SYMFONY_VERSION=2.8.* - allow_failures: - - php: hhvm + env: DEPENDENCIES="symfony/lts:^2" + - php: 7.1 + env: DEPENDENCIES="symfony/lts:^3" sudo: false @@ -30,8 +29,8 @@ cache: - $HOME/.composer/cache before_install: - - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi; - - if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then echo "memory_limit=2G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi; + - if [[ -v $DEPENDENCIES ]]; then composer require --no-update $DEPENDENCIES; fi; + - echo "memory_limit=2G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini install: composer update --prefer-dist --no-interaction $COMPOSER_FLAGS diff --git a/Command/ActivateUserCommand.php b/Command/ActivateUserCommand.php index 1325e33f13..da4ed633e5 100644 --- a/Command/ActivateUserCommand.php +++ b/Command/ActivateUserCommand.php @@ -11,7 +11,8 @@ namespace FOS\UserBundle\Command; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use FOS\UserBundle\Util\UserManipulator; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -20,8 +21,19 @@ /** * @author Antoine Hérault */ -class ActivateUserCommand extends ContainerAwareCommand +class ActivateUserCommand extends Command { + protected static $defaultName = 'fos:user:activate'; + + private $userManipulator; + + public function __construct(UserManipulator $userManipulator) + { + parent::__construct(); + + $this->userManipulator = $userManipulator; + } + /** * {@inheritdoc} */ @@ -48,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getArgument('username'); - $manipulator = $this->getContainer()->get('fos_user.util.user_manipulator'); + $manipulator = $this->userManipulator; $manipulator->activate($username); $output->writeln(sprintf('User "%s" has been activated.', $username)); diff --git a/Command/ChangePasswordCommand.php b/Command/ChangePasswordCommand.php index 8db1d14cbe..d337e08f09 100644 --- a/Command/ChangePasswordCommand.php +++ b/Command/ChangePasswordCommand.php @@ -11,7 +11,8 @@ namespace FOS\UserBundle\Command; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use FOS\UserBundle\Util\UserManipulator; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -20,8 +21,19 @@ /** * ChangePasswordCommand. */ -class ChangePasswordCommand extends ContainerAwareCommand +class ChangePasswordCommand extends Command { + protected static $defaultName = 'fos:user:change-password'; + + private $userManipulator; + + public function __construct(UserManipulator $userManipulator) + { + parent::__construct(); + + $this->userManipulator = $userManipulator; + } + /** * {@inheritdoc} */ @@ -57,7 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $username = $input->getArgument('username'); $password = $input->getArgument('password'); - $manipulator = $this->getContainer()->get('fos_user.util.user_manipulator'); + $manipulator = $this->userManipulator; $manipulator->changePassword($username, $password); $output->writeln(sprintf('Changed password for user %s', $username)); diff --git a/Command/CreateUserCommand.php b/Command/CreateUserCommand.php index 793bc8f20d..f1dabade20 100644 --- a/Command/CreateUserCommand.php +++ b/Command/CreateUserCommand.php @@ -11,7 +11,8 @@ namespace FOS\UserBundle\Command; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use FOS\UserBundle\Util\UserManipulator; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -23,8 +24,19 @@ * @author Thibault Duplessis * @author Luis Cordova */ -class CreateUserCommand extends ContainerAwareCommand +class CreateUserCommand extends Command { + protected static $defaultName = 'fos:user:create'; + + private $userManipulator; + + public function __construct(UserManipulator $userManipulator) + { + parent::__construct(); + + $this->userManipulator = $userManipulator; + } + /** * {@inheritdoc} */ @@ -74,7 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $inactive = $input->getOption('inactive'); $superadmin = $input->getOption('super-admin'); - $manipulator = $this->getContainer()->get('fos_user.util.user_manipulator'); + $manipulator = $this->userManipulator; $manipulator->create($username, $password, $email, !$inactive, $superadmin); $output->writeln(sprintf('Created user %s', $username)); diff --git a/Command/DeactivateUserCommand.php b/Command/DeactivateUserCommand.php index e555fa8799..210eff075a 100644 --- a/Command/DeactivateUserCommand.php +++ b/Command/DeactivateUserCommand.php @@ -11,7 +11,8 @@ namespace FOS\UserBundle\Command; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use FOS\UserBundle\Util\UserManipulator; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -20,8 +21,19 @@ /** * @author Antoine Hérault */ -class DeactivateUserCommand extends ContainerAwareCommand +class DeactivateUserCommand extends Command { + protected static $defaultName = 'fos:user:deactivate'; + + private $userManipulator; + + public function __construct(UserManipulator $userManipulator) + { + parent::__construct(); + + $this->userManipulator = $userManipulator; + } + /** * {@inheritdoc} */ @@ -48,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getArgument('username'); - $manipulator = $this->getContainer()->get('fos_user.util.user_manipulator'); + $manipulator = $this->userManipulator; $manipulator->deactivate($username); $output->writeln(sprintf('User "%s" has been deactivated.', $username)); diff --git a/Command/DemoteUserCommand.php b/Command/DemoteUserCommand.php index 35b1fe6477..44c4cef1dc 100644 --- a/Command/DemoteUserCommand.php +++ b/Command/DemoteUserCommand.php @@ -20,6 +20,8 @@ */ class DemoteUserCommand extends RoleCommand { + protected static $defaultName = 'fos:user:demote'; + /** * {@inheritdoc} */ diff --git a/Command/PromoteUserCommand.php b/Command/PromoteUserCommand.php index fe411b9b0c..0b78de2f8c 100644 --- a/Command/PromoteUserCommand.php +++ b/Command/PromoteUserCommand.php @@ -22,6 +22,8 @@ */ class PromoteUserCommand extends RoleCommand { + protected static $defaultName = 'fos:user:promote'; + /** * {@inheritdoc} */ diff --git a/Command/RoleCommand.php b/Command/RoleCommand.php index 2dc82172e2..ac723aa881 100644 --- a/Command/RoleCommand.php +++ b/Command/RoleCommand.php @@ -12,7 +12,7 @@ namespace FOS\UserBundle\Command; use FOS\UserBundle\Util\UserManipulator; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -22,8 +22,17 @@ /** * @author Lenar Lõhmus */ -abstract class RoleCommand extends ContainerAwareCommand +abstract class RoleCommand extends Command { + private $userManipulator; + + public function __construct(UserManipulator $userManipulator) + { + parent::__construct(); + + $this->userManipulator = $userManipulator; + } + /** * {@inheritdoc} */ @@ -54,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output) throw new \RuntimeException('Not enough arguments.'); } - $manipulator = $this->getContainer()->get('fos_user.util.user_manipulator'); + $manipulator = $this->userManipulator; $this->executeRoleCommand($manipulator, $output, $username, $super, $role); } diff --git a/Controller/ChangePasswordController.php b/Controller/ChangePasswordController.php index 8d76a7abd3..b23430cc88 100644 --- a/Controller/ChangePasswordController.php +++ b/Controller/ChangePasswordController.php @@ -18,7 +18,7 @@ use FOS\UserBundle\FOSUserEvents; use FOS\UserBundle\Model\UserInterface; use FOS\UserBundle\Model\UserManagerInterface; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -31,8 +31,19 @@ * @author Thibault Duplessis * @author Christophe Coevoet */ -class ChangePasswordController extends Controller +class ChangePasswordController extends AbstractController { + private $eventDispatcher; + private $formFactory; + private $userManager; + + public function __construct(EventDispatcherInterface $eventDispatcher, FactoryInterface $formFactory, UserManagerInterface $userManager) + { + $this->eventDispatcher = $eventDispatcher; + $this->formFactory = $formFactory; + $this->userManager = $userManager; + } + /** * Change user password. * @@ -47,8 +58,7 @@ public function changePasswordAction(Request $request) throw new AccessDeniedException('This user does not have access to this section.'); } - /** @var $dispatcher EventDispatcherInterface */ - $dispatcher = $this->get('event_dispatcher'); + $dispatcher = $this->eventDispatcher; $event = new GetResponseUserEvent($user, $request); $dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_INITIALIZE, $event); @@ -57,22 +67,16 @@ public function changePasswordAction(Request $request) return $event->getResponse(); } - /** @var $formFactory FactoryInterface */ - $formFactory = $this->get('fos_user.change_password.form.factory'); - - $form = $formFactory->createForm(); + $form = $this->formFactory->createForm(); $form->setData($user); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - /** @var $userManager UserManagerInterface */ - $userManager = $this->get('fos_user.user_manager'); - $event = new FormEvent($form, $request); $dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_SUCCESS, $event); - $userManager->updateUser($user); + $this->userManager->updateUser($user); if (null === $response = $event->getResponse()) { $url = $this->generateUrl('fos_user_profile_show'); diff --git a/Controller/GroupController.php b/Controller/GroupController.php index e0853d955b..ff74473d0d 100644 --- a/Controller/GroupController.php +++ b/Controller/GroupController.php @@ -18,7 +18,8 @@ use FOS\UserBundle\Form\Factory\FactoryInterface; use FOS\UserBundle\FOSUserEvents; use FOS\UserBundle\Model\GroupInterface; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use FOS\UserBundle\Model\GroupManagerInterface; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -31,17 +32,26 @@ * @author Thibault Duplessis * @author Christophe Coevoet */ -class GroupController extends Controller +class GroupController extends AbstractController { + private $eventDispatcher; + private $formFactory; + private $groupManager; + + public function __construct(EventDispatcherInterface $eventDispatcher, FactoryInterface $formFactory, GroupManagerInterface $groupManager) + { + $this->eventDispatcher = $eventDispatcher; + $this->formFactory = $formFactory; + $this->groupManager = $groupManager; + } + /** * Show all groups. */ public function listAction() { - $groups = $this->get('fos_user.group_manager')->findGroups(); - return $this->render('@FOSUser/Group/list.html.twig', array( - 'groups' => $groups, + 'groups' => $this->groupManager->findGroups(), )); } @@ -54,10 +64,8 @@ public function listAction() */ public function showAction($groupName) { - $group = $this->findGroupBy('name', $groupName); - return $this->render('@FOSUser/Group/show.html.twig', array( - 'group' => $group, + 'group' => $this->findGroupBy('name', $groupName), )); } @@ -73,8 +81,7 @@ public function editAction(Request $request, $groupName) { $group = $this->findGroupBy('name', $groupName); - /** @var $dispatcher EventDispatcherInterface */ - $dispatcher = $this->get('event_dispatcher'); + $dispatcher = $this->eventDispatcher; $event = new GetResponseGroupEvent($group, $request); $dispatcher->dispatch(FOSUserEvents::GROUP_EDIT_INITIALIZE, $event); @@ -83,22 +90,16 @@ public function editAction(Request $request, $groupName) return $event->getResponse(); } - /** @var $formFactory FactoryInterface */ - $formFactory = $this->get('fos_user.group.form.factory'); - - $form = $formFactory->createForm(); + $form = $this->formFactory->createForm(); $form->setData($group); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - /** @var $groupManager \FOS\UserBundle\Model\GroupManagerInterface */ - $groupManager = $this->get('fos_user.group_manager'); - $event = new FormEvent($form, $request); $dispatcher->dispatch(FOSUserEvents::GROUP_EDIT_SUCCESS, $event); - $groupManager->updateGroup($group); + $this->groupManager->updateGroup($group); if (null === $response = $event->getResponse()) { $url = $this->generateUrl('fos_user_group_show', array('groupName' => $group->getName())); @@ -125,18 +126,14 @@ public function editAction(Request $request, $groupName) */ public function newAction(Request $request) { - /** @var $groupManager \FOS\UserBundle\Model\GroupManagerInterface */ - $groupManager = $this->get('fos_user.group_manager'); - /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */ - $formFactory = $this->get('fos_user.group.form.factory'); - /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */ - $dispatcher = $this->get('event_dispatcher'); + $groupManager = $this->groupManager; + $dispatcher = $this->eventDispatcher; $group = $groupManager->createGroup(''); $dispatcher->dispatch(FOSUserEvents::GROUP_CREATE_INITIALIZE, new GroupEvent($group, $request)); - $form = $formFactory->createForm(); + $form = $this->formFactory->createForm(); $form->setData($group); $form->handleRequest($request); @@ -173,13 +170,11 @@ public function newAction(Request $request) public function deleteAction(Request $request, $groupName) { $group = $this->findGroupBy('name', $groupName); - $this->get('fos_user.group_manager')->deleteGroup($group); + $this->groupManager->deleteGroup($group); $response = new RedirectResponse($this->generateUrl('fos_user_group_list')); - /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */ - $dispatcher = $this->get('event_dispatcher'); - $dispatcher->dispatch(FOSUserEvents::GROUP_DELETE_COMPLETED, new FilterGroupResponseEvent($group, $request, $response)); + $this->eventDispatcher->dispatch(FOSUserEvents::GROUP_DELETE_COMPLETED, new FilterGroupResponseEvent($group, $request, $response)); return $response; } @@ -197,7 +192,7 @@ public function deleteAction(Request $request, $groupName) protected function findGroupBy($key, $value) { if (!empty($value)) { - $group = $this->get('fos_user.group_manager')->{'findGroupBy'.ucfirst($key)}($value); + $group = $this->groupManager->{'findGroupBy'.ucfirst($key)}($value); } if (empty($group)) { diff --git a/Controller/ProfileController.php b/Controller/ProfileController.php index 574c38841f..ce4b0c315e 100644 --- a/Controller/ProfileController.php +++ b/Controller/ProfileController.php @@ -21,21 +21,37 @@ use FOS\UserBundle\Model\UserInterface; use FOS\UserBundle\Model\UserManagerInterface; use FOS\UserBundle\Services\EmailConfirmation\EmailUpdateConfirmation; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Translation\Translator; +use Symfony\Component\Translation\TranslatorInterface; /** * Controller managing the user profile. * * @author Christophe Coevoet */ -class ProfileController extends Controller +class ProfileController extends AbstractController { + private $eventDispatcher; + private $formFactory; + private $userManager; + private $emailUpdateConfirmation; + private $translator; + + public function __construct(EventDispatcherInterface $eventDispatcher, FactoryInterface $formFactory, UserManagerInterface $userManager, EmailUpdateConfirmation $emailUpdateConfirmation, TranslatorInterface $translator) + { + $this->eventDispatcher = $eventDispatcher; + $this->formFactory = $formFactory; + $this->userManager = $userManager; + $this->emailUpdateConfirmation = $emailUpdateConfirmation; + $this->translator = $translator; + } + /** * Show the user. */ @@ -65,8 +81,7 @@ public function editAction(Request $request) throw new AccessDeniedException('This user does not have access to this section.'); } - /** @var $dispatcher EventDispatcherInterface */ - $dispatcher = $this->get('event_dispatcher'); + $dispatcher = $this->eventDispatcher; $event = new GetResponseUserEvent($user, $request); $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_INITIALIZE, $event); @@ -75,22 +90,16 @@ public function editAction(Request $request) return $event->getResponse(); } - /** @var $formFactory FactoryInterface */ - $formFactory = $this->get('fos_user.profile.form.factory'); - - $form = $formFactory->createForm(); + $form = $this->formFactory->createForm(); $form->setData($user); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - /** @var $userManager UserManagerInterface */ - $userManager = $this->get('fos_user.user_manager'); - $event = new FormEvent($form, $request); $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_SUCCESS, $event); - $userManager->updateUser($user); + $this->userManager->updateUser($user); if (null === $response = $event->getResponse()) { $url = $this->generateUrl('fos_user_profile_show'); @@ -117,42 +126,33 @@ public function editAction(Request $request) */ public function confirmEmailUpdateAction(Request $request, $token) { - $userManager = $this->container->get('fos_user.user_manager'); - /** @var User $user */ - $user = $userManager->findUserByConfirmationToken($token); + $user = $this->userManager->findUserByConfirmationToken($token); // If user was not found throw 404 exception if (!$user) { - /** @var Translator $translator */ - $translator = $this->get('translator'); - throw $this->createNotFoundException($translator->trans('email_update.error.message', array(), 'FOSUserBundle')); + throw $this->createNotFoundException($this->translator->trans('email_update.error.message', array(), 'FOSUserBundle')); } // Show invalid token message if the user id found via token does not match the current users id (e.g. anon. or other user) if (!($this->getUser() instanceof UserInterface) || ($user->getId() !== $this->getUser()->getId())) { - /** @var Translator $translator */ - $translator = $this->get('translator'); - throw new AccessDeniedException($translator->trans('email_update.error.message', array(), 'FOSUserBundle')); + throw new AccessDeniedException($this->translator->trans('email_update.error.message', array(), 'FOSUserBundle')); } - /** @var EmailUpdateConfirmation $emailUpdateConfirmation */ - $emailUpdateConfirmation = $this->get('fos_user.email_update_confirmation'); - - $emailUpdateConfirmation->setUser($user); + $this->emailUpdateConfirmation->setUser($user); - $newEmail = $emailUpdateConfirmation->fetchEncryptedEmailFromConfirmationLink($request->get('target')); + $newEmail = $this->emailUpdateConfirmation->fetchEncryptedEmailFromConfirmationLink($request->get('target')); // Update user email if ($newEmail) { - $user->setConfirmationToken($emailUpdateConfirmation->getEmailConfirmedToken()); + $user->setConfirmationToken($this->emailUpdateConfirmation->getEmailConfirmedToken()); $user->setEmail($newEmail); } - $userManager->updateUser($user); + $this->userManager->updateUser($user); $event = new UserEvent($user, $request); - $this->get('event_dispatcher')->dispatch(FOSUserEvents::EMAIL_UPDATE_SUCCESS, $event); + $this->eventDispatcher->dispatch(FOSUserEvents::EMAIL_UPDATE_SUCCESS, $event); return $this->redirect($this->generateUrl('fos_user_profile_show')); } diff --git a/Controller/RegistrationController.php b/Controller/RegistrationController.php index eb468f3e67..d4c0dde2b0 100644 --- a/Controller/RegistrationController.php +++ b/Controller/RegistrationController.php @@ -18,12 +18,14 @@ use FOS\UserBundle\FOSUserEvents; use FOS\UserBundle\Model\UserInterface; use FOS\UserBundle\Model\UserManagerInterface; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Exception\AccessDeniedException; /** @@ -32,8 +34,21 @@ * @author Thibault Duplessis * @author Christophe Coevoet */ -class RegistrationController extends Controller +class RegistrationController extends AbstractController { + private $eventDispatcher; + private $formFactory; + private $userManager; + private $tokenStorage; + + public function __construct(EventDispatcherInterface $eventDispatcher, FactoryInterface $formFactory, UserManagerInterface $userManager, TokenStorageInterface $tokenStorage) + { + $this->eventDispatcher = $eventDispatcher; + $this->formFactory = $formFactory; + $this->userManager = $userManager; + $this->tokenStorage = $tokenStorage; + } + /** * @param Request $request * @@ -41,12 +56,8 @@ class RegistrationController extends Controller */ public function registerAction(Request $request) { - /** @var $formFactory FactoryInterface */ - $formFactory = $this->get('fos_user.registration.form.factory'); - /** @var $userManager UserManagerInterface */ - $userManager = $this->get('fos_user.user_manager'); - /** @var $dispatcher EventDispatcherInterface */ - $dispatcher = $this->get('event_dispatcher'); + $userManager = $this->userManager; + $dispatcher = $this->eventDispatcher; $user = $userManager->createUser(); $user->setEnabled(true); @@ -58,7 +69,7 @@ public function registerAction(Request $request) return $event->getResponse(); } - $form = $formFactory->createForm(); + $form = $this->formFactory->createForm(); $form->setData($user); $form->handleRequest($request); @@ -96,16 +107,16 @@ public function registerAction(Request $request) /** * Tell the user to check their email provider. */ - public function checkEmailAction() + public function checkEmailAction(Request $request) { - $email = $this->get('session')->get('fos_user_send_confirmation_email/email'); + $email = $request->getSession()->get('fos_user_send_confirmation_email/email'); if (empty($email)) { - return new RedirectResponse($this->get('router')->generate('fos_user_registration_register')); + return new RedirectResponse($this->generateUrl('fos_user_registration_register')); } - $this->get('session')->remove('fos_user_send_confirmation_email/email'); - $user = $this->get('fos_user.user_manager')->findUserByEmail($email); + $request->getSession()->remove('fos_user_send_confirmation_email/email'); + $user = $this->userManager->findUserByEmail($email); if (null === $user) { throw new NotFoundHttpException(sprintf('The user with email "%s" does not exist', $email)); @@ -126,8 +137,7 @@ public function checkEmailAction() */ public function confirmAction(Request $request, $token) { - /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */ - $userManager = $this->get('fos_user.user_manager'); + $userManager = $this->userManager; $user = $userManager->findUserByConfirmationToken($token); @@ -135,8 +145,7 @@ public function confirmAction(Request $request, $token) throw new NotFoundHttpException(sprintf('The user with confirmation token "%s" does not exist', $token)); } - /** @var $dispatcher EventDispatcherInterface */ - $dispatcher = $this->get('event_dispatcher'); + $dispatcher = $this->eventDispatcher; $user->setConfirmationToken(null); $user->setEnabled(true); @@ -159,7 +168,7 @@ public function confirmAction(Request $request, $token) /** * Tell the user his account is now confirmed. */ - public function confirmedAction() + public function confirmedAction(Request $request) { $user = $this->getUser(); if (!is_object($user) || !$user instanceof UserInterface) { @@ -168,19 +177,19 @@ public function confirmedAction() return $this->render('@FOSUser/Registration/confirmed.html.twig', array( 'user' => $user, - 'targetUrl' => $this->getTargetUrlFromSession(), + 'targetUrl' => $this->getTargetUrlFromSession($request->getSession()), )); } /** * @return mixed */ - private function getTargetUrlFromSession() + private function getTargetUrlFromSession(SessionInterface $session) { - $key = sprintf('_security.%s.target_path', $this->get('security.token_storage')->getToken()->getProviderKey()); + $key = sprintf('_security.%s.target_path', $this->tokenStorage->getToken()->getProviderKey()); - if ($this->get('session')->has($key)) { - return $this->get('session')->get($key); + if ($session->has($key)) { + return $session->get($key); } } } diff --git a/Controller/ResettingController.php b/Controller/ResettingController.php index e63fbc3259..020c1bed2b 100644 --- a/Controller/ResettingController.php +++ b/Controller/ResettingController.php @@ -15,10 +15,13 @@ use FOS\UserBundle\Event\FormEvent; use FOS\UserBundle\Event\GetResponseNullableUserEvent; use FOS\UserBundle\Event\GetResponseUserEvent; +use FOS\UserBundle\Form\Factory\FactoryInterface; use FOS\UserBundle\FOSUserEvents; +use FOS\UserBundle\Mailer\MailerInterface; use FOS\UserBundle\Model\UserInterface; +use FOS\UserBundle\Model\UserManagerInterface; use FOS\UserBundle\Util\TokenGeneratorInterface; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -30,8 +33,25 @@ * @author Thibault Duplessis * @author Christophe Coevoet */ -class ResettingController extends Controller +class ResettingController extends AbstractController { + private $eventDispatcher; + private $formFactory; + private $userManager; + private $tokenGenerator; + private $mailer; + private $retryTtl; + + public function __construct(EventDispatcherInterface $eventDispatcher, FactoryInterface $formFactory, UserManagerInterface $userManager, TokenGeneratorInterface $tokenGenerator, MailerInterface $mailer, $retryTtl) + { + $this->eventDispatcher = $eventDispatcher; + $this->formFactory = $formFactory; + $this->userManager = $userManager; + $this->tokenGenerator = $tokenGenerator; + $this->mailer = $mailer; + $this->retryTtl = $retryTtl; + } + /** * Request reset user password: show form. */ @@ -52,9 +72,8 @@ public function sendEmailAction(Request $request) $username = $request->request->get('username'); /** @var $user UserInterface */ - $user = $this->get('fos_user.user_manager')->findUserByUsernameOrEmail($username); - /** @var $dispatcher EventDispatcherInterface */ - $dispatcher = $this->get('event_dispatcher'); + $user = $this->userManager->findUserByUsernameOrEmail($username); + $dispatcher = $this->eventDispatcher; /* Dispatch init event */ $event = new GetResponseNullableUserEvent($user, $request); @@ -64,9 +83,7 @@ public function sendEmailAction(Request $request) return $event->getResponse(); } - $ttl = $this->container->getParameter('fos_user.resetting.retry_ttl'); - - if (null !== $user && !$user->isPasswordRequestNonExpired($ttl)) { + if (null !== $user && !$user->isPasswordRequestNonExpired($this->retryTtl)) { $event = new GetResponseUserEvent($user, $request); $dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_REQUEST, $event); @@ -75,9 +92,7 @@ public function sendEmailAction(Request $request) } if (null === $user->getConfirmationToken()) { - /** @var $tokenGenerator TokenGeneratorInterface */ - $tokenGenerator = $this->get('fos_user.util.token_generator'); - $user->setConfirmationToken($tokenGenerator->generateToken()); + $user->setConfirmationToken($this->tokenGenerator->generateToken()); } /* Dispatch confirm event */ @@ -88,9 +103,9 @@ public function sendEmailAction(Request $request) return $event->getResponse(); } - $this->get('fos_user.mailer')->sendResettingEmailMessage($user); + $this->mailer->sendResettingEmailMessage($user); $user->setPasswordRequestedAt(new \DateTime()); - $this->get('fos_user.user_manager')->updateUser($user); + $this->userManager->updateUser($user); /* Dispatch completed event */ $event = new GetResponseUserEvent($user, $request); @@ -121,7 +136,7 @@ public function checkEmailAction(Request $request) } return $this->render('@FOSUser/Resetting/check_email.html.twig', array( - 'tokenLifetime' => ceil($this->container->getParameter('fos_user.resetting.retry_ttl') / 3600), + 'tokenLifetime' => ceil($this->retryTtl / 3600), )); } @@ -135,12 +150,8 @@ public function checkEmailAction(Request $request) */ public function resetAction(Request $request, $token) { - /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */ - $formFactory = $this->get('fos_user.resetting.form.factory'); - /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */ - $userManager = $this->get('fos_user.user_manager'); - /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */ - $dispatcher = $this->get('event_dispatcher'); + $userManager = $this->userManager; + $dispatcher = $this->eventDispatcher; $user = $userManager->findUserByConfirmationToken($token); @@ -155,7 +166,7 @@ public function resetAction(Request $request, $token) return $event->getResponse(); } - $form = $formFactory->createForm(); + $form = $this->formFactory->createForm(); $form->setData($user); $form->handleRequest($request); diff --git a/Controller/SecurityController.php b/Controller/SecurityController.php index 4a2ab1b01e..a8177760c9 100644 --- a/Controller/SecurityController.php +++ b/Controller/SecurityController.php @@ -11,15 +11,23 @@ namespace FOS\UserBundle\Controller; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\Security; +use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; -class SecurityController extends Controller +class SecurityController extends AbstractController { + private $tokenManager; + + public function __construct(CsrfTokenManagerInterface $tokenManager = null) + { + $this->tokenManager = $tokenManager; + } + /** * @param Request $request * @@ -50,8 +58,8 @@ public function loginAction(Request $request) // last username entered by the user $lastUsername = (null === $session) ? '' : $session->get($lastUsernameKey); - $csrfToken = $this->has('security.csrf.token_manager') - ? $this->get('security.csrf.token_manager')->getToken('authenticate')->getValue() + $csrfToken = $this->tokenManager + ? $this->tokenManager->getToken('authenticate')->getValue() : null; return $this->renderLogin(array( diff --git a/DependencyInjection/Compiler/CheckForMailerPass.php b/DependencyInjection/Compiler/CheckForMailerPass.php new file mode 100644 index 0000000000..fa2ee0414f --- /dev/null +++ b/DependencyInjection/Compiler/CheckForMailerPass.php @@ -0,0 +1,50 @@ + + * + * 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 Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Flex\Recipe; + +/** + * Checks to see if the mailer service exists. + * + * @author Ryan Weaver + */ +class CheckForMailerPass implements CompilerPassInterface +{ + /** + * {@inheritdoc} + */ + public function process(ContainerBuilder $container) + { + // if the mailer isn't needed, then no error needed + if (!$container->has('fos_user.mailer')) { + return; + } + + // the mailer exists, so all is good + if ($container->has('mailer')) { + return; + } + + if ($container->findDefinition('fos_user.mailer')->hasTag('fos_user.requires_swift')) { + $message = 'A feature you activated in FOSUserBundle requires the "mailer" service to be available.'; + + if (class_exists(Recipe::class)) { + $message .= ' Run "composer require swiftmailer-bundle" to install SwiftMailer or configure a different mailer in "config/packages/fos_user.yaml".'; + } + + throw new \LogicException($message); + } + } +} diff --git a/DependencyInjection/Compiler/CheckForSessionPass.php b/DependencyInjection/Compiler/CheckForSessionPass.php new file mode 100644 index 0000000000..3b0b621fb6 --- /dev/null +++ b/DependencyInjection/Compiler/CheckForSessionPass.php @@ -0,0 +1,40 @@ + + * + * 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 Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Flex\Recipe; + +/** + * Checks to see if the session service exists. + * + * @author Ryan Weaver + */ +class CheckForSessionPass implements CompilerPassInterface +{ + /** + * {@inheritdoc} + */ + public function process(ContainerBuilder $container) + { + if (!$container->has('session')) { + $message = 'FOSUserBundle requires the "session" service to be available.'; + + if (class_exists(Recipe::class)) { + $message .= ' Uncomment the "session" section in "config/packages/framework.yaml" to activate it.'; + } + + throw new \LogicException($message); + } + } +} diff --git a/DependencyInjection/FOSUserExtension.php b/DependencyInjection/FOSUserExtension.php index 757fb1bafa..844b123dcd 100644 --- a/DependencyInjection/FOSUserExtension.php +++ b/DependencyInjection/FOSUserExtension.php @@ -40,6 +40,8 @@ class FOSUserExtension extends Extension ), ); + private $mailerNeeded = false; + /** * {@inheritdoc} */ @@ -79,11 +81,10 @@ public function load(array $configs, ContainerBuilder $container) $loader->load('flash_notifications.xml'); } - $container->setAlias('fos_user.mailer', $config['service']['mailer']); $container->setAlias('fos_user.util.email_canonicalizer', $config['service']['email_canonicalizer']); $container->setAlias('fos_user.util.username_canonicalizer', $config['service']['username_canonicalizer']); $container->setAlias('fos_user.util.token_generator', $config['service']['token_generator']); - $container->setAlias('fos_user.user_manager', $config['service']['user_manager']); + $container->setAlias('fos_user.user_manager', new Alias($config['service']['user_manager'], true)); $container->setAlias('FOS\UserBundle\Model\UserManagerInterface', new Alias('fos_user.user_manager', false)); if ($config['use_listener'] && isset(self::$doctrineDrivers[$config['db_driver']])) { @@ -126,6 +127,10 @@ public function load(array $configs, ContainerBuilder $container) if (!empty($config['group'])) { $this->loadGroups($config['group'], $container, $loader, $config['db_driver']); } + + if ($this->mailerNeeded) { + $container->setAlias('fos_user.mailer', $config['service']['mailer']); + } } /** @@ -163,6 +168,7 @@ private function loadRegistration(array $config, ContainerBuilder $container, Xm $loader->load('registration.xml'); if ($config['confirmation']['enabled']) { + $this->mailerNeeded = true; $loader->load('email_confirmation.xml'); } @@ -201,6 +207,7 @@ private function loadChangePassword(array $config, ContainerBuilder $container, */ private function loadResetting(array $config, ContainerBuilder $container, XmlFileLoader $loader, array $fromEmail) { + $this->mailerNeeded = true; $loader->load('resetting.xml'); if (isset($config['email']['from_email'])) { @@ -237,7 +244,7 @@ private function loadGroups(array $config, ContainerBuilder $container, XmlFileL } } - $container->setAlias('fos_user.group_manager', $config['group_manager']); + $container->setAlias('fos_user.group_manager', new Alias($config['group_manager'], true)); $container->setAlias('FOS\UserBundle\Model\GroupManagerInterface', new Alias('fos_user.group_manager', false)); $this->remapParametersNamespaces($config, $container, array( diff --git a/FOSUserBundle.php b/FOSUserBundle.php index a11f63e76d..e00208552f 100644 --- a/FOSUserBundle.php +++ b/FOSUserBundle.php @@ -14,6 +14,8 @@ use Doctrine\Bundle\CouchDBBundle\DependencyInjection\Compiler\DoctrineCouchDBMappingsPass; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass; use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass; +use FOS\UserBundle\DependencyInjection\Compiler\CheckForMailerPass; +use FOS\UserBundle\DependencyInjection\Compiler\CheckForSessionPass; use FOS\UserBundle\DependencyInjection\Compiler\InjectRememberMeServicesPass; use FOS\UserBundle\DependencyInjection\Compiler\InjectUserCheckerPass; use FOS\UserBundle\DependencyInjection\Compiler\ValidationPass; @@ -35,6 +37,8 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new ValidationPass()); $container->addCompilerPass(new InjectUserCheckerPass()); $container->addCompilerPass(new InjectRememberMeServicesPass()); + $container->addCompilerPass(new CheckForSessionPass()); + $container->addCompilerPass(new CheckForMailerPass()); $this->addRegisterMappingsPass($container); } diff --git a/Resources/config/change_password.xml b/Resources/config/change_password.xml index a2c7ba9f2a..77415b23d2 100644 --- a/Resources/config/change_password.xml +++ b/Resources/config/change_password.xml @@ -16,6 +16,12 @@ %fos_user.model.user.class% + + + + + + diff --git a/Resources/config/commands.xml b/Resources/config/commands.xml index 9602518a39..569e7ac343 100644 --- a/Resources/config/commands.xml +++ b/Resources/config/commands.xml @@ -6,21 +6,27 @@ + + + + + + diff --git a/Resources/config/group.xml b/Resources/config/group.xml index a6335cd531..9dae485330 100644 --- a/Resources/config/group.xml +++ b/Resources/config/group.xml @@ -16,6 +16,12 @@ %fos_user.model.group.class% + + + + + + diff --git a/Resources/config/mailer.xml b/Resources/config/mailer.xml index 7fa2be5e1d..b35313e308 100644 --- a/Resources/config/mailer.xml +++ b/Resources/config/mailer.xml @@ -24,6 +24,7 @@ %fos_user.resetting.email.from_email% + @@ -41,6 +42,7 @@ %fos_user.resetting.email.from_email% + diff --git a/Resources/config/profile.xml b/Resources/config/profile.xml index efe6d1dbba..dba23c16ca 100644 --- a/Resources/config/profile.xml +++ b/Resources/config/profile.xml @@ -18,6 +18,13 @@ + + + + + + + diff --git a/Resources/config/registration.xml b/Resources/config/registration.xml index edc2b0ed04..bf7fa4e01d 100644 --- a/Resources/config/registration.xml +++ b/Resources/config/registration.xml @@ -18,6 +18,12 @@ %fos_user.model.user.class% + + + + + + diff --git a/Resources/config/resetting.xml b/Resources/config/resetting.xml index 3d24abd866..0f69e69e68 100644 --- a/Resources/config/resetting.xml +++ b/Resources/config/resetting.xml @@ -24,6 +24,14 @@ %fos_user.resetting.token_ttl% + + + + + + + %fos_user.resetting.retry_ttl% + diff --git a/Resources/config/routing/change_password.xml b/Resources/config/routing/change_password.xml index 626c9489bd..21c1a00557 100644 --- a/Resources/config/routing/change_password.xml +++ b/Resources/config/routing/change_password.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - FOSUserBundle:ChangePassword:changePassword + fos_user.change_password.controller:changePasswordAction diff --git a/Resources/config/routing/group.xml b/Resources/config/routing/group.xml index 82fa1aaab3..32d6d8e832 100644 --- a/Resources/config/routing/group.xml +++ b/Resources/config/routing/group.xml @@ -5,23 +5,23 @@ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - FOSUserBundle:Group:list + fos_user.group.controller:listAction - FOSUserBundle:Group:new + fos_user.group.controller:newAction - FOSUserBundle:Group:show + fos_user.group.controller:showAction - FOSUserBundle:Group:edit + fos_user.group.controller:editAction - FOSUserBundle:Group:delete + fos_user.group.controller:deleteAction diff --git a/Resources/config/routing/profile.xml b/Resources/config/routing/profile.xml index f6c7ccf34b..606f747621 100644 --- a/Resources/config/routing/profile.xml +++ b/Resources/config/routing/profile.xml @@ -5,11 +5,11 @@ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - FOSUserBundle:Profile:show + fos_user.profiler.controller:showAction - FOSUserBundle:Profile:edit + fos_user.profiler.controller:editAction diff --git a/Resources/config/routing/registration.xml b/Resources/config/routing/registration.xml index 040c22e94b..328f6e8ede 100644 --- a/Resources/config/routing/registration.xml +++ b/Resources/config/routing/registration.xml @@ -5,19 +5,19 @@ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - FOSUserBundle:Registration:register + fos_user.registration.controller:registerAction - FOSUserBundle:Registration:checkEmail + fos_user.registration.controller:checkEmailAction - FOSUserBundle:Registration:confirm + fos_user.registration.controller:confirmAction - FOSUserBundle:Registration:confirmed + fos_user.registration.controller:confirmedAction diff --git a/Resources/config/routing/resetting.xml b/Resources/config/routing/resetting.xml index e3f87e3923..04fa409beb 100644 --- a/Resources/config/routing/resetting.xml +++ b/Resources/config/routing/resetting.xml @@ -5,19 +5,19 @@ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - FOSUserBundle:Resetting:request + fos_user.resetting.controller:requestAction - FOSUserBundle:Resetting:sendEmail + fos_user.resetting.controller:sendEmailAction - FOSUserBundle:Resetting:checkEmail + fos_user.resetting.controller:checkEmailAction - FOSUserBundle:Resetting:reset + fos_user.resetting.controller:resetAction diff --git a/Resources/config/routing/security.xml b/Resources/config/routing/security.xml index 51a2acbdd3..30f6ff74cd 100644 --- a/Resources/config/routing/security.xml +++ b/Resources/config/routing/security.xml @@ -5,15 +5,15 @@ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - FOSUserBundle:Security:login + fos_user.security.controller:loginAction - FOSUserBundle:Security:check + fos_user.security.controller:checkAction - FOSUserBundle:Security:logout + fos_user.security.controller:logoutAction diff --git a/Resources/config/routing/update_email.xml b/Resources/config/routing/update_email.xml index c7243cf7d3..131a94aa90 100644 --- a/Resources/config/routing/update_email.xml +++ b/Resources/config/routing/update_email.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - FOSUserBundle:Profile:confirmEmailUpdate + fos_user.profiler.controller:confirmEmailUpdateAction diff --git a/Resources/config/security.xml b/Resources/config/security.xml index 087a94f2e7..d58c1630a8 100644 --- a/Resources/config/security.xml +++ b/Resources/config/security.xml @@ -23,6 +23,8 @@ null + + @@ -30,6 +32,10 @@ + + + + diff --git a/Tests/Command/ActivateUserCommandTest.php b/Tests/Command/ActivateUserCommandTest.php index 2dd2b13bbc..2fcaa18f3b 100644 --- a/Tests/Command/ActivateUserCommandTest.php +++ b/Tests/Command/ActivateUserCommandTest.php @@ -12,16 +12,16 @@ namespace FOS\UserBundle\Tests\Command; use FOS\UserBundle\Command\ActivateUserCommand; +use FOS\UserBundle\Util\UserManipulator; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\DependencyInjection\ContainerInterface; class ActivateUserCommandTest extends TestCase { public function testExecute() { - $commandTester = $this->createCommandTester($this->getContainer('user')); + $commandTester = $this->createCommandTester($this->getManipulator('user')); $exitCode = $commandTester->execute(array( 'username' => 'user', ), array( @@ -47,7 +47,7 @@ public function testExecuteInteractiveWithQuestionHelper() $application->getHelperSet()->set($helper, 'question'); - $commandTester = $this->createCommandTester($this->getContainer('user'), $application); + $commandTester = $this->createCommandTester($this->getManipulator('user'), $application); $exitCode = $commandTester->execute(array(), array( 'decorated' => false, 'interactive' => true, @@ -58,12 +58,12 @@ public function testExecuteInteractiveWithQuestionHelper() } /** - * @param ContainerInterface $container - * @param Application|null $application + * @param UserManipulator $manipulator + * @param Application|null $application * * @return CommandTester */ - private function createCommandTester(ContainerInterface $container, Application $application = null) + private function createCommandTester(UserManipulator $manipulator, Application $application = null) { if (null === $application) { $application = new Application(); @@ -71,8 +71,7 @@ private function createCommandTester(ContainerInterface $container, Application $application->setAutoExit(false); - $command = new ActivateUserCommand(); - $command->setContainer($container); + $command = new ActivateUserCommand($manipulator); $application->add($command); @@ -84,10 +83,8 @@ private function createCommandTester(ContainerInterface $container, Application * * @return mixed */ - private function getContainer($username) + private function getManipulator($username) { - $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); - $manipulator = $this->getMockBuilder('FOS\UserBundle\Util\UserManipulator') ->disableOriginalConstructor() ->getMock(); @@ -98,12 +95,6 @@ private function getContainer($username) ->with($username) ; - $container - ->expects($this->once()) - ->method('get') - ->with('fos_user.util.user_manipulator') - ->will($this->returnValue($manipulator)); - - return $container; + return $manipulator; } } diff --git a/Tests/Command/ChangePasswordCommandTest.php b/Tests/Command/ChangePasswordCommandTest.php index e5815797fd..f9a135eed9 100644 --- a/Tests/Command/ChangePasswordCommandTest.php +++ b/Tests/Command/ChangePasswordCommandTest.php @@ -12,16 +12,16 @@ namespace FOS\UserBundle\Tests\Command; use FOS\UserBundle\Command\ChangePasswordCommand; +use FOS\UserBundle\Util\UserManipulator; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\DependencyInjection\ContainerInterface; class ChangePasswordCommandTest extends TestCase { public function testExecute() { - $commandTester = $this->createCommandTester($this->getContainer('user', 'pass')); + $commandTester = $this->createCommandTester($this->getManipulator('user', 'pass')); $exitCode = $commandTester->execute(array( 'username' => 'user', 'password' => 'pass', @@ -51,7 +51,7 @@ public function testExecuteInteractiveWithQuestionHelper() $application->getHelperSet()->set($helper, 'question'); - $commandTester = $this->createCommandTester($this->getContainer('user', 'pass'), $application); + $commandTester = $this->createCommandTester($this->getManipulator('user', 'pass'), $application); $exitCode = $commandTester->execute(array(), array( 'decorated' => false, 'interactive' => true, @@ -62,12 +62,12 @@ public function testExecuteInteractiveWithQuestionHelper() } /** - * @param ContainerInterface $container - * @param Application|null $application + * @param UserManipulator $container + * @param Application|null $application * * @return CommandTester */ - private function createCommandTester(ContainerInterface $container, Application $application = null) + private function createCommandTester(UserManipulator $userManipulator, Application $application = null) { if (null === $application) { $application = new Application(); @@ -75,8 +75,7 @@ private function createCommandTester(ContainerInterface $container, Application $application->setAutoExit(false); - $command = new ChangePasswordCommand(); - $command->setContainer($container); + $command = new ChangePasswordCommand($userManipulator); $application->add($command); @@ -89,10 +88,8 @@ private function createCommandTester(ContainerInterface $container, Application * * @return mixed */ - private function getContainer($username, $password) + private function getManipulator($username, $password) { - $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); - $manipulator = $this->getMockBuilder('FOS\UserBundle\Util\UserManipulator') ->disableOriginalConstructor() ->getMock(); @@ -103,12 +100,6 @@ private function getContainer($username, $password) ->with($username, $password) ; - $container - ->expects($this->once()) - ->method('get') - ->with('fos_user.util.user_manipulator') - ->will($this->returnValue($manipulator)); - - return $container; + return $manipulator; } } diff --git a/Tests/Command/CreateUserCommandTest.php b/Tests/Command/CreateUserCommandTest.php index 7d43115216..3882284ae2 100644 --- a/Tests/Command/CreateUserCommandTest.php +++ b/Tests/Command/CreateUserCommandTest.php @@ -12,16 +12,16 @@ namespace FOS\UserBundle\Tests\Command; use FOS\UserBundle\Command\CreateUserCommand; +use FOS\UserBundle\Util\UserManipulator; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\DependencyInjection\ContainerInterface; class CreateUserCommandTest extends TestCase { public function testExecute() { - $commandTester = $this->createCommandTester($this->getContainer('user', 'pass', 'email', true, false)); + $commandTester = $this->createCommandTester($this->getManipulator('user', 'pass', 'email', true, false)); $exitCode = $commandTester->execute(array( 'username' => 'user', 'email' => 'email', @@ -58,7 +58,7 @@ public function testExecuteInteractiveWithQuestionHelper() $application->getHelperSet()->set($helper, 'question'); $commandTester = $this->createCommandTester( - $this->getContainer('user', 'pass', 'email', true, false), $application + $this->getManipulator('user', 'pass', 'email', true, false), $application ); $exitCode = $commandTester->execute(array(), array( 'decorated' => false, @@ -70,12 +70,12 @@ public function testExecuteInteractiveWithQuestionHelper() } /** - * @param ContainerInterface $container - * @param Application|null $application + * @param UserManipulator $manipulator + * @param Application|null $application * * @return CommandTester */ - private function createCommandTester(ContainerInterface $container, Application $application = null) + private function createCommandTester(UserManipulator $manipulator, Application $application = null) { if (null === $application) { $application = new Application(); @@ -83,8 +83,7 @@ private function createCommandTester(ContainerInterface $container, Application $application->setAutoExit(false); - $command = new CreateUserCommand(); - $command->setContainer($container); + $command = new CreateUserCommand($manipulator); $application->add($command); @@ -100,10 +99,8 @@ private function createCommandTester(ContainerInterface $container, Application * * @return mixed */ - private function getContainer($username, $password, $email, $active, $superadmin) + private function getManipulator($username, $password, $email, $active, $superadmin) { - $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); - $manipulator = $this->getMockBuilder('FOS\UserBundle\Util\UserManipulator') ->disableOriginalConstructor() ->getMock(); @@ -114,12 +111,6 @@ private function getContainer($username, $password, $email, $active, $superadmin ->with($username, $password, $email, $active, $superadmin) ; - $container - ->expects($this->once()) - ->method('get') - ->with('fos_user.util.user_manipulator') - ->will($this->returnValue($manipulator)); - - return $container; + return $manipulator; } } diff --git a/Tests/Command/DeactivateUserCommandTest.php b/Tests/Command/DeactivateUserCommandTest.php index 9da64430ab..24d4645924 100644 --- a/Tests/Command/DeactivateUserCommandTest.php +++ b/Tests/Command/DeactivateUserCommandTest.php @@ -12,16 +12,16 @@ namespace FOS\UserBundle\Tests\Command; use FOS\UserBundle\Command\DeactivateUserCommand; +use FOS\UserBundle\Util\UserManipulator; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\DependencyInjection\ContainerInterface; class DeactivateUserCommandTest extends TestCase { public function testExecute() { - $commandTester = $this->createCommandTester($this->getContainer('user')); + $commandTester = $this->createCommandTester($this->getManipulator('user')); $exitCode = $commandTester->execute(array( 'username' => 'user', ), array( @@ -47,7 +47,7 @@ public function testExecuteInteractiveWithQuestionHelper() $application->getHelperSet()->set($helper, 'question'); - $commandTester = $this->createCommandTester($this->getContainer('user'), $application); + $commandTester = $this->createCommandTester($this->getManipulator('user'), $application); $exitCode = $commandTester->execute(array(), array( 'decorated' => false, 'interactive' => true, @@ -58,12 +58,12 @@ public function testExecuteInteractiveWithQuestionHelper() } /** - * @param ContainerInterface $container - * @param Application|null $application + * @param UserManipulator $manipulator + * @param Application|null $application * * @return CommandTester */ - private function createCommandTester(ContainerInterface $container, Application $application = null) + private function createCommandTester(UserManipulator $manipulator, Application $application = null) { if (null === $application) { $application = new Application(); @@ -71,8 +71,7 @@ private function createCommandTester(ContainerInterface $container, Application $application->setAutoExit(false); - $command = new DeactivateUserCommand(); - $command->setContainer($container); + $command = new DeactivateUserCommand($manipulator); $application->add($command); @@ -84,10 +83,8 @@ private function createCommandTester(ContainerInterface $container, Application * * @return mixed */ - private function getContainer($username) + private function getManipulator($username) { - $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); - $manipulator = $this->getMockBuilder('FOS\UserBundle\Util\UserManipulator') ->disableOriginalConstructor() ->getMock(); @@ -98,12 +95,6 @@ private function getContainer($username) ->with($username) ; - $container - ->expects($this->once()) - ->method('get') - ->with('fos_user.util.user_manipulator') - ->will($this->returnValue($manipulator)); - - return $container; + return $manipulator; } } diff --git a/Tests/Command/DemoteUserCommandTest.php b/Tests/Command/DemoteUserCommandTest.php index 8df744a1fb..330e50142a 100644 --- a/Tests/Command/DemoteUserCommandTest.php +++ b/Tests/Command/DemoteUserCommandTest.php @@ -12,16 +12,16 @@ namespace FOS\UserBundle\Tests\Command; use FOS\UserBundle\Command\DemoteUserCommand; +use FOS\UserBundle\Util\UserManipulator; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\DependencyInjection\ContainerInterface; class DemoteUserCommandTest extends TestCase { public function testExecute() { - $commandTester = $this->createCommandTester($this->getContainer('user', 'role', false)); + $commandTester = $this->createCommandTester($this->getManipulator('user', 'role', false)); $exitCode = $commandTester->execute(array( 'username' => 'user', 'role' => 'role', @@ -51,7 +51,7 @@ public function testExecuteInteractiveWithQuestionHelper() $application->getHelperSet()->set($helper, 'question'); - $commandTester = $this->createCommandTester($this->getContainer('user', 'role', false), $application); + $commandTester = $this->createCommandTester($this->getManipulator('user', 'role', false), $application); $exitCode = $commandTester->execute(array(), array( 'decorated' => false, 'interactive' => true, @@ -62,12 +62,12 @@ public function testExecuteInteractiveWithQuestionHelper() } /** - * @param ContainerInterface $container - * @param Application|null $application + * @param UserManipulator $manipulator + * @param Application|null $application * * @return CommandTester */ - private function createCommandTester(ContainerInterface $container, Application $application = null) + private function createCommandTester(UserManipulator $manipulator, Application $application = null) { if (null === $application) { $application = new Application(); @@ -75,8 +75,7 @@ private function createCommandTester(ContainerInterface $container, Application $application->setAutoExit(false); - $command = new DemoteUserCommand(); - $command->setContainer($container); + $command = new DemoteUserCommand($manipulator); $application->add($command); @@ -90,10 +89,8 @@ private function createCommandTester(ContainerInterface $container, Application * * @return mixed */ - private function getContainer($username, $role, $super) + private function getManipulator($username, $role, $super) { - $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); - $manipulator = $this->getMockBuilder('FOS\UserBundle\Util\UserManipulator') ->disableOriginalConstructor() ->getMock(); @@ -114,12 +111,6 @@ private function getContainer($username, $role, $super) ; } - $container - ->expects($this->once()) - ->method('get') - ->with('fos_user.util.user_manipulator') - ->will($this->returnValue($manipulator)); - - return $container; + return $manipulator; } } diff --git a/Tests/Command/PromoteUserCommandTest.php b/Tests/Command/PromoteUserCommandTest.php index 150e3a097d..01cc43c6d0 100644 --- a/Tests/Command/PromoteUserCommandTest.php +++ b/Tests/Command/PromoteUserCommandTest.php @@ -12,16 +12,16 @@ namespace FOS\UserBundle\Tests\Command; use FOS\UserBundle\Command\PromoteUserCommand; +use FOS\UserBundle\Util\UserManipulator; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\DependencyInjection\ContainerInterface; class PromoteUserCommandTest extends TestCase { public function testExecute() { - $commandTester = $this->createCommandTester($this->getContainer('user', 'role', false)); + $commandTester = $this->createCommandTester($this->getManipulator('user', 'role', false)); $exitCode = $commandTester->execute(array( 'username' => 'user', 'role' => 'role', @@ -51,7 +51,7 @@ public function testExecuteInteractiveWithQuestionHelper() $application->getHelperSet()->set($helper, 'question'); - $commandTester = $this->createCommandTester($this->getContainer('user', 'role', false), $application); + $commandTester = $this->createCommandTester($this->getManipulator('user', 'role', false), $application); $exitCode = $commandTester->execute(array(), array( 'decorated' => false, 'interactive' => true, @@ -62,12 +62,12 @@ public function testExecuteInteractiveWithQuestionHelper() } /** - * @param ContainerInterface $container - * @param Application|null $application + * @param UserManipulator $manipulator + * @param Application|null $application * * @return CommandTester */ - private function createCommandTester(ContainerInterface $container, Application $application = null) + private function createCommandTester(UserManipulator $manipulator, Application $application = null) { if (null === $application) { $application = new Application(); @@ -75,8 +75,7 @@ private function createCommandTester(ContainerInterface $container, Application $application->setAutoExit(false); - $command = new PromoteUserCommand(); - $command->setContainer($container); + $command = new PromoteUserCommand($manipulator); $application->add($command); @@ -90,10 +89,8 @@ private function createCommandTester(ContainerInterface $container, Application * * @return mixed */ - private function getContainer($username, $role, $super) + private function getManipulator($username, $role, $super) { - $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); - $manipulator = $this->getMockBuilder('FOS\UserBundle\Util\UserManipulator') ->disableOriginalConstructor() ->getMock(); @@ -114,12 +111,6 @@ private function getContainer($username, $role, $super) ; } - $container - ->expects($this->once()) - ->method('get') - ->with('fos_user.util.user_manipulator') - ->will($this->returnValue($manipulator)); - - return $container; + return $manipulator; } } diff --git a/Tests/EventListener/FlashListenerTest.php b/Tests/EventListener/FlashListenerTest.php index 582b834aec..e78676c5ba 100644 --- a/Tests/EventListener/FlashListenerTest.php +++ b/Tests/EventListener/FlashListenerTest.php @@ -30,7 +30,7 @@ public function setUp() $flashBag = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Flash\FlashBag')->getMock(); - $session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')->getMock(); + $session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')->disableOriginalConstructor()->getMock(); $session ->expects($this->once()) ->method('getFlashBag') diff --git a/composer.json b/composer.json index f89f31e4df..161eb0bcd5 100644 --- a/composer.json +++ b/composer.json @@ -20,22 +20,22 @@ ], "require": { "php": "^5.5.9 || ^7.0", - "symfony/form": "^2.8 || ^3.0", - "symfony/framework-bundle": "^2.8 || ^3.0", - "symfony/security-bundle": "^2.8 || ^3.0", - "symfony/twig-bundle": "^2.8 || ^3.0", + "symfony/form": "^2.8 || ^3.0 || ^4.0", + "symfony/framework-bundle": "^2.8 || ^3.0 || ^4.0", + "symfony/security-bundle": "^2.8 || ^3.0 || ^4.0", + "symfony/twig-bundle": "^2.8 || ^3.0 || ^4.0", + "symfony/validator": "^2.8 || ^3.0 || ^4.0", "twig/twig": "^1.28 || ^2.0", - "symfony/templating": "^2.8 || ^3.0", + "symfony/templating": "^2.8 || ^3.0 || ^4.0", "paragonie/random_compat": "^1 || ^2" }, "require-dev": { "doctrine/doctrine-bundle": "^1.3", "friendsofphp/php-cs-fixer": "^1.11", "swiftmailer/swiftmailer": "^4.3 || ^5.0 || ^6.0", - "symfony/console": "^2.8 || ^3.0", - "symfony/phpunit-bridge": "^2.8 || ^3.0", - "symfony/validator": "^2.8 || ^3.0", - "symfony/yaml": "^2.8 || ^3.0", + "symfony/console": "^2.8 || ^3.0 || ^4.0", + "symfony/phpunit-bridge": "^2.8 || ^3.0 || ^4.0", + "symfony/yaml": "^2.8 || ^3.0 || ^4.0", "phpunit/phpunit": "^4.8.35|^5.4.3" }, "conflict": {