Created
November 19, 2018 18:34
-
-
Save roni-estein/8e14c2bf51d408b50878a1508c3f876a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tests; | |
use App\Account; | |
use App\CompressionProfile; | |
use Illuminate\Auth\AuthenticationException; | |
use Illuminate\Auth\SessionGuard; | |
// This sits on top of the regular test case and allows for macros | |
// and helpers that don't tranfer from project to project. But | |
// serve as a good starting point or reminder | |
abstract class DomainTestCase extends TestCase | |
{ | |
public function setUp() | |
{ | |
parent::setUp(); // TODO: Change the autogenerated stub | |
SessionGuard::macro('account', function () { | |
if (auth()->guest()) { | |
throw new AuthenticationException('You must be logged in for this action'); | |
} | |
return auth()->user()->load('account')->account; | |
}); | |
SessionGuard::macro('accountId', function () { | |
if (auth()->guest()) { | |
throw new AuthenticationException('You must be logged in for this action'); | |
} | |
return auth()->user()->load('account')->account->id; | |
}); | |
} | |
protected function basicSignIn($user = null) | |
{ | |
$user = $user ?: create('App\User'); | |
$this->be($user); | |
return $this; | |
} | |
protected function accountSignIn($user = null) | |
{ | |
$user = $user ?: create('App\User'); | |
$account = $user->account ?? create(Account::class, ['user_id' => $user->id]); | |
$this->be($user); | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment