本文整理汇总了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);
}
}