Guest User

Untitled

a guest
Sep 26th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. public function testHash(){
  2. $hash = Mockery::mock('HashLogin');
  3. $hash->shouldReceive('checkHash')->once();
  4.  
  5. $this->app->instance('HashLogin', $hash);
  6.  
  7. $this->call('GET', 'login/hash/c3e144adfe8133343b37d0d95f987d87b2d87a24');
  8. }
  9.  
  10. public function __construct(User $user, HashLogin $hashlogin){
  11. $this->user = $user;
  12. $this->hashlogin = $hashlogin;
  13. $this->ip_direct = array_key_exists("REMOTE_ADDR",$_SERVER) ? $_SERVER["REMOTE_ADDR"] : null;
  14. $this->ip_elb = array_key_exists("HTTP_X_FORWARDED_FOR",$_SERVER) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : null;
  15.  
  16. $this->beforeFilter(function()
  17. {
  18. if(Auth::check()){return Redirect::to('/');}
  19. });
  20. }
  21.  
  22. public function getHash($code){
  23. $hash = $this->hashlogin->checkHash($code);
  24. if(!$hash){
  25. return $this->badLogin('Invalid Login');
  26. }
  27. $user = $this->user->getFromLegacy($hash->getLegacyUser());
  28. $hash->cleanup();
  29. $this->login($user);
  30. return Redirect::intended('/');
  31. }
  32.  
  33. public function testLoginSuccessfulWithAuthTrue(){
  34. Input::shouldReceive('get')->with('username')->once()->andReturn('user');
  35. Input::shouldReceive('get')->with('password')->once()->andReturn('1234');
  36. Auth::shouldReceive('attempt')->once()->andReturn(true);
  37. $user = Mockery::mock('User');
  38. $user->shouldReceive('buildRBAC')->once();
  39. Auth::shouldReceive('user')->once()->andReturn($user);
  40.  
  41. $this->call('POST', 'login');
  42.  
  43. $this->assertRedirectedToRoute('index');
  44. }
  45.  
  46. public function postIndex(){
  47. $username = Input::get("username");
  48. $pass = Input::get('password');
  49. if(Auth::attempt(array('username' => $username, 'password' => $pass))){
  50. Auth::user()->buildRBAC();
  51. }else{
  52. $user = $this->user->checkForLegacyUser($username);
  53. if($user){
  54. $this->login($user);
  55. }else{
  56. return Redirect::back()->withInput()->with('error', "Invalid credentials.");
  57. }
  58. }
  59. return Redirect::intended('/');
  60. }
  61.  
  62. MockeryExceptionInvalidCountException: Method get("username") from Mockery_5_Illuminate_Http_Request should be called exactly 1 times but called 0 times."
  63.  
  64. $hash = Mockery::mock('AppModelsEloquentHashLogin');
  65. $this->app->instance('AppModelsEloquentHashLogin', $hash);
Add Comment
Please, Sign In to add comment