コード例 #1
0
 public function execute(RegisterUserAction $action)
 {
     $username = new Username($action->getUsername());
     $password = $action->getPassword();
     $email = new Email($action->getEmail());
     $displayName = new Name($action->getDisplayName());
     $preferredLocale = Locale::parse($action->getPreferredLocale());
     $user = $this->userRepository->createNew($username);
     $user->setName($displayName)->setEmail($email)->setPreferredLocale($preferredLocale);
     $encoder = $this->encoderFactory->getEncoder($user);
     $salt = md5(uniqid(null, true));
     $password = $encoder->encodePassword($password, $salt);
     $credentials = $this->credentialsRepository->createNew($user, $password, $salt);
     $this->userRepository->save($user);
     $this->credentialsRepository->save($credentials);
     return $user;
 }
コード例 #2
0
 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);
 }