fahedaljghine / laravel-model-test
用于创建Eloquent模型CRUD功能测试的包
1.0.1
2022-06-24 15:52 UTC
Requires
- php: ^8.0
- illuminate/support: ^8.71|^9.0
Requires (Dev)
- orchestra/testbench: ^6.23|^7.0
- phpunit/phpunit: ^9.4
README
本包允许您通过一个命令生成所有模型的测试。
联系我
您可以通过查看我的网站来查看我的所有信息。
安装
您可以通过composer安装此包
composer require fahedaljghine/laravel-model-test
您必须使用以下命令发布包资源
php artisan vendor:publish --provider="Fahedaljghine\ModelTest\ModelTestServiceProvider"
以下文件内容将被发布到 config/model-test.php
<?php return [ /* * the models you need to generate tests to */ 'models' => [ //'Model1' , 'Model2' ], /* * if your models routes are protected with auth guard middleware * and want to test that against your model set this to true */ 'auth_user' => true, /* * if you are using spatie/laravel-permission in your project * and want to test that against your model set this to true */ 'laravel-permissions' => false ];
先决条件
在测试之前,您需要确保每个模型都有一个工厂
使用方法
将您要测试的模型添加到配置文件中,如下所示
/* * the models you need to generate tests to */ 'models' => [ 'Post' , 'Comment', ],
生成测试
您可以通过运行以下命令为指定模型生成测试
php artisan test:generate
这将为每个模型生成一个测试文件,让您能够扩展或覆盖测试
准备测试!
您可以通过运行以下命令对Post模型进行测试
php artisan test --filter=PostsTest
或者,您可以运行以下命令进行全部测试
php artisan test
变更日志
有关最近更改的更多信息,请参阅CHANGELOG。
Dontae
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。