public function onChangePassword(ChangePasswordEvent $event)
 {
     $user = $event->getUser();
     $objectManager = $this->registry->getManagerForClass(get_class($user));
     if (isset($objectManager)) {
         $encoder = $this->encoderFactory->getEncoder($user);
         $password = $encoder->encodePassword($event->getPlainPassword(), $user->getSalt());
         $accessor = new PropertyAccessor();
         $accessor->setValue($user, 'password', $password);
         $objectManager->persist($user);
         $objectManager->flush();
     }
 }
 /**
  * @param \FSi\Bundle\AdminSecurityBundle\Event\ChangePasswordEvent $event
  * @param \Doctrine\Bundle\DoctrineBundle\Registry $registry
  * @param \FSi\Bundle\AdminSecurityBundle\spec\fixtures\User $user
  * @param \Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface $encodeFactory
  * @param \Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface $encoder
  */
 function it_set_password_when_user_is_doctrine_entity($event, $registry, $user, $encodeFactory, $encoder)
 {
     $prophet = new Prophet();
     $em = $prophet->prophesize('Doctrine\\ORM\\EntityManager');
     $registry->getManagerForClass(Argument::type('string'))->willReturn($em);
     $event->getUser()->shouldBeCalled()->willReturn($user);
     $event->getPlainPassword()->shouldBeCalled()->willReturn('plain_password');
     $user->getSalt()->shouldBeCalled()->willReturn('salt');
     $encodeFactory->getEncoder($user)->shouldBeCalled()->willReturn($encoder);
     $encoder->encodePassword('plain_password', 'salt')->shouldBeCalled()->willReturn('encoded_password');
     $user->setPassword('encoded_password')->shouldBeCalled();
     $em->persist($user->getWrappedObject())->shouldBeCalled();
     $em->flush()->shouldBeCalled();
     $this->onChangePassword($event);
 }