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