humans / laravel-setup-traits
此包已被废弃,不再维护。未建议替代包。
在PHPUnit设置中自动运行特性。
1.1.0
2021-04-10 04:21 UTC
This package is auto-updated.
Last update: 2023-02-20 14:53:06 UTC
README
Laravel 现已内置此功能!
此包允许在测试设置时自动运行特性。
以下是一个示例。
class PostUpdateTest extends TestCase { use ActingAsEdtior; } trait ActingAsEditor { function setupActingAsEditor() { $this->editor = factory(User::class)->states('editor'); $this->be($this->editor); } }
安装
通过composer要求此包。
composer require humans/laravel-setup-traits --dev
在您的基测试用例中使用该特性。
use Humans\SetupTraits\SetupTraits; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase { use SetupTraits; }
创建一个具有方法名 setup
+ 类名
的特性
use Illuminate\Support\Facades\Notification; trait WithoutNotifications { function setupWithoutNotifications { Notification::fake(); } }
然后在任何测试中包含该特性!
class SettingsUpdateTest extends TestCase { use WithoutNotifications; }