/** * 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->providerUserBook = new ProviderUserBook($this->connection); foreach ($this->providerInfoBook->get() as $providerInfo) { $this->providerInfoBook->delete($providerInfo); } foreach ($this->userBook->get() as $user) { $this->userBook->delete($user); } 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()); $user->setId($this->userBook->save($user)); $this->userList[] = $user; for ($k = 0; $k < 10; $k++) { $providerInfo = new ProviderInfo(); $providerInfo->setName(RandomBook::getRandomString())->setAppKey(RandomBook::getRandomString())->setSecretKey(RandomBook::getRandomString()); $providerInfo->setId((int) $this->providerInfoBook->save($providerInfo)); $this->providerInfoList[] = $providerInfo; $providerUser = new ProviderUser(); $providerUser->setUserId($user->getId())->setProviderId($providerInfo->getId())->setProviderName($providerInfo->getName())->setProviderUserId(RandomBook::getRandomString()); $this->providerUserList[] = $providerUser; } } }
/** * @throws \mtoolkit\entity\model\user\exception\InsertUserException * @depends testDelete */ public function testSaveAndGet() { for ($i = 0; $i < count($this->userList); $i++) { /* @var $user User */ $user = $this->userList[$i]; $user->setId($this->userBook->save($this->userList[$i])); $this->userList[$i] = $user; } $userInDB = $this->userBook->get(); $this->assertEquals(count($this->userList), count($userInDB)); for ($i = 0; $i < count($this->userList); $i++) { $currentUser = $this->userList[$i]; $usersInDb = $this->userBook->get($currentUser->getId()); $userInDb = $usersInDb[0]; $this->assertEquals($currentUser, $userInDb); } }