From e4c9ef8aafc2ff3f501c64baba8909a1551937a6 Mon Sep 17 00:00:00 2001 From: A1Gard Date: Fri, 7 Jul 2023 07:12:53 +0330 Subject: [PATCH] fixed laravel test --- .github/workflows/laravel.yml | 2 +- database/seeders/PostSeeder.php | 2 +- database/seeders/ProductSeeder.php | 2 +- tests/Feature/AdminWebPagesTest.php | 27 ++++++++++++++++----------- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 97496f4..8e4719c 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -34,4 +34,4 @@ jobs: DB_DATABASE: database/database.sqlite run: PIC_SEED=0 php artisan migrate --seed - name: Execute tests (Unit and Feature tests) via PHPUnit - run: vendor/bin/phpunit + run: php artisan test diff --git a/database/seeders/PostSeeder.php b/database/seeders/PostSeeder.php index 531d762..1749b77 100755 --- a/database/seeders/PostSeeder.php +++ b/database/seeders/PostSeeder.php @@ -87,7 +87,7 @@ class PostSeeder extends Seeder $p->hash = date('Ym') . str_pad(dechex(crc32($p->slug)), 8, '0', STR_PAD_LEFT); $p->save(); $p->categories()->sync([$item['category_id']]); - if (env('PIC_SEED') != 0){ + if (env('PIC_SEED') !== '0'){ $num = rand(1, 6); $p->addMedia(__DIR__ . "/img/$num/$num.jpg")->preservingOriginal()->toMediaCollection(); } diff --git a/database/seeders/ProductSeeder.php b/database/seeders/ProductSeeder.php index de3d93c..b21fc03 100755 --- a/database/seeders/ProductSeeder.php +++ b/database/seeders/ProductSeeder.php @@ -74,7 +74,7 @@ class ProductSeeder extends Seeder $plan = 6; } $product->categories()->sync($plans[$plan]['cats']); - if (env('PIC_SEED') != 0){ + if (env('PIC_SEED') !== '0'){ $num = rand(1, $plans[$plan]['max']); $product->addMedia($plans[$plan]['dir'] . "$num.jpg")->preservingOriginal()->toMediaCollection(); $num = rand(1, $plans[$plan]['max']); diff --git a/tests/Feature/AdminWebPagesTest.php b/tests/Feature/AdminWebPagesTest.php index c34e89e..689557b 100644 --- a/tests/Feature/AdminWebPagesTest.php +++ b/tests/Feature/AdminWebPagesTest.php @@ -379,18 +379,23 @@ 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']); +// 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')){ $user->assignRole($role); - }else{ - $user = User::where('email','admin@example.com')->first(); } return $user; }