当前位置: 首页>>代码示例>>PHP>>正文


PHP JWTAuth::shouldReceive方法代码示例

本文整理汇总了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);
 }
开发者ID:wyrover,项目名称:laravel-users,代码行数:30,代码来源:AuthControllerTest.php

示例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);
 }
开发者ID:wyrover,项目名称:laravel-users,代码行数:14,代码来源:AuthenticateTest.php

示例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());
 }
开发者ID:wyrover,项目名称:laravel-users,代码行数:18,代码来源:RoutePermissionTest.php


注:本文中的Tymon\JWTAuth\Facades\JWTAuth::shouldReceive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。