Skip to content
This repository has been archived by the owner on Jan 20, 2023. It is now read-only.

humans/laravel-setup-traits

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Setup Traits


Laravel now has this built-in!


This package allows traits to be ran automatically on the setup of your tests.

Here's an example.

class PostUpdateTest extends TestCase
{
    use ActingAsEdtior;
}

trait ActingAsEditor
{
    function setupActingAsEditor()
    {
        $this->editor = factory(User::class)->states('editor');
      
        $this->be($this->editor);
    }
}

Installation

Require the package via composer.

composer require humans/laravel-setup-traits --dev

Use the trait in your base test case.

use Humans\SetupTraits\SetupTraits;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    use SetupTraits;
}

Create a trait you want with the method name setup + class name

use Illuminate\Support\Facades\Notification;

trait	WithoutNotifications
{
    function setupWithoutNotifications
    {
        Notification::fake();
    }
}

Then include the trait in any of your tests!

class SettingsUpdateTest extends TestCase
{
    use WithoutNotifications;
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages