fixed laravel test

pull/22/head
A1Gard 1 year ago
parent f642fb29c2
commit e4c9ef8aaf

@ -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

@ -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();
}

@ -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']);

@ -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{
// 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::factory()->count(1)->create(['email' => 'admin@example.com']);
$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;
}

Loading…
Cancel
Save