Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code refactored: moved common logic of all testcases to parent testcase #23

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions tests/Feature/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 3 additions & 9 deletions tests/Feature/DepositCategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions tests/Feature/DepositTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 0 additions & 19 deletions tests/Feature/ExampleTest.php

This file was deleted.

12 changes: 3 additions & 9 deletions tests/Feature/ExpenseCategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 3 additions & 8 deletions tests/Feature/ExpenseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 3 additions & 8 deletions tests/Feature/PaymentMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
}
}