function it_can_edit_user_profile(UserRepository $userRepository, EventDispatcherInterface $eventDispatcher, User $user, EditProfileAction $action)
 {
     $action->getUser()->willReturn($user);
     $action->getDisplayName()->willReturn('John Doe');
     $action->getPreferredLocale()->willReturn('fr_FR');
     $action->getEmail()->willReturn('*****@*****.**');
     $user->setName(Argument::exact(new Name('John Doe')))->willReturn($user)->shouldBeCalled();
     $user->setEmail(Argument::exact(new Email('*****@*****.**')))->willReturn($user)->shouldBeCalled();
     $user->setPreferredLocale(Argument::exact(Locale::parse('fr_Fr')))->willReturn($user)->shouldBeCalled();
     $userRepository->save($user)->shouldBeCalled();
     $this->execute($action);
 }
Пример #2
0
 /**
  * @param object     $value
  * @param Constraint $constraint
  *
  * @throws UnexpectedTypeException
  * @throws ConstraintDefinitionException
  */
 public function validate($value, Constraint $constraint)
 {
     if (null === $value || '' === $value) {
         return;
     }
     if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
         throw new UnexpectedTypeException($value, 'string');
     }
     $value = (string) $value;
     if (empty($value)) {
         return;
     }
     $value = (string) $value;
     $user = $this->userRepository->findOneByUsername(new Username($value));
     if (null !== $user) {
         $this->context->buildViolation($constraint->message)->addViolation();
     }
 }
 function it_execute_action(UserRepository $userRepository, CredentialsRepository $credentialsRepository, EncoderFactoryInterface $encoderFactory, EventDispatcherInterface $eventDispatcher, PasswordEncoderInterface $passwordEncoder, User $user, Credentials $credentials, RegisterUserAction $action)
 {
     // Mocks
     $action->getUsername()->willReturn('mattketmo');
     $action->getDisplayName()->willReturn('Matthieu Moquet');
     $action->getEmail()->willReturn('*****@*****.**');
     $action->getPassword()->willReturn('super_passw0rd');
     $action->getPreferredLocale()->willReturn('fr_FR');
     $encoderFactory->getEncoder($user)->willReturn($passwordEncoder);
     $passwordEncoder->encodePassword('super_passw0rd', Argument::type('string'))->willReturn('encoded_password==');
     $userRepository->createNew(Argument::exact(new Username('mattketmo')))->willReturn($user);
     $credentialsRepository->createNew($user, 'encoded_password==', Argument::type('string'))->shouldBeCalled()->willReturn($credentials);
     $user->setName(Argument::exact(new Name('Matthieu Moquet')))->shouldBeCalled()->willReturn($user);
     $user->setEmail(Argument::exact(new Email('*****@*****.**')))->shouldBeCalled()->willReturn($user);
     $user->setPreferredLocale(Argument::exact(Locale::parse('fr_FR')))->shouldBeCalled()->willReturn($user);
     $userRepository->save($user)->shouldBeCalled();
     $credentialsRepository->save($credentials)->shouldBeCalled();
     $this->execute($action)->shouldReturn($user);
 }
 function it_should_remote_user(UserRepository $userRepository, EventDispatcherInterface $eventDispatcher, User $user, DeleteAccountAction $action)
 {
     $action->getUser()->willReturn($user);
     $userRepository->remove($user)->shouldBeCalled();
     $this->execute($action);
 }