From 8a7124b9161f3b709d04d40cb91932a07b5d68a8 Mon Sep 17 00:00:00 2001 From: A1Gard Date: Fri, 7 Jul 2023 07:15:56 +0330 Subject: [PATCH] fixed laravel test may last --- .github/workflows/laravel.yml | 3 +++ tests/Feature/AdminWebPagesTest.php | 27 +++++++++++---------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 8e4719c..6ef9115 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -34,4 +34,7 @@ jobs: DB_DATABASE: database/database.sqlite run: PIC_SEED=0 php artisan migrate --seed - name: Execute tests (Unit and Feature tests) via PHPUnit + env: + DB_CONNECTION: sqlite + DB_DATABASE: database/database.sqlite run: php artisan test diff --git a/tests/Feature/AdminWebPagesTest.php b/tests/Feature/AdminWebPagesTest.php index 689557b..c34e89e 100644 --- a/tests/Feature/AdminWebPagesTest.php +++ b/tests/Feature/AdminWebPagesTest.php @@ -379,23 +379,18 @@ class AdminWebPagesTest extends TestCase private function getValidUser(){ -// if (User::where('email','=','admin@example.com')->count() == 0){ -// -// if (Role::where('name','=','super-admin')->count() == 0){ -// $role = Role::create(['name' => 'super-admin']); -// }else{ -// $role = Role::where('name','super-admin')->first(); -// } -// -// $user = User::factory()->count(1)->create(['email' => 'admin@example.com']); -// $user->assignRole($role); -// }else{ -// $user = User::where('email','admin@example.com')->first(); -// } - $role = Role::where('name','super-admin')->first(); - $user = User::where('id','>',0)->first(); - if (! $user->hasRole('super-admin')){ + if (User::where('email','admin@example.com')->count() == 0){ + + if (Role::where('name','super-admin')->count() == 0){ + $role = Role::create(['name' => 'super-admin']); + }else{ + $role = Role::where('name','super-admin')->first(); + } + + $user = User::factory()->count(1)->create(['email' => 'admin@example.com']); $user->assignRole($role); + }else{ + $user = User::where('email','admin@example.com')->first(); } return $user; }