本文整理匯總了PHP中app\models\User::findFirstById方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::findFirstById方法的具體用法?PHP User::findFirstById怎麽用?PHP User::findFirstById使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\models\User
的用法示例。
在下文中一共展示了User::findFirstById方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: runAction
/**
* @return Response
* @throws UserException
*/
public function runAction()
{
/** @var User $user */
$user = User::findFirstById($this->getId());
if ($user) {
return $this->response($user);
} else {
throw new UserException('User not found', 404);
}
}
示例2: runAction
/**
* @return Response
* @throws UserException
*/
public function runAction()
{
$user = User::findFirstById($this->getId());
if ($user) {
$user->delete();
return $this->response($user);
} else {
throw new UserException('User not found', 404);
}
}
示例3: testMain
public function testMain()
{
/** @var User $userToDelete */
$userToDelete = $this->getStub()->offsetGet(0);
$response = $this->delete('/user/' . $userToDelete->getId());
$responsePayload = $response->json();
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($responsePayload['success']);
$this->assertNull($responsePayload['meta']);
$this->assertEquals($responsePayload['data']['id'], $userToDelete->getId());
$this->assertEquals($responsePayload['data']['name'], $userToDelete->getName());
$this->assertEquals($responsePayload['data']['email'], $userToDelete->getEmail());
/** @var User|boolean $deletedUser */
$deletedUser = User::findFirstById($userToDelete->getId());
$this->assertFalse($deletedUser);
}
示例4: testMain
public function testMain()
{
$userFixture = (new UserFixture())->getArray('Create Test');
$response = $this->post('/user', $userFixture);
$responsePayload = $response->json();
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($responsePayload['success']);
$this->assertNull($responsePayload['meta']);
$this->assertEquals($responsePayload['data']['name'], $userFixture['name']);
$this->assertEquals($responsePayload['data']['email'], $userFixture['email']);
/** @var boolean|User $createdUser */
$createdUser = User::findFirstById($responsePayload['data']['id']);
$this->assertNotFalse($createdUser);
$this->assertEquals($userFixture['name'], $createdUser->getName());
$this->assertEquals($userFixture['email'], $createdUser->getEmail());
$isValidPassword = (new Security())->checkHash($userFixture['password'], $createdUser->getPassword());
$this->assertTrue($isValidPassword);
}
示例5: testPasswordNotChange
public function testPasswordNotChange()
{
/** @var User $userToUpdate */
$userToUpdate = $this->getStub()->offsetGet(0);
$userFixture = (new UserFixture())->getArray('Update Test');
unset($userFixture['password']);
$response = $this->put('/user/' . $userToUpdate->getId(), $userFixture);
$responsePayload = $response->json();
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($responsePayload['success']);
$this->assertNull($responsePayload['meta']);
$this->assertEquals($responsePayload['data']['name'], $userFixture['name']);
$this->assertEquals($responsePayload['data']['email'], $userFixture['email']);
/** @var User|boolean $userAfterUpdate */
$userAfterUpdate = User::findFirstById($responsePayload['data']['id']);
$this->assertNotFalse($userAfterUpdate);
$this->assertEquals($userFixture['name'], $userAfterUpdate->getName());
$this->assertEquals($userFixture['email'], $userAfterUpdate->getEmail());
$this->assertEquals($userToUpdate->getPassword(), $userAfterUpdate->getPassword());
}
示例6: runAction
/**
* @return Response
* @throws UserException
*/
public function runAction()
{
$user = User::findFirstById($this->getId());
if ($user) {
$name = $this->getPayload()->getName();
if (!is_null($name)) {
$user->setName($name);
}
$email = $this->getPayload()->getEmail();
if (!is_null($email)) {
$user->setEmail($email);
}
$password = $this->getPayload()->getPassword();
if (!is_null($password)) {
$user->setPassword($password);
}
$user->save();
return $this->response($user);
} else {
throw new UserException('User not found', 404);
}
}