Beispiel #1
0
 protected function setUp()
 {
     parent::setUp();
     $this->userRepository = new SimpleUserRepository();
     $this->sessionRepository = new SimpleUserSessionRepository();
     $this->credentialChecker = new BasicCredentialChecker($this->userRepository);
     $this->sessionManager = new BasicUserSessionManager($this->sessionRepository);
     $this->userSessionFactory = new BasicUserSessionFactory();
     $this->service = new UserServiceDefault($this->credentialChecker, $this->userSessionFactory, $this->sessionManager);
     $this->defaultName = 'Pippo';
     $this->defaultUsername = '******';
     $this->defaultPassword = '******';
     $this->defaultUser = new BasicUser($this->defaultName, $this->defaultUsername, $this->defaultPassword);
     $this->userRepository->save($this->defaultUser);
 }
 private function _check(BasicCredential $credential)
 {
     $user = $this->userRepository->getUserByUsername($credential->getUsername());
     if (!$user) {
         throw new UserNotFoundException();
     }
     if (!$user instanceof BasicUser) {
         throw new IncompatibleModelException(BasicUser::class, $user);
     }
     /** @var BasicUser $user */
     if ($user->getPassword() !== $credential->getPassword()) {
         throw new WrongPasswordException();
     }
     return $user;
 }