public function testPublishEmail()
 {
     DomainEvents::setEventDispatcher(new EventDispatcher());
     $user = User::fromDTO(new CreateUserDTO('Ma27', 'test-password', '*****@*****.**'), (new UserActivation())->buildKeyCode(new ActivationKeyCodeGenerator()));
     $publisher = $this->getMock(BackendInterface::class);
     $publisher->expects($this->once())->method('createAndPublish')->with('sen_mailer', ['user' => $user, 'config_path' => 'SententiaregumApp:registration', 'parameters' => ['code' => $user->getActivation()->getKeyCode(), 'name' => 'Ma27'], 'override_locale' => true]);
     $event = new CreateUserEvent($user);
     $event->setActivationKey($user->getActivation()->getKeyCode());
     $listener = new PostRegistrationListener($publisher);
     $listener->postUserRegistration($event);
 }
Exemplo n.º 2
0
 /**
  * Creates a user by a data transfer object
  *
  * @param CreateUserDTO $userData
  * @param UserActivation $activation
  *
  * @return User
  */
 public static function fromDTO(CreateUserDTO $userData, UserActivation $activation = null)
 {
     $credentials = new Credentials($userData->getUsername(), $userData->getPassword());
     $profile = new UserDetails($userData->getEmail(), new \DateTime(), new \DateTime(), $userData->getLocale(), $userData->getRealName());
     $user = new self($credentials, $profile, [], $userData->getRoles(), $activation);
     $event = new CreateUserEvent($user);
     if (null !== $activation) {
         $event->setActivationKey($activation->getKeyCode());
     }
     DomainEvents::raise($event);
     return $user;
 }