You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB

2 years ago
  1. <?php
  2. namespace Tests\Base;
  3. use App\Documents\FingerPrintDocument;
  4. use App\Documents\UserDocument;
  5. use Jenssegers\Mongodb\Eloquent\Model;
  6. trait AuthMethodsTrait
  7. {
  8. protected function getToken($user = null)
  9. {
  10. $user = empty($user) ? UserDocument::factory()->create() : $user;
  11. $fingerPrint = FingerPrintDocument::factory()->create(['user_id' => $user->id]);
  12. return $fingerPrint->token;
  13. }
  14. protected function loginAsAdmin($user = ['id' => 1, 'group_id' => 1, 'name' => 'admin', 'email' => 'admin@gmail.com'])
  15. {
  16. return $this->loginAs(['*'], $user);
  17. }
  18. protected function loginAsUser($permissions = [], $user = ['id' => 1, 'group_id' => 1, 'name' => 'user', 'email' => 'user@gmail.com'])
  19. {
  20. return $this->loginAs($permissions, $user);
  21. }
  22. protected function loginAs($permissions = [], $user = ['id' => 1, 'group_id' => 1, 'name' => 'fake', 'email' => 'fake@gmail.com'])
  23. {
  24. $user = $user instanceof Model ? $user : new UserDocument($user);
  25. $user->permissions = $permissions;
  26. $this->be($user);
  27. return $this;
  28. }
  29. }