Skip to content

Instantly share code, notes, and snippets.

@roni-estein
Created November 19, 2018 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roni-estein/8e14c2bf51d408b50878a1508c3f876a to your computer and use it in GitHub Desktop.
Save roni-estein/8e14c2bf51d408b50878a1508c3f876a to your computer and use it in GitHub Desktop.
<?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