當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。