Refactoring code snippet for test suite

Posted 10 months ago by xtremer360

I'm trying to figure out how I can better refactor this section in my code because it is located in every test file in my test suite. The only difference is the the slug is different for the permission.

Any ideas?

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

    $this->user = factory(User::class)->create();
    $this->role = factory(Role::class)->create(['slug' => 'admin']);
    $this->permission = factory(Permission::class)->create(['slug' => 'slug-here']);

    $this->role->givePermissionTo($this->permission);
    $this->user->assignRole($this->role);
}

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.