humans / laravel-setup-traits
Autorun traits on PHPUnit setup.
Installs: 6 715
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 1
This package is auto-updated.
Last update: 2023-02-20 14:53:06 UTC
README
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; }