Exemple #1
0
 private function doRegister()
 {
     try {
         $userRepository = new UserRepository($this->storage);
         $user = UserFactory::create(new UniqueId(), $this->request->get('name'), $this->request->get('email'), $this->request->get('password'), new UserGroups($this->storage));
         $userRepository->insert($user);
     } catch (DataNotValid $e) {
         return $this->returnErrorMessages(['field' => $e->getFieldName(), 'message' => $e->getMessage()]);
     }
     return $this->app->redirect('/groups/index');
 }
Exemple #2
0
 public function getByEmail($email) : UserEntity
 {
     $result = $this->storage->query(function ($pdo, $operations) use($email) {
         $dbClass = $operations . '\\FetchData';
         $columns = ['id', 'name', 'email', 'password'];
         return $dbClass::getByField($pdo, $columns, 'user', 'email', $email);
     });
     if (!$result) {
         throw new RecordNotExists();
     }
     $id = new UniqueId($result['id']);
     $userGroups = new UserGroups($this->storage);
     return UserFactory::create($id, $result['name'], $result['email'], $result['password'], $userGroups);
 }
Exemple #3
0
 /**
  * @test
  */
 public function factoryShouldPrepareCorrectEntity()
 {
     $mockUniqueId = $this->getMock('Fiche\\Domain\\Policy\\UniqueIdInterface');
     $mockUserGroupsRepository = $this->getMock('Fiche\\Domain\\Repository\\UserGroupsRepository');
     $id = new $mockUniqueId();
     $userGroupsRepository = new $mockUserGroupsRepository();
     $name = 'User';
     $email = '*****@*****.**';
     $password = '******';
     $user = UserFactory::create($id, $name, $email, $password, $userGroupsRepository);
     $this->assertInstanceOf(User::class, $user);
     $this->assertEquals($name, $user->getName());
     $this->assertEquals($password, $user->getPassword());
     $this->assertEquals($email, $user->getEmail());
 }