diff --git a/tests/Feature/AccountTest.php b/tests/Feature/AccountTest.php index 58b89be..0999e22 100644 --- a/tests/Feature/AccountTest.php +++ b/tests/Feature/AccountTest.php @@ -4,27 +4,21 @@ use App\Models\Account; use App\Models\User; -use Database\Seeders\PermissionSeeder; use Illuminate\Foundation\Testing\RefreshDatabase; -use Laravel\Sanctum\Sanctum; +use Illuminate\Support\Facades\Auth; use Tests\TestCase; class AccountTest extends TestCase { use RefreshDatabase; - private $user; + private User $user; public function setUp(): void { parent::setUp(); - $this->user = User::factory()->create(); - - Sanctum::actingAs($this->user); - - $this->artisan('db:seed', ['--class' => PermissionSeeder::class]); - $this->app->make(\Spatie\Permission\PermissionRegistrar::class)->forgetCachedPermissions(); + $this->user = Auth::user(); } public function test_user_can_create_an_account() diff --git a/tests/Feature/DepositCategoryTest.php b/tests/Feature/DepositCategoryTest.php index bb54b6f..e2b3377 100644 --- a/tests/Feature/DepositCategoryTest.php +++ b/tests/Feature/DepositCategoryTest.php @@ -4,27 +4,21 @@ use App\Models\DepositCategory; use App\Models\User; -use Database\Seeders\PermissionSeeder; use Illuminate\Foundation\Testing\RefreshDatabase; -use Laravel\Sanctum\Sanctum; +use Illuminate\Support\Facades\Auth; use Tests\TestCase; class DepositCategoryTest extends TestCase { use RefreshDatabase; - private $user; + private User $user; public function setUp(): void { parent::setUp(); - $this->user = User::factory()->create(); - - Sanctum::actingAs($this->user, ['*']); - - $this->artisan('db:seed', ['--class' => PermissionSeeder::class]); - $this->app->make(\Spatie\Permission\PermissionRegistrar::class)->forgetCachedPermissions(); + $this->user = Auth::user(); } public function test_user_can_create_deposit_category(): void diff --git a/tests/Feature/DepositTest.php b/tests/Feature/DepositTest.php index 8beed75..3c241d5 100644 --- a/tests/Feature/DepositTest.php +++ b/tests/Feature/DepositTest.php @@ -4,27 +4,21 @@ use App\Models\Deposit; use App\Models\User; -use Database\Seeders\PermissionSeeder; use Illuminate\Foundation\Testing\RefreshDatabase; -use Laravel\Sanctum\Sanctum; +use Illuminate\Support\Facades\Auth; use Tests\TestCase; class DepositTest extends TestCase { use RefreshDatabase; - private $user; + private User $user; public function setUp(): void { parent::setUp(); - $this->user = User::factory()->create(); - - Sanctum::actingAs($this->user); - - $this->artisan('db:seed', ['--class' => PermissionSeeder::class]); - $this->app->make(\Spatie\Permission\PermissionRegistrar::class)->forgetCachedPermissions(); + $this->user = Auth::user(); } public function test_user_can_deposit() diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100644 index 8364a84..0000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,19 +0,0 @@ -get('/'); - - $response->assertStatus(200); - } -} diff --git a/tests/Feature/ExpenseCategoryTest.php b/tests/Feature/ExpenseCategoryTest.php index 0614150..aac3093 100644 --- a/tests/Feature/ExpenseCategoryTest.php +++ b/tests/Feature/ExpenseCategoryTest.php @@ -4,27 +4,21 @@ use App\Models\ExpenseCategory; use App\Models\User; -use Database\Seeders\PermissionSeeder; use Illuminate\Foundation\Testing\RefreshDatabase; -use Laravel\Sanctum\Sanctum; +use Illuminate\Support\Facades\Auth; use Tests\TestCase; class ExpenseCategoryTest extends TestCase { use RefreshDatabase; - private $user; + private User $user; public function setUp(): void { parent::setUp(); - $this->user = User::factory()->create(); - Sanctum::actingAs($this->user); - - $this->artisan('db:seed', ['--class' => PermissionSeeder::class]); - - $this->app->make(\Spatie\Permission\PermissionRegistrar::class)->forgetCachedPermissions(); + $this->user = Auth::user(); } public function test_user_can_create_expense_category() diff --git a/tests/Feature/ExpenseTest.php b/tests/Feature/ExpenseTest.php index 1f84302..2bf87f9 100644 --- a/tests/Feature/ExpenseTest.php +++ b/tests/Feature/ExpenseTest.php @@ -4,26 +4,21 @@ use App\Models\Expense; use App\Models\User; -use Database\Seeders\PermissionSeeder; use Illuminate\Foundation\Testing\RefreshDatabase; -use Laravel\Sanctum\Sanctum; +use Illuminate\Support\Facades\Auth; use Tests\TestCase; class ExpenseTest extends TestCase { use RefreshDatabase; - private $user; + private User $user; public function setUp(): void { parent::setUp(); - $this->user = User::factory()->create(); - Sanctum::actingAs($this->user); - - $this->artisan('db:seed', ['--class' => PermissionSeeder::class]); - $this->app->make(\Spatie\Permission\PermissionRegistrar::class)->forgetCachedPermissions(); + $this->user = Auth::user(); } public function test_user_can_create_expense() diff --git a/tests/Feature/PaymentMethodTest.php b/tests/Feature/PaymentMethodTest.php index 6cfb48d..7f27bf4 100644 --- a/tests/Feature/PaymentMethodTest.php +++ b/tests/Feature/PaymentMethodTest.php @@ -4,26 +4,21 @@ use App\Models\PaymentMethod; use App\Models\User; -use Database\Seeders\PermissionSeeder; use Illuminate\Foundation\Testing\RefreshDatabase; -use Laravel\Sanctum\Sanctum; +use Illuminate\Support\Facades\Auth; use Tests\TestCase; class PaymentMethodTest extends TestCase { use RefreshDatabase; - private $user; + private User $user; public function setUp(): void { parent::setUp(); - $this->user = User::factory()->create(); - Sanctum::actingAs($this->user); - - $this->artisan('db:seed', ['--class' => PermissionSeeder::class]); - $this->app->make(\Spatie\Permission\PermissionRegistrar::class)->forgetCachedPermissions(); + $this->user = Auth::user(); } public function test_user_can_create_payment_method() diff --git a/tests/TestCase.php b/tests/TestCase.php index f687f08..2650966 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,7 +2,10 @@ namespace Tests; +use App\Models\User; +use Database\Seeders\PermissionSeeder; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; +use Laravel\Sanctum\Sanctum; abstract class TestCase extends BaseTestCase { @@ -11,5 +14,10 @@ public function setUp(): void parent::setUp(); $this->withoutExceptionHandling(); + + Sanctum::actingAs(User::factory()->create()); + + $this->artisan('db:seed', ['--class' => PermissionSeeder::class]); + $this->app->make(\Spatie\Permission\PermissionRegistrar::class)->forgetCachedPermissions(); } }