コード例 #1
0
 /**
  * @throws \mtoolkit\entity\model\role\exception\InsertRoleException
  * @depends testDelete
  */
 public function testSaveAndGet()
 {
     for ($i = 0; $i < count($this->roleList); $i++) {
         /* @var $role Role */
         $role = $this->roleList[$i];
         $role->setId($this->roleBook->save($this->roleList[$i]));
         $this->roleList[$i] = $role;
     }
     $rolesInDB = $this->roleBook->get();
     $this->assertEquals(count($this->roleList), count($rolesInDB));
     for ($i = 0; $i < count($this->roleList); $i++) {
         $currentRole = $this->roleList[$i];
         $rolesInDb = $this->roleBook->get($currentRole->getId());
         $roleInDB = $rolesInDb[0];
         $this->assertEquals($currentRole, $roleInDB);
     }
 }
コード例 #2
0
 /**
  * Sets up the fixture, for example, open a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     parent::setUp();
     $this->connection = Connection::get();
     $this->userBook = new UserBook($this->connection);
     $this->providerInfoBook = new ProviderInfoBook($this->connection);
     $this->roleBook = new RoleBook($this->connection);
     foreach ($this->providerInfoBook->get() as $providerInfo) {
         $this->providerInfoBook->delete($providerInfo);
     }
     foreach ($this->roleBook->get() as $role) {
         $this->roleBook->delete($role);
     }
     for ($k = 0; $k < 10; $k++) {
         $user = new User();
         $user->setEnabled(RandomBook::getRandomBoolean())->setEnabledDate(RandomBook::getRandomDate())->setAccessFailedCount(rand(1, 5))->setEmail(RandomBook::getRandomEmail())->setPassword(RandomBook::getRandomString())->setPhoneNumber(RandomBook::getRandomPhoneNumber())->setTwoFactorEnabled(RandomBook::getRandomBoolean())->setUserName(RandomBook::getRandomString());
         $this->userList[] = $user;
     }
 }
コード例 #3
0
ファイル: UserBook.php プロジェクト: mtoolkit/mtoolkit-entity
 /**
  * @param int|null $userId
  * @param string|null $username
  * @param string|null $email
  * @return User[]
  * @throws \Exception
  */
 public function get($userId = null, $username = null, $email = null)
 {
     MDataType::mustBeNullableInt($userId);
     MDataType::mustBeNullableString($username);
     MDataType::mustBeNullableString($email);
     $userList = array();
     $sql = "CALL mt_user_get(?, ?, ?);";
     $query = new MPDOQuery($sql, $this->connection);
     $query->bindValue($userId);
     $query->bindValue($username);
     $query->bindValue($email);
     $queryResult = $query->exec();
     if ($queryResult == false || $query->getResult()->rowCount() <= 0) {
         return $userList;
     }
     foreach ($query->getResult() as $row) {
         $user = new User();
         $enabledDate = \DateTime::createFromFormat('Y-m-d H:i:s', $row['enabled_date']);
         $user->setId((int) $row['id'])->setEmail($row['email'])->setPassword($row['password'])->setPhoneNumber($row['phone_number'])->setTwoFactorEnabled($row['two_factor_enabled'] == 1 ? true : false)->setEnabledDate($enabledDate)->setEnabled($row['enabled'] == 1 ? true : false)->setAccessFailedCount((int) $row['access_failed_count'])->setUserName($row['username'])->setRoleList($this->roleBook->get((int) $row['id']))->setProviderUserList($this->providerUserBook->get((int) $row['id']));
         $userList[] = $user;
     }
     return $userList;
 }