本文整理匯總了PHP中Tymon\JWTAuth\Facades\JWTAuth::shouldReceive方法的典型用法代碼示例。如果您正苦於以下問題:PHP JWTAuth::shouldReceive方法的具體用法?PHP JWTAuth::shouldReceive怎麽用?PHP JWTAuth::shouldReceive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Tymon\JWTAuth\Facades\JWTAuth
的用法示例。
在下文中一共展示了JWTAuth::shouldReceive方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testLoginFailure
public function testLoginFailure()
{
// not send credentials
$res = $this->call('POST', '/auth/login');
$this->assertEquals(401, $res->getStatusCode());
$results = json_decode($res->getContent());
$this->assertEquals('error', $results->status);
$this->assertEquals('authenticate', $results->type);
$this->assertEquals('Invalid Credentials.', $results->message);
// user not found
$res = $this->call('POST', '/auth/login', ['email' => 'nouser@example.com', 'password' => '123456']);
$this->assertEquals(401, $res->getStatusCode());
$results = json_decode($res->getContent());
$this->assertEquals('error', $results->status);
$this->assertEquals('authenticate', $results->type);
$this->assertEquals('Invalid Credentials.', $results->message);
// wrong password
$res = $this->call('POST', '/auth/login', ['email' => 'admin@example.com', 'password' => 'abcdef']);
$this->assertEquals(401, $res->getStatusCode());
$results = json_decode($res->getContent());
$this->assertEquals('error', $results->status);
$this->assertEquals('authenticate', $results->type);
$this->assertEquals('Invalid Credentials.', $results->message);
// can't create token
JWTAuth::shouldReceive('attempt')->once()->andThrow(new Tymon\JWTAuth\Exceptions\JWTException('Could not create token.', 500));
$res = $this->call('POST', '/auth/login');
$results = json_decode($res->getContent());
$this->assertEquals(500, $res->getStatusCode());
$this->assertEquals('Could not create token.', $results->message);
}
示例2: testUserNotFound
public function testUserNotFound()
{
// Check user not found
$request = Mockery::mock();
JWTAuth::shouldReceive('setRequest')->once()->andReturn($request);
$request->shouldReceive('getToken')->once()->andReturn(true);
JWTAuth::shouldReceive('authenticate')->once()->andReturn(false);
$res = $this->call('POST', '/auth/logout');
$result = json_decode($res->getContent());
$this->assertEquals(404, $res->getStatusCode());
$this->assertEquals('User not found.', $result->message);
$this->assertEquals('error', $result->status);
$this->assertEquals('authenticate', $result->type);
}
示例3: testRouteRequirePermissionGuestAccess
public function testRouteRequirePermissionGuestAccess()
{
RoutePermission::setRoutePermissions('POST /blog/{id}', ['create-blog']);
$res = $this->call('POST', '/blog/1');
$this->assertEquals(401, $res->getStatusCode());
$request = Mockery::mock();
$request->shouldReceive('getToken')->once()->andReturn('mocktoken');
JWTAuth::shouldReceive('setRequest')->once()->andReturn($request);
JWTAuth::shouldReceive('authenticate')->once()->andThrow(new Tymon\JWTAuth\Exceptions\JWTException('Not authenticate.', 401));
$res = $this->call('POST', '/blog/1', [], [], [], ['HTTP_Authorization' => "Bearer fake_token"]);
$this->assertEquals(401, $res->getStatusCode());
$request = Mockery::mock();
$request->shouldReceive('getToken')->once()->andReturn('mocktoken');
JWTAuth::shouldReceive('setRequest')->once()->andReturn($request);
JWTAuth::shouldReceive('authenticate')->once()->andReturn(null);
$res = $this->call('POST', '/blog/1', [], [], [], ['HTTP_Authorization' => "Bearer fake_token"]);
$this->assertEquals(401, $res->getStatusCode());
}