vendredi 25 mai 2018

unable to execute integration test for DB seeder - Error : Call to a member function connection() on null

I am trying to write an integration test for my db seeder, but it does not seem to be returning an instance of that seeder. so it fails to execute

when i debug it the $adminUserSeeder is showing the following

enter image description here

this is my test

 namespace Tests\Unit\user;
use AdminUserSeeder;
use App\Test;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use PHPUnit\Framework\TestCase;

class AdminSeederTest extends TestCase
{
    use DatabaseTransactions;

    public function setUp()
    {
        parent::setUp();
    }

    public function testRun()
    {
        $adminUserSeeder = new AdminUserSeeder();
        $adminUserSeeder->run();
        $this->assertDatabaseHas('users', ['name' =>  'admin']);
    }

}

and this is my seeder class

use Illuminate\Database\Seeder;

class AdminUserSeeder extends Seeder
{

    public function run()
    {
     $user = (new App\User)->where('name','admin')->first();
      if($user)
         {
             $user->delete();
         }
        factory(App\User::class,'admin')->create();
    }
}



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2s8yq7G
via IFTTT

Aucun commentaire:

Enregistrer un commentaire